Skip to content

Commit c5ef33e

Browse files
authoredMar 28, 2023
Production container (#17)
* Add gunicorn for production server, use alpine linux container * use gunicorn for prod container, freeze dependencies * change port * don't remove build deps * remove redundant user directive
1 parent 257b634 commit c5ef33e

File tree

5 files changed

+67
-14
lines changed

5 files changed

+67
-14
lines changed
 

‎Dockerfile

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
FROM python:3.11.2-bullseye
1+
FROM python:3.11.2-alpine@sha256:d811538656b665bba649b3ac2c3fc8a5187e24cd510a34d7e905d7ec4534fb89
2+
3+
4+
RUN apk update && \
5+
apk add postgresql-dev gcc musl-dev && \
6+
addgroup -S quizgroup && \
7+
adduser -S -h /home/quizmaster quizmaster -G quizgroup
28

3-
RUN useradd -ms /bin/bash quizmaster
49
USER quizmaster
510
WORKDIR /home/quizmaster
611

@@ -11,4 +16,4 @@ RUN python3 -m pip install --upgrade pip && \
1116
pip install --user -r requirements.txt --no-cache-dir && \
1217
pip cache purge
1318

14-
CMD [ "python3", "-m", "flask", "run", "--host=0.0.0.0"]
19+
CMD [ "python3", "-m", "gunicorn", "--access-logfile=-", "--workers=2", "--threads=4", "--worker-class=gthread", "--bind=0.0.0.0", "src.app:app" ]

‎docker-compose-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
build: .
1515
restart: "no"
1616
ports:
17-
- 5000:5000
17+
- 5000:8000
1818
environment:
1919
DATABASE_URL: ${DATABASE_URL}
2020
SECRET_KEY: ${SECRET_KEY}

‎docs/Howto.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Python v3.11+
66
- Create virtual environment with venv (optional)
77
- run `pip install -r requirements-dev.txt`
8+
<br>Note that `requirements.txt` is for production use and contains minimal dependencies.
89
- Docker
910
- psql
1011
- create an `.env` file with the following content using your own passwords and secrets

‎requirements-dev.txt

+45-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
1-
flask==2.2.3
2-
flask-sqlalchemy==3.0.3
3-
psycopg2-binary==2.9.5
4-
python-dotenv==1.0.0
1+
astroid==2.15.1
2+
async-generator==1.10
3+
attrs==22.2.0
54
autopep8==2.0.2
6-
pylint==2.17.0
5+
certifi==2022.12.7
6+
charset-normalizer==3.1.0
7+
click==8.1.3
8+
dill==0.3.6
9+
exceptiongroup==1.1.1
10+
Faker==18.3.1
11+
Flask==2.2.3
12+
Flask-SQLAlchemy==3.0.3
13+
greenlet==2.0.2
14+
h11==0.14.0
15+
idna==3.4
716
invoke==2.0.0
17+
isort==5.12.0
18+
itsdangerous==2.1.2
19+
Jinja2==3.1.2
20+
lazy-object-proxy==1.9.0
21+
MarkupSafe==2.1.2
22+
mccabe==0.7.0
23+
outcome==1.2.0
24+
platformdirs==3.2.0
25+
psycopg2-binary==2.9.5
26+
pycodestyle==2.10.0
27+
pylint==2.17.0
28+
PySocks==1.7.1
29+
python-dateutil==2.8.2
30+
python-dotenv==1.0.0
31+
requests==2.28.2
832
robotframework==6.0.2
9-
robotframework-seleniumlibrary==6.0.0
10-
robotframework-requests==0.9.4
1133
robotframework-faker==5.0.0
34+
robotframework-pythonlibcore==4.1.2
35+
robotframework-requests==0.9.4
36+
robotframework-seleniumlibrary==6.0.0
37+
selenium==4.8.3
38+
six==1.16.0
39+
sniffio==1.3.0
40+
sortedcontainers==2.4.0
41+
SQLAlchemy==2.0.7
42+
tomlkit==0.11.7
43+
trio==0.22.0
44+
trio-websocket==0.10.2
45+
typing_extensions==4.5.0
46+
urllib3==1.26.15
47+
Werkzeug==2.2.3
48+
wrapt==1.15.0
49+
wsproto==1.2.0

‎requirements.txt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
flask==2.2.3
2-
flask-sqlalchemy==3.0.3
1+
click==8.1.3
2+
Flask==2.2.3
3+
Flask-SQLAlchemy==3.0.3
4+
greenlet==2.0.2
5+
gunicorn==20.1.0
6+
itsdangerous==2.1.2
7+
Jinja2==3.1.2
8+
MarkupSafe==2.1.2
39
psycopg2==2.9.5
4-
python-dotenv==1.0.0
10+
python-dotenv==1.0.0
11+
SQLAlchemy==2.0.7
12+
typing_extensions==4.5.0
13+
Werkzeug==2.2.3

0 commit comments

Comments
 (0)
Please sign in to comment.