mirror of https://github.com/veops/cmdb.git
添加容器化部署方式
This commit is contained in:
parent
02ea6afa9c
commit
5f389459e8
|
@ -0,0 +1,16 @@
|
||||||
|
FROM centos:7.6.1810
|
||||||
|
|
||||||
|
LABEL description="Python2.7.5,cmdb"
|
||||||
|
|
||||||
|
RUN mkdir -p /data/apps/cmdb /data/apps/cmdb/logs
|
||||||
|
|
||||||
|
COPY . /data/apps/cmdb
|
||||||
|
|
||||||
|
WORKDIR /data/apps/cmdb
|
||||||
|
|
||||||
|
RUN yum install -y epel-release \
|
||||||
|
&& yum install -y python-pip \
|
||||||
|
&& pip install --no-cache-dir -r docker-start/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"]
|
||||||
|
|
|
@ -56,3 +56,9 @@ cp api/settings.py.example api/settings.py
|
||||||
- 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
- 浏览器打开: [http://127.0.0.1:8000](http://127.0.0.1:8000)
|
||||||
- 如果是非本机访问, 要修改**ui/.env**里**VUE_APP_API_BASE_URL**里的IP地址为后端服务的ip地址
|
- 如果是非本机访问, 要修改**ui/.env**里**VUE_APP_API_BASE_URL**里的IP地址为后端服务的ip地址
|
||||||
|
|
||||||
|
docker运行
|
||||||
|
----
|
||||||
|
进入主目录
|
||||||
|
```
|
||||||
|
docker-compose up
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
FROM centos:7.6.1810
|
||||||
|
|
||||||
|
LABEL description="Python2.7.5,cmdb"
|
||||||
|
|
||||||
|
RUN mkdir -p /data/apps/cmdb ~/.pip /data/apps/cmdb/logs
|
||||||
|
|
||||||
|
COPY .. /data/apps/cmdb
|
||||||
|
|
||||||
|
WORKDIR /data/apps/cmdb
|
||||||
|
|
||||||
|
RUN mv /data/apps/cmdb/pip.conf ~/.pip/ \
|
||||||
|
&& yum install -y epel-release \
|
||||||
|
&& yum install -y python-pip \
|
||||||
|
&& pip install -r 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"]
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
version: '3.4'
|
||||||
|
|
||||||
|
services:
|
||||||
|
cmdb-ui:
|
||||||
|
build:
|
||||||
|
context: ./ui
|
||||||
|
dockerfile: Dockerfile-ui
|
||||||
|
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
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
networks:
|
||||||
|
- new
|
||||||
|
|
||||||
|
cmdb-api:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile-api
|
||||||
|
image: cmdb-api:0.1
|
||||||
|
container_name: cmdb-api
|
||||||
|
command:
|
||||||
|
- /bin/bash
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
cp api/settings.py.example api/settings.py
|
||||||
|
sed -i 's#{user}:{password}@127.0.0.1:3306/{db}#cmdb:123456@mysql:3306/cmdb#g' api/settings.py
|
||||||
|
sed -i 's/127.0.0.1/redis/g' api/settings.py
|
||||||
|
gunicorn --workers=3 autoapp:app -b 0.0.0.0:5000
|
||||||
|
depends_on:
|
||||||
|
- cmdb-db
|
||||||
|
- cmdb-cache
|
||||||
|
networks:
|
||||||
|
new:
|
||||||
|
aliases:
|
||||||
|
- cmdb-api
|
||||||
|
|
||||||
|
cmdb-db:
|
||||||
|
image: mysql:5.7
|
||||||
|
container_name: cmdb-db
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
MYSQL_ROOT_PASSWORD: '123456'
|
||||||
|
MYSQL_DATABASE: 'cmdb'
|
||||||
|
MYSQL_USER: 'cmdb'
|
||||||
|
MYSQL_PASSWORD: '123456'
|
||||||
|
volumes:
|
||||||
|
- db-data:/var/lib/mysql
|
||||||
|
- ./docs/cmdb.sql:/docker-entrypoint-initdb.d/cmdb.sql
|
||||||
|
networks:
|
||||||
|
new:
|
||||||
|
aliases:
|
||||||
|
- mysql
|
||||||
|
|
||||||
|
cmdb-cache:
|
||||||
|
image: redis:latest
|
||||||
|
container_name: cmdb-cache
|
||||||
|
networks:
|
||||||
|
new:
|
||||||
|
aliases:
|
||||||
|
- redis
|
||||||
|
|
||||||
|
cmdb-proxy:
|
||||||
|
image: nginx:latest
|
||||||
|
container_name: cmdb-proxy
|
||||||
|
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:
|
||||||
|
- ./docker-start/nginx.cmdb.conf.example:/etc/nginx/conf.d/nginx.cmdb.conf.example
|
||||||
|
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
|
||||||
|
nginx -g 'daemon off;'
|
||||||
|
networks:
|
||||||
|
- new
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db-data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
new:
|
|
@ -0,0 +1,44 @@
|
||||||
|
server {
|
||||||
|
listen ${NGINX_PORT};
|
||||||
|
access_log /var/log/nginx/access.cmdb.log;
|
||||||
|
error_log /var/log/nginx/error.cmdb.log;
|
||||||
|
|
||||||
|
add_header 'Access-Control-Allow-Origin' "$http_origin";
|
||||||
|
add_header 'Access-Control-Allow-Credentials' 'true';
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With';
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_buffers 16 8k;
|
||||||
|
gzip_http_version 1.1;
|
||||||
|
gzip_min_length 256;
|
||||||
|
gzip_types
|
||||||
|
text/plain
|
||||||
|
text/css
|
||||||
|
text/js
|
||||||
|
text/xml
|
||||||
|
text/javascript
|
||||||
|
application/javascript
|
||||||
|
application/x-javascript
|
||||||
|
application/json
|
||||||
|
application/xml
|
||||||
|
application/rss+xml
|
||||||
|
image/svg+xml;
|
||||||
|
location / {
|
||||||
|
proxy_pass http://${CMDB_UI_HOST};
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
}
|
||||||
|
location /api {
|
||||||
|
proxy_pass http://${CMDB_API_HOST};
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Scheme $scheme;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_redirect off;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
-i https://mirrors.aliyun.com/pypi/simple
|
||||||
|
# Flask
|
||||||
|
Flask==1.0.3
|
||||||
|
Werkzeug==0.15.4
|
||||||
|
click>=5.0
|
||||||
|
# Api
|
||||||
|
Flask-RESTful ==0.3.7
|
||||||
|
# Database
|
||||||
|
Flask-SQLAlchemy ==2.4.0
|
||||||
|
SQLAlchemy ==1.3.5
|
||||||
|
PyMySQL ==0.9.3
|
||||||
|
redis ==3.2.1
|
||||||
|
# Migrations
|
||||||
|
Flask-Migrate ==2.5.2
|
||||||
|
# Deployment
|
||||||
|
gevent ==1.4.0
|
||||||
|
gunicorn>=19.1.1
|
||||||
|
supervisor ==4.0.3
|
||||||
|
# Auth
|
||||||
|
Flask-Login ==0.4.1
|
||||||
|
Flask-Bcrypt ==0.7.1
|
||||||
|
Flask-Cors>=3.0.8
|
||||||
|
# Caching
|
||||||
|
Flask-Caching>=1.0.0
|
||||||
|
# Environment variable parsing
|
||||||
|
environs ==4.2.0
|
||||||
|
marshmallow ==2.20.2
|
||||||
|
# async tasks
|
||||||
|
celery ==4.3.0
|
||||||
|
more-itertools ==5.0.0
|
||||||
|
kombu ==4.4.0
|
||||||
|
# other
|
||||||
|
six ==1.12.0
|
||||||
|
bs4>=0.0.1
|
||||||
|
toposort>=1.5
|
||||||
|
requests>=2.22.0
|
||||||
|
PyJWT>=1.7.1
|
Loading…
Reference in New Issue