Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 9832694f

Přidáno uživatelem Stanislav Král před asi 4 roky(ů)

#8219 - Dockerization improvements and gunicorn WSGI implementation

- when using docker to run the application nginx proxy is now used (app is then available at localhost:80)

Zobrazit rozdíly:

app.py
13 13
    host = "0.0.0.0"
14 14
    port = 5000
15 15

  
16
    # TODO better load this from config.py
16 17
    if "FLASK_HOST" in os.environ:
17 18
        host = os.environ["FLASK_HOST"]
18 19

  
docker-compose.yml
1
version: '3.3'
1
version: '3.7'
2

  
3
networks:
4
    web:
5

  
2 6
services:
3
    server:
7
    nginx:
8
        restart: unless-stopped
4 9
        build:
5
            dockerfile: docker/Dockerfile
6 10
            context: .
11
            dockerfile: docker/nginx/Dockerfile
12
        networks:
13
            - web
7 14
        ports:
8
            - '5000:5000'
15
            - 80:80
16
    gunicorn:
17
        restart: unless-stopped
18
        build:
19
            context: .
20
            dockerfile: docker/gunicorn/Dockerfile
21
        networks:
22
            - web
docker/Dockerfile
1
FROM python:3.8.5-slim-buster 
2

  
3
WORKDIR /usr/src/app
4

  
5
# copy application dependency list
6
COPY requirements.txt ./
7

  
8
# install application dependencies
9
RUN pip install --no-cache-dir -r requirements.txt
10

  
11
# copy the whole application
12
COPY . .
13

  
14
# run the application
15
CMD [ "python", "./app.py" ]
docker/gunicorn/Dockerfile
1
FROM python:3.8.5-slim-buster 
2

  
3
WORKDIR /usr/src/app
4

  
5
# copy the whole application
6
COPY . .
7

  
8
# upgrade pip, install gunicorn and app dependencies
9
RUN \
10
    pip3 install --upgrade pip && \
11
    pip3 install gunicorn && \
12
    pip3 install --no-cache-dir -r requirements.txt
13

  
14
# expose port 8000
15
# TODO could be loaded from env vars
16
EXPOSE 8000
17

  
18
# run the application via gunicorn WSGI
19
CMD ["gunicorn", "-c", "docker/gunicorn/config.py", "wsgi:flask_app"]
docker/gunicorn/config.py
1
bind = '0.0.0.0'
docker/nginx/Dockerfile
1
FROM nginx:1.19-alpine
2

  
3
COPY docker/nginx/application.conf /etc/nginx/conf.d/default.conf
4

  
5
# TODO copy only static resources
6
COPY . /app
7

  
8
WORKDIR /app
docker/nginx/application.conf
1
server {
2
    listen       80;
3
    listen  [::]:80;
4

  
5
    location / {
6
        proxy_set_header Host $host;
7
        proxy_set_header X-Real-IP $remote_addr;
8
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9
        proxy_set_header X-Forwarded-Proto $scheme;
10

  
11
        proxy_redirect off;
12
        proxy_pass http://gunicorn:8000;
13
    }
14

  
15
    location = /50x.html {
16
        root   /usr/share/nginx/html;
17
    }
18
}
static/test.txt
1
test
wsgi.py
1
from app import app as flask_app
2

  
3

  
4
if __name__ == "__main__":
5
    flask_app.run()

Také k dispozici: Unified diff