-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (54 loc) · 2.08 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (54 loc) · 2.08 KB
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
67
68
69
70
71
72
73
74
75
# syntax=docker/dockerfile:1
ARG PYTHON_IMAGE=python:3.14.7-slim-trixie@sha256:cad9a2c871761c413caa6fdd6441c783451e740a48aaeba60ae62a8b53525ef6
FROM ${PYTHON_IMAGE} AS base
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONHASHSEED=random \
VIRTUAL_ENV=/opt/venv \
PATH=/opt/venv/bin:$PATH
RUN python -m venv "$VIRTUAL_ENV"
WORKDIR /app
FROM base AS development
RUN apt-get update \
&& apt-get install --yes --no-install-recommends ca-certificates git sqlite3 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements-dev.txt ./
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements-dev.txt
# The Dev Containers extension bind-mounts the workspace at runtime, so keep
# source code out of this development image. This also avoids requiring a
# particular source-tree layout merely to open the repository in VS Code.
CMD ["python", "-m", "feedback"]
FROM development AS test
COPY pyproject.toml ./
COPY src ./src
COPY tests ./tests
RUN pip install --no-deps .
CMD ["pytest", "-q"]
FROM base AS production-builder
COPY requirements.txt pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
COPY src ./src
RUN pip install --no-deps .
FROM ${PYTHON_IMAGE} AS production
ENV VIRTUAL_ENV=/opt/venv \
PATH=/opt/venv/bin:$PATH \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONHASHSEED=random
RUN apt-get update \
&& apt-get install --yes --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd --gid 10001 feedback \
&& useradd --uid 10001 --gid 10001 --no-create-home --home-dir /nonexistent \
--shell /usr/sbin/nologin feedback \
&& mkdir --parents /app /data \
&& chown 10001:10001 /data
COPY --from=production-builder --chown=10001:10001 /opt/venv /opt/venv
WORKDIR /app
USER 10001:10001
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["python", "-c", "import socket; socket.create_connection(('127.0.0.1', 8080), 2).close()"]
ENTRYPOINT ["python", "-m", "feedback"]