-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (53 loc) · 1.95 KB
/
Dockerfile
File metadata and controls
70 lines (53 loc) · 1.95 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
# ==================================================
# Dependency + test stage
# ==================================================
FROM python:3.11.14-slim-trixie AS build
ARG TRADING_RUNTIME_COMMIT
ENV TRADING_RUNTIME_COMMIT=${TRADING_RUNTIME_COMMIT}
ENV PATH="/install/bin:/install-dev/bin:${PATH}"
ENV PYTHONPATH="/install/lib/python3.11/site-packages"
WORKDIR /workspaces/trading-runtime
# System dependencies for building Python packages & running tests
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
ca-certificates \
build-essential && \
rm -rf /var/lib/apt/lists/*
# Install Python dependencies first (maximizes Docker cache)
COPY requirements.txt requirements-dev.txt .
RUN pip install --upgrade pip \
&& pip install --prefix=/install -r requirements.txt \
&& pip install --prefix=/install-dev -r requirements-dev.txt
# Copy project files
COPY pyproject.toml .
COPY scripts/check.sh .
COPY trading_runtime/ trading_runtime/
COPY tests/ tests/
# Install the package itself
RUN pip install --prefix=/install .
# Run test & quality checks
ENV PYTHONPATH="/install/lib/python3.11/site-packages:/install-dev/lib/python3.11/site-packages"
RUN chmod +x check.sh && ./check.sh
# ==================================================
# Runtime stage (clean production image)
# ==================================================
FROM python:3.11.14-slim-trixie AS runtime
ARG GIT_COMMIT
ARG GIT_BRANCH
ARG GIT_DIRTY
ENV GIT_COMMIT=${GIT_COMMIT} \
GIT_BRANCH=${GIT_BRANCH} \
GIT_DIRTY=${GIT_DIRTY} \
PYTHONUNBUFFERED=1
# Minimal runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Create non-root user for production runtime
RUN adduser --disabled-password --gecos '' appuser
# Copy only installed Python artifacts from build stage
COPY --from=build /install /usr/local
# Drop privileges
USER appuser