Skip to content

Commit 22372cb

Browse files
committed
use image with pre-installed python and uv
only install `make` in dev use uv's Docker best practices i.e. caching
1 parent c76e27a commit 22372cb

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

backend/Dockerfile

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ ARG TYPE=deploy
44
# ─────────────────────────────────────────────────────────────
55
# Base stage - common setup
66
# ─────────────────────────────────────────────────────────────
7-
FROM python:3.12-slim AS base
7+
# Use Astral's image with pre-installed UV and Python 3.13
8+
FROM ghcr.io/astral-sh/uv:python3.13-trixie-slim AS base
89

9-
WORKDIR /app
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
1012

11-
# Install system dependencies
12-
RUN apt-get update && apt-get install -y --no-install-recommends \
13-
curl \
14-
build-essential \
15-
&& rm -rf /var/lib/apt/lists/*
16-
17-
# Install uv
18-
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
19-
ENV PATH="/root/.local/bin:$PATH"
13+
WORKDIR /app
2014

2115
# Copy dependency files
2216
COPY pyproject.toml uv.lock* ./
@@ -26,14 +20,24 @@ COPY pyproject.toml uv.lock* ./
2620
# ─────────────────────────────────────────────────────────────
2721
FROM base AS dev
2822

23+
# Install system dependencies (e.g. make)
24+
RUN apt-get update && apt-get install -y --no-install-recommends \
25+
make \
26+
&& rm -rf /var/lib/apt/lists/*
27+
2928
# Install all dependencies including dev group
30-
RUN uv sync
29+
RUN --mount=type=cache,target=/root/.cache/uv \
30+
uv sync --no-install-project --frozen
3131

3232
# Copy all source code and tests
3333
COPY tenantfirstaid/ ./tenantfirstaid/
34-
COPY scripts/ ./scripts/
35-
COPY tests/ ./tests/
36-
COPY Makefile ./
34+
COPY scripts/ ./scripts/
35+
COPY tests/ ./tests/
36+
COPY Makefile ./
37+
38+
# Sync the project
39+
RUN --mount=type=cache,target=/root/.cache/uv \
40+
uv sync --locked
3741

3842
ENV FLASK_ENV=development
3943
ENV ENV=dev
@@ -49,8 +53,12 @@ CMD ["uv", "run", "python", "-m", "tenantfirstaid.app"]
4953
# ─────────────────────────────────────────────────────────────
5054
FROM base AS deploy
5155

56+
# Enable bytecode compilation
57+
ENV UV_COMPILE_BYTECODE=1
58+
5259
# Install only production dependencies
53-
RUN uv sync --no-dev
60+
RUN --mount=type=cache,target=/root/.cache/uv \
61+
uv sync --no-dev
5462

5563
# Copy only application code (no tests)
5664
COPY tenantfirstaid/ ./tenantfirstaid/

0 commit comments

Comments
 (0)