Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
#THIS DOCKERFILE RUNS THE WEB API

# Use the official Python base image
# Use slim uv-based Python image with Python 3.12
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy
# Environment optimizations for uv and path
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
PATH="/app/.venv/bin:$PATH"

# Set the working directory in the container
# Set working directory
WORKDIR /app

# Install the project's dependencies using the lockfile and settings
# Install system dependencies in one clean layer
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy pyproject + lock file first for layer caching
COPY pyproject.toml uv.lock ./

# Install only dependencies (for optimal caching)
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 --frozen --no-install-project --no-dev

# Install the Python dependencies
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y git

COPY ./chap_core ./chap_core
COPY ./config ./config
COPY ./scripts/seed.py ./scripts/seed.py
COPY ./pyproject.toml .
COPY ./uv.lock .
COPY ./README.md .
# Copy project files
COPY chap_core/ chap_core/
COPY config/ config/
COPY scripts/seed.py scripts/seed.py
COPY README.md .

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
# Install project itself (dev=False, project=True)
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
41 changes: 21 additions & 20 deletions Dockerfile.inla
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# If you have issues with platform compatibility and uv, plesae build with
# docker build --platform=linux/amd64 -f Dockerfile.inla .
# ⚠️ NOTE: If you are on Apple Silicon (arm64), build with:
# docker build --platform=linux/amd64 -f Dockerfile.inla .
# INLA base image is only available for amd64

FROM ivargr/r_inla

# Copy uv and uvx CLI tools from base Python/uv image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Enable bytecode compilation and safe volume handling
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
# Set up env vars for uv and Python
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
PATH="/app/.venv/bin:$PATH"

# Set working directory
WORKDIR /app

# Install all system packages in a single layer
# Install system dependencies in one efficient layer
RUN apt-get update && \
apt-get install -y --no-install-recommends \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git \
libncurses-dev \
libreadline-dev \
libbz2-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# First install only the dependencies using the lockfile (no source code yet)
# Copy only dependency files first for better layer caching
COPY pyproject.toml uv.lock ./

# Install Python dependencies only (no dev, no project code yet)
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 --frozen --no-install-project --no-dev

# Copy source files
COPY ./chap_core ./chap_core
COPY ./config ./config
COPY ./pyproject.toml .
COPY ./uv.lock .
COPY ./README.md .
# Copy application source files
COPY chap_core/ chap_core/
COPY config/ config/
COPY README.md .

# Now install the project (with dependencies already cached)
# Install the project itself now that dependencies are cached
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

# Final environment path setup
ENV PATH="/app/.venv/bin:$PATH"
Loading