Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate first OC Python projects to uv (SMR-2) #2984

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.pdm-build

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
1 change: 0 additions & 1 deletion apps/openchallenges/data-lambda/.python-version

This file was deleted.

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.13 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 pyproject.toml uv.lock ./

# 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

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 ${LAMBDA_TASK_ROOT}/app

# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambda_handler"]
CMD ["app.app.lambda_handler"]
13 changes: 0 additions & 13 deletions apps/openchallenges/data-lambda/install.sh

This file was deleted.

501 changes: 0 additions & 501 deletions apps/openchallenges/data-lambda/poetry.lock

This file was deleted.

2 changes: 1 addition & 1 deletion apps/openchallenges/data-lambda/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prepare": {
"executor": "nx:run-commands",
"options": {
"command": "./install.sh",
"command": "uv sync",
"cwd": "{projectRoot}"
}
},
Expand Down
32 changes: 21 additions & 11 deletions apps/openchallenges/data-lambda/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
[tool.poetry]
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
authors = [
{name = "Verena Chung", email = "verena.chung@sagebase.org"},
]
requires-python = "==3.13.1"
dependencies = [
"requests==2.32.3",
"gspread==6.1.4",
"pandas==2.2.3",
"numpy==2.1.0",
]
name = "openchallenges-data-lambda"
version = "0.1.0"
description = "A containerized AWS Lambda to import challenge data into the OC database"
authors = ["Verena Chung <verena.chung@sagebase.org>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "3.11.10"
requests = "2.32.3"
gspread = "6.1.4"
pandas = "2.2.3"
numpy = "2.1.0"
[dependency-groups]
dev = []
prod = []
test = []

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.uv]
default-groups = []
286 changes: 286 additions & 0 deletions apps/openchallenges/data-lambda/uv.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion apps/openchallenges/edam-etl/.python-version

This file was deleted.

47 changes: 39 additions & 8 deletions apps/openchallenges/edam-etl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
FROM python:3.12.0-slim
FROM ghcr.io/astral-sh/uv:0.5.14 AS uv

# First, bundle the dependencies into the task root.
FROM python:3.12.8-slim 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 uv.lock ./

# 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 "/app"

FROM python:3.12.8-slim

ARG USERNAME=app
ARG USER_UID=1000
Expand All @@ -16,16 +41,22 @@ RUN groupadd --gid "$USER_GID" "$USERNAME" \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

WORKDIR ${APP_DIR}
COPY src src/
COPY pyproject.toml poetry.lock ./
# WORKDIR ${APP_DIR}
# COPY src src/
# COPY pyproject.toml uv.lock ./

# Use the version of Poetry installed in the dev container.
# See /workspaces/sage-monorepo/tools/devcontainers/sage/.devcontainer/Dockerfile
RUN pip install --no-cache-dir poetry==1.6.1 \
&& poetry config --local virtualenvs.create false \
&& poetry install --with prod --no-root --no-interaction --no-ansi \
&& pip cache purge
# RUN pip install --no-cache-dir uv==0.5.14 \
# && poetry config --local virtualenvs.create false \
# && poetry install --with prod --no-root --no-interaction --no-ansi \
# && pip cache purge

# Copy the runtime dependencies from the builder stage.
COPY --from=builder /app /app

# Copy the application code.
COPY ./src /app/src

WORKDIR /
COPY docker-entrypoint.sh ./
Expand Down
Loading
Loading