-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.prod
62 lines (45 loc) · 1.47 KB
/
Dockerfile.prod
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
##############
# temp stage #
##############
FROM python:3.11.4-slim-buster as builder
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# system deps
RUN apt-get update && apt-get install -y --no-install-recommends gcc
# lint
RUN pip install --upgrade pip
RUN pip install flake8==6.0.0
COPY . .
RUN flake8 --ignore=E501,F401 .
# python deps
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
###############
# final stage #
###############
FROM python:3.11.4-slim-buster
WORKDIR /app
# system and python deps
RUN apt-get update && apt-get install -y --no-install-recommends netcat
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
COPY ./entrypoint.prod.sh .
RUN sed -i 's/\r$//g' ./entrypoint.prod.sh
RUN chmod +x ./entrypoint.prod.sh
COPY . .
RUN addgroup --gid 1001 --system app && \
adduser --no-create-home --shell /bin/false --disabled-password --uid 1001 --system --group app
RUN chown -R app:app .
USER app
RUN mkdir /app/staticfiles
HEALTHCHECK CMD curl --fail http://localhost:8000 || exit 1
ENTRYPOINT ["./entrypoint.prod.sh"]
# TODO: Cache Python Packages to the Docker Host
# TODO: only COPY what is needed
# TODO: add envars via --mount=type=secret
# TODO: combine Dockerfiles into one and use flag or envar to switch
# TODO: update dockerfile.json snippet
# TODO: use docker scan before deployment