Browse Source

Added Gunicorn and Nginx for production use

joel
Simon Bowie 3 years ago
parent
commit
8faf409be7
4 changed files with 38 additions and 5 deletions
  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 View File

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


db: db:
image: mariadb:latest image: mariadb:latest
env_file: env_file:
- ./.env.prod - ./.env.prod
volumes: volumes:
dbdata:/var/lib/mysql
- dbdata:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password' 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 View File

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 View File

# get config variables from OS environment variables: set in env file passed through Docker Compose # 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['SECRET_KEY'] = os.environ.get('SECRET_KEY')
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL') app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'False'


db.init_app(app) db.init_app(app)



+ 1
- 0
web/requirements.txt View File

flask-sqlalchemy flask-sqlalchemy
flask-login flask-login
flask-moment flask-moment
gunicorn

Loading…
Cancel
Save