-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (35 loc) · 1.71 KB
/
Copy pathDockerfile
File metadata and controls
48 lines (35 loc) · 1.71 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
# ---------------------------------------------------------------------------
# Multi-stage Docker build for HPC Workload Optimizer
# ---------------------------------------------------------------------------
# ---- Stage 1: builder – install Python dependencies into a virtual-env ----
# Pin digest for reproducible builds – update periodically via:
# docker manifest inspect python:3.12-slim
FROM python:3.12-slim@sha256:48006ff57afe15f247ad3da166e9487da0f66a94adbc92810b0e189382d79246 AS builder
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.lock /tmp/requirements.lock
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r /tmp/requirements.lock
# ---- Stage 2: runtime – lean image with only what we need -----------------
FROM python:3.12-slim@sha256:48006ff57afe15f247ad3da166e9487da0f66a94adbc92810b0e189382d79246 AS runtime
# Install curl for the health-check probe and create non-root user
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --create-home --uid 1000 appuser
# Copy the pre-built virtual-env from the builder stage
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /app
# Copy project source and install the package itself
COPY pyproject.toml README.md ./
COPY python/ python/
COPY schemas/ schemas/
COPY configs/ configs/
RUN pip install --no-cache-dir . \
&& chown -R appuser:appuser /app
USER appuser
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl --fail http://localhost:8080/health || exit 1
ENTRYPOINT ["hpcopt", "serve", "api", "--host", "0.0.0.0", "--port", "8080"]