-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (54 loc) · 2.39 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (54 loc) · 2.39 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
# ------------------------------------------------------------
# Stage 1: Base/builder layer - Setup Python environment
# ------------------------------------------------------------
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
# Configure environment variables
ENV UV_SYSTEM_PYTHON=1
ENV UV_LINK_MODE=copy
# Set working directory
WORKDIR /src/
# Install curl for health checks and procps for pgrep
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get install -y --no-install-recommends \
curl \
procps
# Install Python dependencies using uv
# Mount only the necessary files (dependency definitions)
# This optimizes layer caching - changes to other files won't invalidate this layer
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync \
--all-extras \
--frozen \
--no-install-project
# ------------------------------------------------------------
# Stage 2: Release - Final production image
# ------------------------------------------------------------
FROM builder AS release
# Use SIGINT for stopping the container
# This allows for graceful shutdown and proper cleanup
STOPSIGNAL SIGINT
COPY . /src/
# Copy the uv cache from builder stage and compile bytecode once
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --compile
# Download the TailwindCSS CLI
# Using SQLite memory database and dummy secret key during build
RUN DATABASE_URL=sqlite://:memory: SECRET_KEY=build-key uv run --frozen -m manage tailwind --skip-checks download_cli
# Build the TailwindCSS styles
RUN DATABASE_URL=sqlite://:memory: SECRET_KEY=build-key uv run --frozen -m manage tailwind --skip-checks build
# Collect static files for production serving
RUN DATABASE_URL=sqlite://:memory: SECRET_KEY=build-key uv run --frozen -m manage collectstatic --noinput
CMD ["/src/start-web.sh"]
# Web stage (default)
FROM release AS web
HEALTHCHECK --interval=60s --timeout=10s --start-period=40s --retries=3 \
CMD ["/src/healthcheck-web.sh"]
CMD ["/src/start-web.sh"]
# Worker stage for django-q2
FROM release AS worker
HEALTHCHECK --interval=60s --timeout=30s --start-period=30s --retries=3 \
CMD ["/src/healthcheck-worker.sh"]
CMD ["/src/start-worker.sh"]