-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (54 loc) · 2.61 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (54 loc) · 2.61 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
# ============================================================
# SmartNode — Multi-stage Dockerfile (production)
# ============================================================
# Stage 1: builder — install locked dependencies into a venv
# Stage 2: runtime — slim image, non-root user, gunicorn WSGI
# ============================================================
# ------ Stage 1: builder -----------------------------------------------
FROM python:3.11-slim AS builder
WORKDIR /build
# Install build tools needed by some wheels
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Copy only the dependency manifests first (layer-cache friendly)
COPY requirements.txt ./
# Create an isolated virtualenv and install locked runtime deps + gunicorn
RUN python -m venv /opt/venv \
&& /opt/venv/bin/pip install --upgrade pip --no-cache-dir \
&& /opt/venv/bin/pip install --no-cache-dir --require-hashes -r requirements.txt \
&& /opt/venv/bin/pip install --no-cache-dir "gunicorn>=22.0,<24.0"
# ------ Stage 2: runtime -----------------------------------------------
FROM python:3.11-slim AS runtime
# OCI image labels — static values are set here; dynamic labels
# (version, revision, created) are injected by docker/metadata-action
# in the CI publish workflow via --label flags at build time.
LABEL org.opencontainers.image.title="SmartNode" \
org.opencontainers.image.description="Space-Based Intelligent Relay Simulation Platform" \
org.opencontainers.image.source="https://github.com/Tong89/smartNode" \
org.opencontainers.image.licenses="MIT"
# Runtime system dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user/group for the application
RUN groupadd --gid 1001 smartnode \
&& useradd --uid 1001 --gid smartnode --shell /bin/bash --create-home smartnode
# Copy the pre-built virtualenv from the builder stage
COPY --from=builder /opt/venv /opt/venv
# Ensure the venv is on PATH
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
# Copy application source code (respects .dockerignore)
COPY --chown=smartnode:smartnode . .
# Copy and configure the entrypoint script
COPY --chown=smartnode:smartnode docker/entrypoint.sh /app/docker/entrypoint.sh
RUN chmod +x /app/docker/entrypoint.sh
# Switch to non-root user
USER smartnode
# Expose the default service port
EXPOSE 5000
# Use tini as PID-1 (proper signal propagation and zombie reaping)
ENTRYPOINT ["tini", "--", "/app/docker/entrypoint.sh"]