-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.worker
More file actions
68 lines (52 loc) · 1.96 KB
/
Dockerfile.worker
File metadata and controls
68 lines (52 loc) · 1.96 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
# syntax=docker/dockerfile:1
# ===================================
# Stage 1: Builder - Install dependencies
# ===================================
FROM python:3.13-slim AS builder
# Install system dependencies and uv
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libpq-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --no-cache-dir uv==0.5.18
WORKDIR /app
# Copy dependency files (lock file ensures reproducible builds)
COPY pyproject.toml uv.lock ./
# Install dependencies using uv sync (respects lock file for reproducibility)
# --frozen ensures lock file is used without modification
# --no-dev excludes development dependencies for production
RUN uv sync --frozen --no-dev
# ===================================
# Stage 2: Runtime - Minimal image
# ===================================
FROM python:3.13-slim
# Install runtime dependencies only (no build tools)
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy virtual environment from builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy application code
COPY . .
# Create non-root user for security
RUN adduser --disabled-password --gecos '' --uid 1000 appuser && \
chown -R appuser:appuser /app
# Use non-root user
USER appuser
# Activate virtual environment
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Health check - verify worker is responsive
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD pgrep -f "python worker.py" || exit 1
# Metadata labels
LABEL org.opencontainers.image.title="Python FastAPI Boilerplate - Temporal Worker"
LABEL org.opencontainers.image.description="Temporal workflow worker for FastAPI boilerplate"
LABEL org.opencontainers.image.version="0.1.0"
LABEL org.opencontainers.image.authors="thaithienvanid"
# Run the Temporal worker
CMD ["python", "worker.py"]