diff --git a/README.md b/README.md index 7ec75186..449a42d8 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,19 @@ MyEMS项目由下列组件构成: [安装 web UI](./web/README.md) + +### Docker Docker-compose 安装 +``` +git clone https://gitee.com/myems/myems.git + +# for generate the static direction: 'build' +cd myems/web +npm run build + +cd myems +docker-compose up -d +``` + ## 功能版本对比 | 功能 |社区版 |企业版 | 说明 | | :--- | :----: | :----: | :----: | diff --git a/admin/Dockerfile b/admin/Dockerfile new file mode 100644 index 00000000..8b3d2691 --- /dev/null +++ b/admin/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx + +# remove the config +RUN rm /etc/nginx/conf.d/default.conf && \ + rm /etc/nginx/nginx.conf && \ + mkdir -p /usr/share/nginx/admin + +# copy the config and web codes +COPY nginx.conf /etc/nginx/ +COPY . /usr/share/nginx/admin +CMD ['nginx', '-c /etc/nginx/nginx.conf', '-g "daemon off;"'] \ No newline at end of file diff --git a/admin/nginx.conf b/admin/nginx.conf new file mode 100644 index 00000000..d093b30b --- /dev/null +++ b/admin/nginx.conf @@ -0,0 +1,57 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/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 /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + server { + listen 8001; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/admin; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location /api { + proxy_pass http://127.0.0.1:8000/; + proxy_connect_timeout 75; + proxy_read_timeout 600; + send_timeout 600; + } + + } + +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..18fb4554 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +version: '3' +services: + api: + build: ./myems-api + command: gunicorn app:api -b 0.0.0.0:8000 + network_mode: "host" + restart: always + + aggregation: + build: ./myems-aggregation + command: python main.py + network_mode: "host" + restart: always + + cleaning: + build: ./myems-cleaning + command: python main.py + network_mode: "host" + restart: always + + modbus_tcp: + build: ./myems-modbus-tcp + command: python main.py + network_mode: "host" + restart: always + + normalization: + build: ./myems-normalization + command: python main.py + network_mode: "host" + restart: always + + admin: + build: ./admin + command: nginx -c /etc/nginx/nginx.conf -g "daemon off;" + healthcheck: + test: [ "CMD","nginx","-t" ] + network_mode: "host" + restart: always + + web: + build: ./web + command: nginx -c /etc/nginx/nginx.conf -g "daemon off;" + healthcheck: + test: [ "CMD","nginx","-t" ] + network_mode: "host" + restart: always \ No newline at end of file diff --git a/myems-aggregation/Dockerfile b/myems-aggregation/Dockerfile new file mode 100644 index 00000000..7775d19c --- /dev/null +++ b/myems-aggregation/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7 +WORKDIR /code + +COPY . /code +RUN pip install -r requirements.txt +CMD ['python', 'main.py'] \ No newline at end of file diff --git a/myems-aggregation/requirements.txt b/myems-aggregation/requirements.txt new file mode 100644 index 00000000..a6dc3627 --- /dev/null +++ b/myems-aggregation/requirements.txt @@ -0,0 +1 @@ +mysql-connector \ No newline at end of file diff --git a/myems-api/Dockerfile b/myems-api/Dockerfile new file mode 100644 index 00000000..05f44852 --- /dev/null +++ b/myems-api/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7 +WORKDIR /code + +COPY . /code +RUN pip install -r requirements.txt +CMD ['gunicorn', 'app:api', '-b 0.0.0.0:8000'] \ No newline at end of file diff --git a/myems-api/requirements.txt b/myems-api/requirements.txt new file mode 100644 index 00000000..12bd96f0 --- /dev/null +++ b/myems-api/requirements.txt @@ -0,0 +1,9 @@ +anytree +simplejson +mysql.connector +falcon +falcon_cors +falcon-multipart +gunicorn +openpyxl +pillow \ No newline at end of file diff --git a/myems-cleaning/Dockerfile b/myems-cleaning/Dockerfile new file mode 100644 index 00000000..7775d19c --- /dev/null +++ b/myems-cleaning/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7 +WORKDIR /code + +COPY . /code +RUN pip install -r requirements.txt +CMD ['python', 'main.py'] \ No newline at end of file diff --git a/myems-cleaning/requirements.txt b/myems-cleaning/requirements.txt new file mode 100644 index 00000000..51fbac7f --- /dev/null +++ b/myems-cleaning/requirements.txt @@ -0,0 +1,2 @@ +mysql-connector +schedule \ No newline at end of file diff --git a/myems-modbus-tcp/Dockerfile b/myems-modbus-tcp/Dockerfile new file mode 100644 index 00000000..7775d19c --- /dev/null +++ b/myems-modbus-tcp/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7 +WORKDIR /code + +COPY . /code +RUN pip install -r requirements.txt +CMD ['python', 'main.py'] \ No newline at end of file diff --git a/myems-modbus-tcp/requirements.txt b/myems-modbus-tcp/requirements.txt new file mode 100644 index 00000000..a867d987 --- /dev/null +++ b/myems-modbus-tcp/requirements.txt @@ -0,0 +1,3 @@ +mysql-connector +modbus_tk +schedule diff --git a/myems-normalization/Dockerfile b/myems-normalization/Dockerfile new file mode 100644 index 00000000..7775d19c --- /dev/null +++ b/myems-normalization/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7 +WORKDIR /code + +COPY . /code +RUN pip install -r requirements.txt +CMD ['python', 'main.py'] \ No newline at end of file diff --git a/myems-normalization/requirements.txt b/myems-normalization/requirements.txt new file mode 100644 index 00000000..67ece48e --- /dev/null +++ b/myems-normalization/requirements.txt @@ -0,0 +1,3 @@ +mysql-connector +openpyxl +sympy \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 00000000..41d7d2c8 --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,13 @@ +FROM nginx + +# remove the config +RUN rm /etc/nginx/conf.d/default.conf && \ + rm /etc/nginx/nginx.conf && \ + mkdir -p /usr/share/nginx/web + +# copy the config and web codes +# Attention: +# You should run 'npm run build' in the web direction to generate the build direction because this's a react projection. +COPY nginx.conf /etc/nginx/ +COPY . /usr/share/nginx/web +CMD ['nginx', '-c /etc/nginx/nginx.conf', '-g "daemon off;"'] \ No newline at end of file diff --git a/web/nginx.conf b/web/nginx.conf new file mode 100644 index 00000000..1c462061 --- /dev/null +++ b/web/nginx.conf @@ -0,0 +1,56 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/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 /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + server { + listen 80; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/web; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location /api { + proxy_pass http://127.0.0.1:8000/; + proxy_connect_timeout 75; + proxy_read_timeout 600; + send_timeout 600; + } + + } + +}