Skip to content

Commit

Permalink
Switch API package management from Pipenv to PDM (#4107)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb authored Apr 23, 2024
1 parent da3101d commit 7dac3ad
Show file tree
Hide file tree
Showing 35 changed files with 2,849 additions and 3,197 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ archive/ @WordPress/openverse-catalog
dag-sync.sh @WordPress/openverse-catalog

api/ @WordPress/openverse-api
packages/python/ @WordPress/openverse-api
ingestion_server/ @WordPress/openverse-api
sample_data/ @WordPress/openverse-api
load_sample_data.sh @WordPress/openverse-api
Expand Down
1 change: 1 addition & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ catalog:
- docker-compose.yml
api:
- api/**
- packages/python/**
- docker/db/**
- docker/es/**
- docker/nginx/**
Expand Down
5 changes: 3 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"addLabels": ["🧱 stack: frontend"]
},
{
"matchFileNames": ["api/**"],
"matchFileNames": ["{api,packages/python}/**"],
"addLabels": ["🧱 stack: api"]
},
{
Expand All @@ -73,7 +73,8 @@
"api/**",
"catalog/**",
"ingestion_server/**",
"documentation/**"
"documentation/**",
"packages/python/openverse-attribution/**"
]
},
{
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ logs/
# Python environments
env/
venv/
.venv/
pip-log.txt

# Python
Expand Down Expand Up @@ -65,3 +66,7 @@ ingestion_server.log
*.tsbuildinfo

dist

# PDM
.pdm-python
.pdm-build
3 changes: 3 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.pytest_cache/
test/

# New virtualenv will be created in the container
.venv/
29 changes: 16 additions & 13 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

# Automatically build image using Python version specified in the `Pipfile`.
# Automatically build image using Python version specified in `pyproject.toml`
ARG API_PY_VERSION

##################
Expand All @@ -26,23 +26,25 @@ ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_NO_COLOR=1

# Activate the virtualenv
ENV PATH="/venv/bin:$PATH"

# - Install system packages needed for building Python dependencies
# - Create a virtualenv inside `/venv`
# - Install Pipenv to install Python dependencies
# - Install PDM to install Python dependencies
RUN apt-get update \
&& apt-get install -y python3-dev git \
&& rm -rf /var/lib/apt/lists/* \
&& python -m venv /venv \
&& pip install --upgrade pipenv
&& pip install pdm~=2.14

# Copy subpackages from additional build-context 'packages'
COPY --from=packages openverse-attribution ./packages/python/openverse-attribution

# Copy the Python project manifest and PDM lockfile into the container
COPY pyproject.toml pdm.lock ./

# Copy the Pipenv files into the container
COPY Pipfile Pipfile.lock ./
# Pass additional arguments when installing Python packages with PDM
ARG PDM_INSTALL_ARGS='--no-editable'

# Install Python dependencies system-wide (uses the active virtualenv)
RUN pipenv install --system --deploy --dev
# Install Python dependencies into a new virtualenv
RUN pdm install --check --frozen-lockfile $PDM_INSTALL_ARGS

#######
# API #
Expand All @@ -58,14 +60,14 @@ ENV PIP_NO_CACHE_DIR=1
ENV PIP_NO_COLOR=1

# Activate the virtualenv
ENV PATH="/venv/bin:$PATH"
ENV PATH="/.venv/bin:$PATH"

WORKDIR /api

ADD api/utils/fonts/SourceSansPro-Bold.ttf /usr/share/fonts/truetype/SourceSansPro-Bold.ttf

# Copy virtualenv from the builder image
COPY --from=builder /venv /venv
COPY --from=builder /.venv /.venv

# Copy `audiowaveform` dependencies. This is unreliable as we use
# The `latest` version of the audiowaveform image which may introduce
Expand Down Expand Up @@ -96,6 +98,7 @@ RUN useradd --create-home opener \
USER opener

# Copy code into the final image
COPY --chown=opener --from=packages openverse-attribution /packages/python/openverse-attribution/
COPY --chown=opener . /api/

# Collect static assets, these are used by the next stage, `nginx`
Expand Down
50 changes: 0 additions & 50 deletions api/Pipfile

This file was deleted.

Loading

0 comments on commit 7dac3ad

Please sign in to comment.