From 046d0e60b766d0da219eebb66be8f00fa722712f Mon Sep 17 00:00:00 2001 From: pycook Date: Fri, 8 Nov 2019 15:26:22 +0800 Subject: [PATCH 1/4] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docker 一键安装说明补充 --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf7a796..6ce40f9 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,11 @@ cp api/settings.py.example api/settings.py - 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000) - 如果是非本机访问, 要修改**ui/.env**里**VUE_APP_API_BASE_URL**里的IP地址为后端服务的ip地址 -docker运行 +docker 一键构建和运行 ---- -进入主目录 +- 进入主目录(首次镜像的构建需要**10分钟**左右,视网络情况而定) ``` docker-compose up -d ``` + +- 浏览器打开: [http://localhost](http://localhost) From 3fdfa4dc92f12d6f7102b21f0c078aa1676c1675 Mon Sep 17 00:00:00 2001 From: pycook Date: Sun, 10 Nov 2019 19:06:38 +0800 Subject: [PATCH 2/4] Docker to production --- Pipfile | 2 +- README.md | 2 +- api/Dockerfile | 1 - docker-compose.yml | 40 ++++++++++-------------------------- docs/nginx.cmdb.conf.example | 14 +++++++++++-- docs/requirements.txt | 4 ++-- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/Pipfile b/Pipfile index 7459fd8..43b1257 100644 --- a/Pipfile +++ b/Pipfile @@ -19,7 +19,7 @@ redis = "==3.2.1" Flask-Migrate = "==2.5.2" # Deployment gevent = "==1.4.0" -gunicorn = ">=19.1.1" +gunicorn = "==19.1.1" supervisor = "==4.0.3" # Auth Flask-Login = "==0.4.1" diff --git a/README.md b/README.md index 6ce40f9..2c680bd 100644 --- a/README.md +++ b/README.md @@ -63,4 +63,4 @@ docker 一键构建和运行 docker-compose up -d ``` -- 浏览器打开: [http://localhost](http://localhost) +- 浏览器打开: [http://localhost:8000](http://localhost:8000) diff --git a/api/Dockerfile b/api/Dockerfile index 7b26ed7..9f11108 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -15,4 +15,3 @@ RUN yum install -y epel-release && yum clean all\ && pip install --no-cache-dir -r docs/requirements.txt CMD ["bash", "-c", "cp api/settings.py.example api/settings.py && sed -i 's#{user}:{password}@127.0.0.1:3306/{db}#:@127.0.0.1:3306/cmdb#g' api/settings.py && flask run"] - diff --git a/docker-compose.yml b/docker-compose.yml index a3817be..2ac8c46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,6 @@ version: '3.4' services: - cmdb-ui: - build: - context: ./ui - dockerfile: Dockerfile - image: cmdb-ui:0.1 - container_name: cmdb-ui - command: ["sh", "-c", "sed -i 's#http://127.0.0.1:5000##g' .env && yarn run serve"] - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:5000"] - interval: 5s - timeout: 5s - retries: 100 - start_period: 10s - depends_on: - - cmdb-api - networks: - - new - cmdb-api: build: context: . @@ -67,32 +49,32 @@ services: aliases: - redis - cmdb-proxy: - image: nginx:latest - container_name: cmdb-proxy + cmdb-ui: + build: + context: ./ui + dockerfile: Dockerfile + image: cmdb-ui:0.1 + container_name: cmdb-ui depends_on: - cmdb-api - - cmdb-ui - volumes: - - "$PWD/conf.d:/etc/nginx/conf.d" environment: CMDB_API_HOST: cmdb-api:5000 - CMDB_UI_HOST: cmdb-ui:8000 NGINX_PORT: 80 volumes: + - "$PWD/conf.d:/etc/nginx/conf.d" - ./docs/nginx.cmdb.conf.example:/etc/nginx/conf.d/nginx.cmdb.conf.example - command: + command: - /bin/bash - -c - | - envsubst '$$CMDB_API_HOST $$CMDB_UI_HOST $$NGINX_PORT' < /etc/nginx/conf.d/nginx.cmdb.conf.example > /etc/nginx/conf.d/cmdb.conf + envsubst '$$CMDB_API_HOST $$NGINX_PORT' < /etc/nginx/conf.d/nginx.cmdb.conf.example > /etc/nginx/conf.d/cmdb.conf rm -f /etc/nginx/conf.d/default.conf + curl http://cmdb-api:5000/api/v0.1/ci/flush nginx -g 'daemon off;' - curl http://localhost/api/v0.1/ci/flush networks: - new ports: - - "80:80" + - "8000:80" volumes: db-data: diff --git a/docs/nginx.cmdb.conf.example b/docs/nginx.cmdb.conf.example index ca5b246..cba57a5 100644 --- a/docs/nginx.cmdb.conf.example +++ b/docs/nginx.cmdb.conf.example @@ -25,9 +25,12 @@ server { application/xml application/rss+xml image/svg+xml; + + root /etc/nginx/html; location / { - proxy_pass http://${CMDB_UI_HOST}; - proxy_set_header Host $host; + root /etc/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; } location /api { proxy_pass http://${CMDB_API_HOST}; @@ -41,4 +44,11 @@ server { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } + location ~* \.(css|js)$ { + access_log off; + add_header Pragma public; + add_header Cache-Control "public, max-age=7776000"; + #add_header Cache-Control "public,no-cache, max-age=0"; + add_header X-Asset "yes"; + } } diff --git a/docs/requirements.txt b/docs/requirements.txt index a3d813d..af6ef72 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -11,10 +11,10 @@ SQLAlchemy ==1.3.5 PyMySQL ==0.9.3 redis ==3.2.1 # Migrations -Flask-Migrate ==2.5.2 +Flask-Migrate == 2.5.2 # Deployment gevent ==1.4.0 -gunicorn>=19.1.1 +gunicorn == 19.1.1 supervisor ==4.0.3 # Auth Flask-Login ==0.4.1 From de22a4e04bd746a2c77863e6d4c8608cad931099 Mon Sep 17 00:00:00 2001 From: pycook Date: Sun, 10 Nov 2019 19:10:23 +0800 Subject: [PATCH 3/4] gunicorn==19.5.0 --- Pipfile | 2 +- docs/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Pipfile b/Pipfile index 43b1257..182432c 100644 --- a/Pipfile +++ b/Pipfile @@ -19,7 +19,7 @@ redis = "==3.2.1" Flask-Migrate = "==2.5.2" # Deployment gevent = "==1.4.0" -gunicorn = "==19.1.1" +gunicorn = "==19.5.0" supervisor = "==4.0.3" # Auth Flask-Login = "==0.4.1" diff --git a/docs/requirements.txt b/docs/requirements.txt index af6ef72..9ed3509 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -14,7 +14,7 @@ redis ==3.2.1 Flask-Migrate == 2.5.2 # Deployment gevent ==1.4.0 -gunicorn == 19.1.1 +gunicorn == 19.5.0 supervisor ==4.0.3 # Auth Flask-Login ==0.4.1 From 618cd7ff162362b8c983ea3b0031479747695a3c Mon Sep 17 00:00:00 2001 From: pycook Date: Mon, 11 Nov 2019 00:25:22 +0800 Subject: [PATCH 4/4] vue lint --- api/lib/cmdb/const.py | 7 +++++-- api/lib/cmdb/value.py | 2 ++ docker-compose.yml | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/lib/cmdb/const.py b/api/lib/cmdb/const.py index ffeabae..d7e0b39 100644 --- a/api/lib/cmdb/const.py +++ b/api/lib/cmdb/const.py @@ -1,5 +1,8 @@ # -*- coding:utf-8 -*- + +from __future__ import unicode_literals + import datetime import six @@ -37,8 +40,8 @@ type_map = { 'deserialize': { Attribute.INT: string2int, Attribute.FLOAT: float, - Attribute.TEXT: escape, - Attribute.TIME: escape, + Attribute.TEXT: lambda x: escape(x).encode('utf-8').decode('utf-8'), + Attribute.TIME: lambda x: escape(x).encode('utf-8').decode('utf-8'), Attribute.DATETIME: str2datetime, Attribute.DATE: str2datetime, }, diff --git a/api/lib/cmdb/value.py b/api/lib/cmdb/value.py index c320644..a9eb4fe 100644 --- a/api/lib/cmdb/value.py +++ b/api/lib/cmdb/value.py @@ -1,6 +1,8 @@ # -*- coding:utf-8 -*- +from __future__ import unicode_literals + import markupsafe from flask import abort diff --git a/docker-compose.yml b/docker-compose.yml index 2ac8c46..dadc603 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,7 +61,6 @@ services: CMDB_API_HOST: cmdb-api:5000 NGINX_PORT: 80 volumes: - - "$PWD/conf.d:/etc/nginx/conf.d" - ./docs/nginx.cmdb.conf.example:/etc/nginx/conf.d/nginx.cmdb.conf.example command: - /bin/bash