Skip to content

Commit

Permalink
update dockerfile to use uv
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela committed Feb 12, 2025
1 parent 90c83b2 commit 6a2912e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
39 changes: 22 additions & 17 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
FROM python:3.11-slim as base
LABEL maintainer="[email protected]"
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS production

# Requirement of fiona and gdal.
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends libexpat1; \
rm -rf /var/lib/apt/lists/*
WORKDIR /app

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

FROM base as production
ENV NAME api
ENV APP_HOME /opt/$NAME
ENV DATA_HOME ${APP_HOME}/data
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

WORKDIR $APP_HOME
# Install the project's dependencies using the lockfile and settings
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 . .
# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

RUN pip install --no-cache-dir -r requirements.txt
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

EXPOSE 8000
# Reset the entrypoint, don't invoke `uv`
ENTRYPOINT []

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--root-path", "/api/"]

FROM production as development
FROM production AS development

RUN pip install --no-cache-dir -r requirements-dev.txt
RUN uv sync --frozen --dev
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.9'
services:
api:
build:
Expand Down

0 comments on commit 6a2912e

Please sign in to comment.