add docker configuration for production

This commit is contained in:
dominik24c 2022-11-18 00:20:50 +01:00
parent b2dfccf869
commit bd99609de2
8 changed files with 114 additions and 3 deletions

View File

@ -0,0 +1,4 @@
FROM nginx:1.23-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx.conf /etc/nginx/conf.d

17
backend/Dockerfile.prod Normal file
View File

@ -0,0 +1,17 @@
FROM python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
RUN apt update && \
pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
RUN flask db migrate

View File

@ -1,7 +1,8 @@
from dotenv import load_dotenv
from app import create_app
load_dotenv()
app = create_app()
if __name__ == "__main__":
load_dotenv()
app = create_app()
app.run()
app.run(host="0.0.0.0")

15
backend/nginx.conf Normal file
View File

@ -0,0 +1,15 @@
upstream web_app {
server backend_service:5000;
}
server {
listen 80;
location / {
proxy_pass http://web_app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}

View File

@ -13,3 +13,4 @@ apiflask>=1.0.2,<1.1.0
python-dotenv==0.21.0
factory_boy>=3.2.1,<3.3.0
reportlab>=3.6.12,<3.7.0
gunicorn>=20.1.0,<20.2.0

41
docker-compose.prod.yaml Normal file
View File

@ -0,0 +1,41 @@
version: '3.3'
services:
backend_service:
build:
context: ./backend
dockerfile: ./Dockerfile.prod
command: gunicorn -w 4 --bind 0.0.0.0:5000 main:app
# command: flask run --host 0.0.0.0 --port 5000
volumes:
- "./db_data:/app/backend/db.sqlite"
environment:
- FLASK_APP=main.py
- FLASK_ENV=production
- ENABLE_CORS=1
expose:
- 5000
ports:
- "5000:5000"
# nginx_server:
# build:
# context: ./backend
# dockerfile: ./Dockerfile.nginx.prod
# depends_on:
# - backend_service
# ports:
# - "6666:80"
nginx_client:
build:
context: ./frontend
dockerfile: ./Dockerfile.prod
# depends_on:
# - nginx_server
ports:
- "9998:80"
volumes:
db_data:

23
frontend/Dockerfile.prod Normal file
View File

@ -0,0 +1,23 @@
FROM node:16-alpine as builder
ENV CHOKIDAR_USEPOLLING 1
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm i
RUN mkdir node_modules/.cache && chmod -R 777 node_modules/.cache
COPY . .
RUN npm run build
FROM nginx:1.23-alpine
COPY --from=builder /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx.conf /etc/nginx/conf.d

9
frontend/nginx.conf Normal file
View File

@ -0,0 +1,9 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}