mirror of
				https://github.com/veops/cmdb.git
				synced 2025-11-04 05:36:17 +08:00 
			
		
		
		
	Docker to production
This commit is contained in:
		
							
								
								
									
										2
									
								
								Pipfile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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"
 | 
			
		||||
 
 | 
			
		||||
@@ -63,4 +63,4 @@ docker 一键构建和运行
 | 
			
		||||
    docker-compose up -d
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
- 浏览器打开: [http://localhost](http://localhost)
 | 
			
		||||
- 浏览器打开: [http://localhost:8000](http://localhost:8000)
 | 
			
		||||
 
 | 
			
		||||
@@ -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"]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,18 @@
 | 
			
		||||
FROM alpine:3.9
 | 
			
		||||
FROM alpine:3.9 as builder
 | 
			
		||||
 | 
			
		||||
LABEL description="cmdb-ui"
 | 
			
		||||
 | 
			
		||||
RUN mkdir -p /data/apps/cmdb-ui/logs
 | 
			
		||||
 | 
			
		||||
COPY . /data/apps/cmdb-ui 
 | 
			
		||||
 | 
			
		||||
WORKDIR /data/apps/cmdb-ui
 | 
			
		||||
 | 
			
		||||
RUN apk add yarn && yarn install 
 | 
			
		||||
RUN apk add yarn && yarn install && sed -i 's#http://127.0.0.1:5000##g' .env && yarn build
 | 
			
		||||
 | 
			
		||||
CMD ["sh", "-c", "yarn run serve"]
 | 
			
		||||
 | 
			
		||||
FROM nginx:latest
 | 
			
		||||
 | 
			
		||||
RUN apt-get update && apt-get install -y curl && apt-get clean
 | 
			
		||||
 | 
			
		||||
RUN mkdir /etc/nginx/html
 | 
			
		||||
 | 
			
		||||
COPY --from=builder /data/apps/cmdb-ui/dist /etc/nginx/html/
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user