Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE去除,docker文件编写 #77

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions DEPLOYDOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Docker本地测试部署
Docker部署到本地,仅提供本地测试,请勿在生产环境直接使用!如需生产环境使用,请自己重新定制。

## 部署准备
在直接使用Docker部署前,需要准备Docker环境以及修改相关配置。

### Docker及Docker compose安装
部署需安装Docker,Docker compose请自行参考[官网](https://docs.docker.com/install/)。

### 前端配置
参考[部署指南](DEPLOY.md)将项目打包编译,修改dist/static/site-map.js如下:
```js
(function () {
window.API = {
'CESHI_API_HOST': '127.0.0.1:10615'
}
Object.freeze(window.API)
Object.defineProperty(window, 'API', {
configurable: false,
writable: false
})
})()
```
### 后端配置
后端不需要任何配置,只需要到sia-task-build-component和sia-task-executor-demo下均执行
> mvn clean install

或者直接在项目根目录下运行:
> mvn clean install

**【注意】**:
在sia-task-executor-demo中执行之前,需要先确认sia-task-hunter的版本,即maven打包时激活的profile。
去修改sia-task-executor-demo的pom文件,修改如下:
```xml
<dependency>
<groupId>com.sia</groupId>
<artifactId>sia-task-hunter</artifactId>
<version>1.0.0</version>
<!-- 你激活的maven profile产生的classifier-->
<classifier>jdk18</classifier>
</dependency>
```
### 运行
在项目根目录下运行:
> docker-compose -f docker-compose-zk.yml up -d
> docker-compose -f docker-compose-mariadb.yml up -d

因为zk和数据库运行后需要一段时间进行选举和初始化,另外可能碰到zk某个节点启动失败,需要重新启动(运行[关闭](#close)命令再重新运行启动命令),稍微等待一会再运行
> docker-compose -f docker-compose-sia.yml up -d

等待运行成功后,即可通过127.0.0.1:9999访问管理页面。

### 关闭{#close}
依次运行如下命令:
> docker-compose -f docker-compose-sia.yml down

> docker-compose -f docker-compose-zk.yml down

> docker-compose -f docker-compose-zk.yml down

### 调试
所有java项目已经配置远程调试端口,按下面说明配置端口即可远程调试。

### 说明
所有项目均在docker中运行,访问地址均为127.0.0.1,端口如下:

|项目|远程调试端口|访问端口|
|:---:|:---:|:---:|
|display|--|9999|
|config|9109|10615|
|scheduler|9209|19011|
|demo|9309|10089|
|db|3306|3306|
|zk1|--|2181|
|zk2|--|2182|
|zk3|--|2183|

前端项目,将前端打包的代码以及nginx配置挂载成了卷。其他项目未挂载任何卷。
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[使用指南](USERSGUIDE.md) </br>
[开发指南](DEVELOPGUIDE.md) </br>
[部署指南](DEPLOY.md)</br>
[Docker本地测试部署](DEPLOYDOCKER.md)</br>
[Demo](FASTSTART.md)</br>

背景
Expand Down
26 changes: 26 additions & 0 deletions docker-compose-mariadb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.1'
services:
task_db:
image: mariadb:10.4.8-bionic
container_name: task_db
hostname: task_db
ports:
- 3306:3306
environment:
- "MYSQL_ROOT_PASSWORD=root"
- "MYSQL_DATABASE=siatask"
- "MYSQL_ROOT_HOST=%"
command: [
'mysqld',
'--innodb-buffer-pool-size=20M',
'--character-set-server=utf8',
'--collation-server=utf8_general_ci',
'--default-time-zone=+8:00',
'--lower-case-table-names=1'
]
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
default:
external:
name: sia_net
73 changes: 73 additions & 0 deletions docker-compose-sia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
version: '3.1'
services:
task_config:
container_name: task_config
build:
context: .
dockerfile: docker-resources/task-config/Dockerfile
hostname: task_config
expose:
- 10615
- 9009
ports:
- 10615:10615
- 9109:9009
environment:
JAVA_OPTS: -server -Xms128m -Xmx256m -Xss256k -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=. -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=9009
ZOOKEEPERHOSTS: zoo1:2181
SPRING_DATASOURCE_URL: jdbc:mysql://task_db:3306/siatask?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
SPRING_DATASOURCE_PASSWORD: root
task_scheduler:
container_name: task_scheduler
build:
context: .
dockerfile: docker-resources/task-scheduler/Dockerfile
hostname: task_scheduler
expose:
- 19011
- 9009
ports:
- 19011:19011
- 9209:9009
environment:
JAVA_OPTS: -server -Xms128m -Xmx256m -Xss256k -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=. -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=9009
ZOOKEEPERHOSTS: zoo1:2181
SPRING_DATASOURCE_URL: jdbc:mysql://task_db:3306/siatask?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
SPRING_DATASOURCE_PASSWORD: root
task_display:
container_name: task_display
build:
context: .
dockerfile: docker-resources/task-display/Dockerfile
hostname: task_display
volumes:
- ./sia-task-config-display/dist:/app/dist
- ./docker-resources/task-display/nginx.conf:/etc/nginx/nginx.conf:ro
environment:
NGINX_PORT: 80
ports:
- 9999:80
depends_on:
- task_config
- task_scheduler
task_demo:
build:
context: .
dockerfile: docker-resources/task-demo/Dockerfile
container_name: task_demo
hostname: task_demo
depends_on:
- task_display
expose:
- 10089
ports:
- 10089:10089
- 9309:9009
environment:
SERVER_PORT: 10089
JAVA_OPTS: -server -Xms128m -Xmx256m -Xss256k -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=. -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=9009
ZOOKEEPERHOSTS: zoo1:2181
networks:
default:
external:
name: sia_net
40 changes: 40 additions & 0 deletions docker-compose-zk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.1'
services:
zoo1:
image: zookeeper:3.5.5
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
TZ: Asia/Shanghai
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper:3.5.5
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
TZ: Asia/Shanghai
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
depends_on:
- zoo1
zoo3:
image: zookeeper:3.5.5
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
TZ: Asia/Shanghai
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
depends_on:
- zoo2
networks:
default:
external:
name: sia_net
11 changes: 11 additions & 0 deletions docker-resources/task-config/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM openjdk:8-jdk-alpine
LABEL maintainer="YangLong<[email protected]>"
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir /spring
WORKDIR /spring
COPY sia-task-config/target/sia-task-config.jar /spring/app.jar
COPY sia-task-build-component/config/task_config_open.yml /spring/application-open.yml
COPY docker-resources/task-config/entrypoint.sh /spring/entrypoint.sh
RUN mkdir logs
ENTRYPOINT ["/spring/entrypoint.sh","-Dspring.config.location=application-open.yml","/spring/app.jar"]
4 changes: 4 additions & 0 deletions docker-resources/task-config/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
JAVA_OPTS="$JAVA_OPTS"
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"
java $JAVA_OPTS $1 -jar $2
10 changes: 10 additions & 0 deletions docker-resources/task-demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM openjdk:8-jdk-alpine
LABEL maintainer="YangLong<[email protected]>"
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir /spring
WORKDIR /spring
COPY sia-task-executor-demo/target/sia-task-executor-demo.jar /spring/app.jar
COPY docker-resources/task-demo/entrypoint.sh /spring/entrypoint.sh
RUN mkdir logs
ENTRYPOINT ["/spring/entrypoint.sh","/spring/app.jar"]
4 changes: 4 additions & 0 deletions docker-resources/task-demo/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
JAVA_OPTS="$JAVA_OPTS"
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"
java $JAVA_OPTS -jar $1
4 changes: 4 additions & 0 deletions docker-resources/task-display/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.17.4-alpine
LABEL maintainer="YangLong<[email protected]>"
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
59 changes: 59 additions & 0 deletions docker-resources/task-display/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 256;
}


http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

#access_log /logs/api/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;
server {
listen 80;
server_name localhost;
location / {
root /app/dist;
index index.html index.htm;
try_files $uri $uri/ @router;
}
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen 80;
server_name localhost;
location / {
proxy_pass http://task_scheduler:10615;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
}
11 changes: 11 additions & 0 deletions docker-resources/task-scheduler/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM openjdk:8-jdk-alpine
LABEL maintainer="YangLong<[email protected]>"
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir /spring
WORKDIR /spring
COPY sia-task-scheduler/target/sia-task-scheduler.jar /spring/app.jar
COPY sia-task-build-component/config/task_scheduler_open.yml /spring/application-open.yml
COPY docker-resources/task-scheduler/entrypoint.sh /spring/entrypoint.sh
RUN mkdir logs
ENTRYPOINT ["/spring/entrypoint.sh","-Dspring.config.location=application-open.yml","/spring/app.jar"]
4 changes: 4 additions & 0 deletions docker-resources/task-scheduler/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
JAVA_OPTS="$JAVA_OPTS"
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"
java $JAVA_OPTS $1 -jar $2
Loading