-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
66 lines (49 loc) · 1.44 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# syntax=docker/dockerfile:1.4
FROM python:3.10 as builder
WORKDIR /tmp/wheels
COPY pyproject.toml .
# Prebuild dependencies as wheels
RUN <<'EOFDOCKER'
apt update
apt-get install -y python3-toml
rm -rf /var/lib/apt/lists/*
/usr/bin/python3 <<'EOF'
from pathlib import Path
import toml
pyproject = toml.loads(Path("pyproject.toml").read_text())
proj = pyproject["project"]
deps = {
"wheel",
*pyproject["build-system"]["requires"],
*proj["dependencies"],
*proj["optional-dependencies"]["test"],
*proj["optional-dependencies"]["dev"],
}
Path("requirements.txt").write_text("\n".join(deps))
EOF
python3 -m pip wheel -r requirements.txt
EOFDOCKER
FROM python:3.10-slim as runner
COPY --from=builder /tmp/wheels/*.whl /tmp/wheels/
ENV PORT=8000
RUN \
apt update \
&& apt-get install -y cron \
&& rm -rf /var/lib/apt/lists/*
COPY clean-old.sh /
RUN crontab -l | { cat; echo "*/5 * * * * bash /clean-old.sh"; } | crontab -
WORKDIR /app
COPY pyproject.toml *.md /app/
COPY src ./src/
COPY tests ./tests/
RUN \
adduser docker-user \
&& chown --recursive docker-user:docker-user /app
USER docker-user
RUN \
python3 -m venv --system-site-packages .venv \
&& ./.venv/bin/python3 -m pip install pip==22
RUN \
./.venv/bin/python3 -m pip install --no-index --find-links=/tmp/wheels /app[test,dev] \
&& ./.venv/bin/python3 -m pytest tests
CMD [ "sh", "-c", "./.venv/bin/gunicorn --bind=:${PORT} --workers=4 icw:app" ]