Skip to content

Commit

Permalink
chore: migrate agora-data to uv (SMR-10) (#2991)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored Feb 7, 2025
1 parent 429fe97 commit 797ac54
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 853 deletions.
6 changes: 0 additions & 6 deletions apps/agora/data/.dockerignore

This file was deleted.

1 change: 0 additions & 1 deletion apps/agora/data/.python-version

This file was deleted.

50 changes: 34 additions & 16 deletions apps/agora/data/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
FROM ghcr.io/astral-sh/uv:0.5.14 AS uv

# First, bundle the dependencies into the task root.
FROM python:3.11.9-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.11.9-slim

ARG LOCAL_DATA_DIR="./local/data"
ARG USERNAME=app
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ENV APP_DIR=/opt/app \
ENV APP_DIR=/app \
APP_USERNAME=${USERNAME}
ENV PYTHONPATH="${APP_DIR}"

RUN groupadd --gid "$USER_GID" "$USERNAME" \
&& useradd --uid "$USER_UID" --gid "$USER_GID" -m "$USERNAME" \
# Install sudo
&& apt-get update -qq -y && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install --no-install-recommends -qq -y \
gosu \
&& apt-get -y autoclean \
&& apt-get -y clean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

WORKDIR ${APP_DIR}
COPY src src/
COPY pyproject.toml poetry.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 \
# Give APP_USER write permission to directory where synapse data will be written
&& mkdir -p ${LOCAL_DATA_DIR} \
&& chown ${APP_USERNAME} ${LOCAL_DATA_DIR}
# Copy the runtime dependencies from the builder stage.
COPY --from=builder ${APP_DIR} ${APP_DIR}

# Copy the application code.
COPY ./src /${APP_DIR}/src
RUN chown -R ${APP_USERNAME}:${APP_USERNAME} ${APP_DIR}

WORKDIR /
COPY docker-entrypoint.sh ./
Expand Down
790 changes: 0 additions & 790 deletions apps/agora/data/poetry.lock

This file was deleted.

3 changes: 0 additions & 3 deletions apps/agora/data/poetry.toml

This file was deleted.

15 changes: 0 additions & 15 deletions apps/agora/data/prepare-python.sh

This file was deleted.

4 changes: 2 additions & 2 deletions apps/agora/data/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"prepare": {
"executor": "nx:run-commands",
"options": {
"command": "./prepare-python.sh",
"command": "uv sync",
"cwd": "{projectRoot}"
}
},
"serve": {
"executor": "nx:run-commands",
"options": {
"command": "poetry run python src/main.py",
"command": "uv run src/main.py",
"cwd": "{projectRoot}"
}
},
Expand Down
39 changes: 19 additions & 20 deletions apps/agora/data/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
[tool.poetry]
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
authors = [
{name = "Hallie Swan", email = "[email protected]"},
]
requires-python = "==3.11.9"
dependencies = [
"synapseclient==4.3.0",
"pymongo==4.7.3",
]
name = "agora-data"
version = "0.1.0"
description = "Agora Data Release"
authors = ["Hallie Swan <[email protected]>"]
readme = "README.md"
packages = [{include = "src"}]
include = [
{ path = "src/data/collections.csv" },
{ path = "src/data/collections-indexes.json" },
]

[tool.poetry.dependencies]
python = "3.11.9"
synapseclient = "4.3.0"
pymongo = "4.7.3"
[dependency-groups]
dev = []
prod = []
test = []

[tool.poetry.group.dev.dependencies]

[tool.poetry.group.prod.dependencies]

[tool.poetry.group.test.dependencies]

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

Large diffs are not rendered by default.

0 comments on commit 797ac54

Please sign in to comment.