Skip to content

Commit

Permalink
chore: manage packages in Dockerfile with uv instead of poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter committed Jan 31, 2025
1 parent 2783345 commit ee3d5d1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 50 deletions.
36 changes: 26 additions & 10 deletions apps/openchallenges/data-lambda/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
FROM python:3.13.0-slim-bullseye AS builder
FROM ghcr.io/astral-sh/uv:0.5.14 AS uv

# Install the same version of Poetry as inside the dev container
RUN pip install --no-cache-dir poetry==1.8.3
# First, bundle the dependencies into the task root.
FROM public.ecr.aws/lambda/python:3.11 AS builder

# Enable bytecode compilation, to improve cold-start performance.
ENV UV_COMPILE_BYTECODE=1

# Disable installer metadata, to create a deterministic layer.
ENV UV_NO_INSTALLER_METADATA=1

# Enable copy mode to support bind mount caching.
ENV UV_LINK_MODE=copy

# Copy uv binary
COPY --from=uv /uv /bin/uv

# Copy dependency files
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN poetry export --without-hashes --format=requirements.txt > requirements.txt
COPY uv.lock pyproject.toml ./

# Generate requirements.txt and install dependencies
RUN uv export --frozen --no-emit-workspace --no-dev --no-editable -o requirements.txt && \
uv pip install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"

FROM public.ecr.aws/lambda/python:3.13
FROM public.ecr.aws/lambda/python:3.11

COPY --from=builder /app/requirements.txt ${LAMBDA_TASK_ROOT}/
COPY openchallenges_data_lambda/app.py ${LAMBDA_TASK_ROOT}/
# Copy the runtime dependencies from the builder stage.
COPY --from=builder ${LAMBDA_TASK_ROOT} ${LAMBDA_TASK_ROOT}

RUN python3.13 -m pip install --no-cache-dir -r requirements.txt -t .
# Copy the application code.
COPY openchallenges_data_lambda/app.py ${LAMBDA_TASK_ROOT}/app

# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambda_handler"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@fortawesome/free-solid-svg-icons": "6.6.0",
"@nrwl/js": "19.8.0",
"@nx-tools/container-metadata": "6.1.1",
"@nx-tools/nx-container": "6.1.1",
"@nx-tools/nx-container": "6.2.0",
"@nx/angular": "20.3.1",
"@nx/cypress": "20.3.1",
"@nx/devkit": "20.3.1",
Expand Down
Loading

0 comments on commit ee3d5d1

Please sign in to comment.