Skip to content

Commit

Permalink
use uv sync instead of pip install requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Feb 6, 2025
1 parent df1968e commit c1df809
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1,195 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

# Exclude the following files and directories from the Docker build context
# Exclude the following files and directories from the Docker build context
.venv
.env
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

43 changes: 24 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN uv venv /opt/invenio/.venv
# Use the virtual environment automatically
ENV VIRTUAL_ENV=/opt/invenio/.venv \
UV_PROJECT_ENVIRONMENT=/opt/invenio/.venv \
# Place entry points in the environment at the front of the path
PATH="/opt/invenio/.venv/bin:$PATH" \
WORKING_DIR=/opt/invenio \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=0 \
INVENIO_INSTANCE_PATH=/opt/invenio/var/instance

WORKDIR ${INVENIO_INSTANCE_PATH}

COPY pyproject.toml requirements.txt ./
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install -r requirements.txt
uv sync --frozen --no-install-project --no-dev
COPY . .

COPY site ${INVENIO_INSTANCE_PATH}/site
Expand All @@ -44,42 +48,43 @@ COPY app_data ${INVENIO_INSTANCE_PATH}/app_data
COPY translations ${INVENIO_INSTANCE_PATH}/translations
COPY ./invenio.cfg ${INVENIO_INSTANCE_PATH}

# Install Python dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev

# Build Javascript assets
RUN --mount=type=cache,target=/var/cache/assets uv run invenio collect --verbose && uv run invenio webpack buildall
RUN --mount=type=cache,target=/var/cache/assets invenio collect --verbose && invenio webpack buildall

FROM python:3.12-slim-bookworm AS runtime

# Install OS package dependencies
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt apt-get update -y --fix-missing && \
apt-get install apt-utils gpg libcairo2 debian-keyring debian-archive-keyring apt-transport-https curl -y --no-install-recommends && \
# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg && \
# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list && \
apt update && apt-get clean
apt-get clean

ENV VIRTUAL_ENV=/opt/invenio/.venv \
PATH="/opt/invenio/.venv/bin:$PATH" \
WORKING_DIR=/opt/invenio \
INVENIO_INSTANCE_PATH=/opt/invenio/var/instance

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY --from=builder ${INVENIO_INSTANCE_PATH}/site ${INVENIO_INSTANCE_PATH}/site
COPY --from=builder ${INVENIO_INSTANCE_PATH}/static ${INVENIO_INSTANCE_PATH}/static
COPY --from=builder ${INVENIO_INSTANCE_PATH}/assets ${INVENIO_INSTANCE_PATH}/assets
COPY --from=builder ${INVENIO_INSTANCE_PATH}/templates ${INVENIO_INSTANCE_PATH}/templates
COPY --from=builder ${INVENIO_INSTANCE_PATH}/app_data ${INVENIO_INSTANCE_PATH}/app_data
COPY --from=builder ${INVENIO_INSTANCE_PATH}/translations ${INVENIO_INSTANCE_PATH}/translations
COPY --from=builder ${INVENIO_INSTANCE_PATH}/invenio.cfg ${INVENIO_INSTANCE_PATH}/invenio.cfg
# Create invenio user and set appropriate permissions
ENV INVENIO_USER_ID=1000
RUN adduser invenio --uid ${INVENIO_USER_ID} --gid 0 --no-create-home --disabled-password

COPY --from=builder --chown=invenio:root ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/site ${INVENIO_INSTANCE_PATH}/site
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/static ${INVENIO_INSTANCE_PATH}/static
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/assets ${INVENIO_INSTANCE_PATH}/assets
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/templates ${INVENIO_INSTANCE_PATH}/templates
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/app_data ${INVENIO_INSTANCE_PATH}/app_data
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/translations ${INVENIO_INSTANCE_PATH}/translations
COPY --from=builder --chown=invenio:root ${INVENIO_INSTANCE_PATH}/invenio.cfg ${INVENIO_INSTANCE_PATH}/invenio.cfg
COPY ./Caddyfile /etc/caddy/Caddyfile

COPY ./setup.sh /opt/invenio/.venv/bin/setup.sh

WORKDIR ${WORKING_DIR}/src

# Create invenio user and set appropriate permissions
ENV INVENIO_USER_ID=1000
RUN adduser invenio --uid ${INVENIO_USER_ID} --gid 0 --no-create-home --disabled-password && \
chown -R invenio:root /opt/invenio/src && \
chown -R invenio:root /opt/invenio/var
# USER invenio

EXPOSE 5000
Expand Down
28 changes: 14 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

services:
proxy:
image: caddy:2.8.1
image: caddy:2.8.4
restart: "unless-stopped"
ports:
- "80:80"
Expand Down Expand Up @@ -111,8 +111,8 @@ services:
condition: service_started
cache:
condition: service_started
db:
condition: service_started
# db:
# condition: service_started
worker:
command: "celery -A invenio_app.celery worker --beat --events --loglevel=WARNING"
image: ghcr.io/front-matter/invenio-rdm-starter:latest
Expand Down Expand Up @@ -153,22 +153,22 @@ services:
condition: service_started
cache:
condition: service_started
db:
condition: service_started
# db:
# condition: service_started
cache:
image: valkey/valkey:7.2.5-bookworm
restart: "unless-stopped"
ports:
- "6379:6379"
db:
image: postgres:16.4-bookworm
restart: "unless-stopped"
environment:
- POSTGRES_USER=${POSTGRES_USER:-inveniordm}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-inveniordm}
- POSTGRES_DB=${POSTGRES_DB:-inveniordm}
ports:
- 5432:5432
# db:
# image: postgres:16.4-bookworm
# restart: "unless-stopped"
# environment:
# - POSTGRES_USER=${POSTGRES_USER:-inveniordm}
# - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-inveniordm}
# - POSTGRES_DB=${POSTGRES_DB:-inveniordm}
# ports:
# - 5432:5432
search:
image: opensearchproject/opensearch:2.12.0
restart: "unless-stopped"
Expand Down
10 changes: 3 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "invenio-rdm-starter"
version = "0.5.1"
version = "12.0.13"
description = "Starter for the turn-key research data management repository"
authors = [
{ name = "Martin Fenner", email = "[email protected]" }
Expand All @@ -10,15 +10,11 @@ requires-python = ">=3.12"
license = "MIT"
dependencies = [
"invenio-app-rdm~=12.0.13",
"invenio-rdm-records~=10.8.6",
"invenio-records-resources~=5.10.0",
"invenio-search[opensearch2]~=2.4.1",
"invenio-s3~=1.0.0",
"idutils~=1.4.0",
"babel-edtf~=1.2.0",
"importlib-metadata~=6.11.0",
"invenio-s3~=1.0.7",
"gunicorn~=22.0.0",
"ruff>=0.9.0",
"commonmeta-py>=0.8.6",
]

[build-system]
Expand Down
Loading

0 comments on commit c1df809

Please sign in to comment.