-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (43 loc) · 2.04 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (43 loc) · 2.04 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
# syntax=docker/dockerfile:1@sha256:87999aa3d42bdc6bea60565083ee17e86d1f3339802f543c0d03998580f9cb89
FROM python:3.14@sha256:5f1cdbcab9a50594a79502dd73e885456d2a2fc31f1a1fa18484815b37ee9152 AS builder
# Set working directory
WORKDIR /app
# Copy dependency files for layer caching
COPY constraints.txt requirements.txt ./
# Install security-patched, pinned pip first, then dependencies. The runtime
# stage copies this upgraded pip installation from the builder.
RUN --mount=type=cache,target=/root/.cache/pip \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
pip install --no-cache-dir --require-hashes -r constraints.txt && \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
pip install --no-cache-dir --require-hashes -r requirements.txt
# Production stage
FROM python:3.14-slim@sha256:cea0e6040540fb2b965b6e7fb5ffa00871e632eef63719f0ea54bca189ce14a6
# The release workflow injects its computed version once for every runtime
# surface. Unversioned local builds deliberately fall back to package metadata
# or 0.0.0+unknown instead of claiming to be a published release.
ARG STAMPBOT_VERSION
ENV STAMPBOT_VERSION=${STAMPBOT_VERSION}
# Apply current Debian security updates, then create the non-root user
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/* && \
useradd -m -u 1000 stampbot && \
mkdir -p /app && \
chown -R stampbot:stampbot /app
WORKDIR /app
# Copy Python dependencies from builder
COPY --from=builder /usr/local/lib/python3.14/site-packages /usr/local/lib/python3.14/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --chown=stampbot:stampbot stampbot/ ./stampbot/
COPY --chown=stampbot:stampbot pyproject.toml settings.toml ./
# Switch to non-root user
USER stampbot
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
# Run application
CMD ["python", "-m", "stampbot"]