Skip to content

Commit 51e0ea8

Browse files
author
Martin Catty
committed
feat: add docker configuration for both dev and production
1 parent ac9afae commit 51e0ea8

5 files changed

Lines changed: 119 additions & 0 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ uv run ruff format --check && uv run ruff check
3939
## Packaging
4040

4141
voir package_scripts/main.sh
42+
43+
## Fonctionnement
44+
45+
Une fois l’app installée on peut vérifier qu’elle fonctionne avec :
46+
47+
```sh
48+
curl -X POST \
49+
http://localhost:5000/pdf \
50+
-H "Content-Type: application/json" \
51+
-d '{"html": "<html><body><h1>Test</h1></body></html>"}' \
52+
--output test.pdf
53+
```
54+
55+
## Build
56+
57+
Pour la production :
58+
59+
```sh
60+
docker build -f ops/production/Dockerfile -t NAME .
61+
```

ops/dev/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM debian:12-slim
2+
3+
ARG UV_VERSION=0.5.4
4+
ARG GROUP_ID=1000
5+
ARG USER_ID=1000
6+
7+
ENV PYTHONUNBUFFERED=1
8+
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
python3 \
11+
ca-certificates \
12+
weasyprint \
13+
curl && rm -rf /var/lib/apt/lists/*
14+
15+
RUN curl -sSL "https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz" | tar -xz -C /usr/local/bin --strip-components=1
16+
17+
RUN groupadd -g "${GROUP_ID}" app && \
18+
useradd --create-home --no-log-init -u "${USER_ID}" -g "${GROUP_ID}" app
19+
20+
USER app
21+
22+
WORKDIR /home/app
23+
24+
RUN uv venv /home/app/venv
25+
ENV PATH="/home/app/venv/bin:$PATH"
26+
27+
RUN uv pip install -e .
28+
29+
CMD ["python3", "-m", "flask", "--app", "src.app:create_app()", "run", "--host=0.0.0.0"]

ops/dev/app_env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BASE_URL=http://localhost:5000

ops/dev/docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3.7'
2+
x-app_common:
3+
&app_common
4+
build:
5+
context: ../../
6+
dockerfile: ops/dev/Dockerfile
7+
args:
8+
UV_VERSION: 0.5.4
9+
# use the user id and group id matching the host user
10+
USER_ID: 1000
11+
GROUP_ID: 1001
12+
env_file:
13+
- app_env
14+
stdin_open: true
15+
tty: true
16+
volumes:
17+
- app_data:/home/app
18+
ports:
19+
- 5000
20+
21+
services:
22+
app:
23+
<<: *app_common
24+
25+
volumes:
26+
app_data:
27+
driver_opts:
28+
type: none
29+
device: "${PWD}/../../"
30+
o: bind

ops/production/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM debian:12-slim
2+
3+
ARG UV_VERSION=0.5.4
4+
ARG GROUP_ID=1000
5+
ARG USER_ID=1000
6+
7+
ENV PYTHONUNBUFFERED=1
8+
ENV PYTHONDONTWRITEBYTECODE=1
9+
ENV PIP_NO_CACHE_DIR=1
10+
ENV GUNICORN_WORKERS=4
11+
ENV APP_PORT=5000
12+
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
python3 \
15+
ca-certificates \
16+
tini \
17+
weasyprint \
18+
curl && rm -rf /var/lib/apt/lists/*
19+
20+
RUN curl -sSL "https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz" | tar -xz -C /usr/local/bin --strip-components=1
21+
22+
RUN groupadd -g "${GROUP_ID}" app && \
23+
useradd --create-home --no-log-init -u "${USER_ID}" -g "${GROUP_ID}" app
24+
25+
USER app
26+
27+
WORKDIR /home/app
28+
29+
COPY --chown=app:app src/ src/
30+
COPY --chown=app:app pyproject.toml .
31+
32+
ENV PATH="/home/app/venv/bin:$PATH"
33+
RUN uv venv /home/app/venv && \
34+
. /home/app/venv/bin/activate && \
35+
uv pip install -e . && \
36+
uv pip install gunicorn
37+
38+
ENTRYPOINT ["/usr/bin/tini", "--"]
39+
CMD ["gunicorn", "--workers=${GUNICORN_WORKERS}", "--bind=0.0.0.0:${APP_PORT}", "src.app:create_app()"]

0 commit comments

Comments
 (0)