瀏覽代碼

Added Gunicorn and Nginx for production use

joel
Simon Bowie 3 年之前
父節點
當前提交
8faf409be7
共有 4 個文件被更改,包括 38 次插入5 次删除
  1. +20
    -5
      docker-compose.prod.yml
  2. +16
    -0
      nginx-conf/toolkit.conf
  3. +1
    -0
      web/app/__init__.py
  4. +1
    -0
      web/requirements.txt

+ 20
- 5
docker-compose.prod.yml 查看文件

@@ -3,12 +3,13 @@ services:
web:
build: ./web
container_name: python
ports:
- "5000:5000"
volumes:
- ./web:/code
expose:
- 5000
env_file:
- ./.env.prod
depends_on:
- db
command: gunicorn --workers=3 --bind 0.0.0.0:5000 "app:create_app()"

db:
image: mariadb:latest
@@ -17,5 +18,19 @@ services:
env_file:
- ./.env.prod
volumes:
dbdata:/var/lib/mysql
- dbdata:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'

nginx:
image: nginx:latest
container_name: nginx
restart: unless-stopped
ports:
- "1337:80"
volumes:
- ./nginx-conf:/etc/nginx/conf.d
depends_on:
- web

volumes:
dbdata:

+ 16
- 0
nginx-conf/toolkit.conf 查看文件

@@ -0,0 +1,16 @@
upstream toolkit {
server web:5000;
}

server {

listen 80;

location / {
proxy_pass http://toolkit;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}

}

+ 1
- 0
web/app/__init__.py 查看文件

@@ -26,6 +26,7 @@ def create_app():
# get config variables from OS environment variables: set in env file passed through Docker Compose
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY')
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'False'

db.init_app(app)


+ 1
- 0
web/requirements.txt 查看文件

@@ -2,3 +2,4 @@ flask
flask-sqlalchemy
flask-login
flask-moment
gunicorn

Loading…
取消
儲存