Skip to content

Commit 612c2e2

Browse files
committed
Simple uv setup.
1 parent 3b61430 commit 612c2e2

File tree

10 files changed

+2132
-66
lines changed

10 files changed

+2132
-66
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ repos:
2626
entry: bash -c "cd frontend && npx prettier src --write"
2727
language: system
2828
- repo: https://github.com/psf/black
29-
rev: 23.11.0
29+
rev: 24.10.0
3030
hooks:
3131
- id: black
3232
- repo: https://github.com/PyCQA/isort
33-
rev: 5.12.0
33+
rev: 5.13.2
3434
hooks:
3535
- id: isort
3636
args: [ "--profile=black" ]
3737
- repo: https://github.com/pre-commit/pre-commit-hooks
38-
rev: v4.5.0
38+
rev: v5.0.0
3939
hooks:
4040
- id: check-yaml
4141
exclude: deployments/kubernetes/charts
4242
- id: end-of-file-fixer
4343
exclude: 'openapi.json|frontend/src/openapi/v2/'
4444
- id: trailing-whitespace
4545
exclude: 'openapi.json|frontend/src/openapi/v2/'
46-
- repo: https://github.com/shellcheck-py/shellcheck-py
47-
rev: v0.9.0.6
48-
hooks:
49-
- id: shellcheck
46+
# - repo: https://github.com/shellcheck-py/shellcheck-py
47+
# rev: v0.10.0.1
48+
# hooks:
49+
# - id: shellcheck
5050
- repo: https://github.com/PyCQA/flake8
51-
rev: 6.1.0
51+
rev: 7.1.1
5252
hooks:
5353
- id: flake8

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

backend/Dockerfile

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
FROM python:3.9
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim
23

3-
WORKDIR /code
4+
# Install the project into `/app`
5+
WORKDIR /app
46

5-
# set python env variables
6-
ENV PYTHONDONTWRITEBYTECODE 1
7-
ENV PYTHONUNBUFFERED 1
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
89

9-
# install pipenv
10-
RUN pip install pipenv
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
1112

12-
# copy required pipenv files
13-
COPY ./Pipfile ./Pipfile.lock /code/
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev
1418

15-
# install requirements locally in the project at /code/.venv
16-
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
19+
# Then, add the rest of the project source code and install it
20+
# Installing separately from its dependencies allows optimal layer caching
21+
ADD backend /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
--mount=type=bind,source=uv.lock,target=uv.lock \
24+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
25+
uv sync --frozen --no-dev
1726

18-
# add requirements to path
19-
ENV PATH="/code/.venv/bin:$PATH"
27+
# Place executables in the environment at the front of the path
28+
ENV PATH="/app/.venv/bin:$PATH"
2029

21-
# copy app code at end to make it easier to change code and not have to rebuild requirement layers
22-
COPY ./app /code/app
30+
# Reset the entrypoint, don't invoke `uv`
31+
ENTRYPOINT []
2332

2433
# launch app using uvicorn
2534
# Number of recommended workers is 2 x number_of_cores +1

backend/heartbeat.Dockerfile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
FROM python:3.9
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim
23

3-
WORKDIR /code
4+
# Install the project into `/app`
5+
WORKDIR /app
46

5-
# set python env variables
6-
ENV PYTHONDONTWRITEBYTECODE 1
7-
ENV PYTHONUNBUFFERED 1
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
89

9-
# install pipenv
10-
RUN pip install pipenv
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
1112

12-
# copy required pipenv files
13-
COPY ./Pipfile ./Pipfile.lock /code/
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev
1418

15-
# install requirements locally in the project at /code/.venv
16-
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
19+
# Then, add the rest of the project source code and install it
20+
# Installing separately from its dependencies allows optimal layer caching
21+
ADD backend /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
--mount=type=bind,source=uv.lock,target=uv.lock \
24+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
25+
uv sync --frozen --no-dev
1726

18-
# add requirements to path
19-
ENV PATH="/code/.venv/bin:$PATH"
27+
# Place executables in the environment at the front of the path
28+
ENV PATH="/app/.venv/bin:$PATH"
2029

21-
ENV PYTHONPATH=/code
22-
23-
# copy app code at end to make it easier to change code and not have to rebuild requirement layers
24-
COPY ./app /code/app
25-
COPY ./heartbeat_listener.py /code/heartbeat_listener.py
30+
# Reset the entrypoint, don't invoke `uv`
31+
ENTRYPOINT []
2632

2733
CMD ["python", "heartbeat_listener.py"]

backend/messages.Dockerfile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
FROM python:3.9
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim
23

3-
WORKDIR /code
4+
# Install the project into `/app`
5+
WORKDIR /app
46

5-
# set python env variables
6-
ENV PYTHONDONTWRITEBYTECODE 1
7-
ENV PYTHONUNBUFFERED 1
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
89

9-
# install pipenv
10-
RUN pip install pipenv
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
1112

12-
# copy required pipenv files
13-
COPY ./Pipfile ./Pipfile.lock /code/
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev
1418

15-
# install requirements locally in the project at /code/.venv
16-
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
19+
# Then, add the rest of the project source code and install it
20+
# Installing separately from its dependencies allows optimal layer caching
21+
ADD backend /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
--mount=type=bind,source=uv.lock,target=uv.lock \
24+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
25+
uv sync --frozen --no-dev
1726

18-
# add requirements to path
19-
ENV PATH="/code/.venv/bin:$PATH"
27+
# Place executables in the environment at the front of the path
28+
ENV PATH="/app/.venv/bin:$PATH"
2029

21-
ENV PYTHONPATH=/code
22-
23-
# copy app code at end to make it easier to change code and not have to rebuild requirement layers
24-
COPY ./app /code/app
25-
COPY ./message_listener.py /code/message_listener.py
30+
# Reset the entrypoint, don't invoke `uv`
31+
ENTRYPOINT []
2632

2733
CMD ["python", "message_listener.py"]

docker-compose.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.7'
2-
31
# Settings and configurations that are common for all minio containers
42
x-minio-common: &minio-common
53
image: quay.io/minio/minio:RELEASE.2022-01-25T19-56-04Z
@@ -40,7 +38,7 @@ services:
4038
image: 'clowder/clowder2-backend:2.0.0-beta.3'
4139
restart: unless-stopped
4240
build:
43-
context: ./backend
41+
dockerfile: backend/Dockerfile
4442
networks:
4543
- clowder2
4644
environment:
@@ -102,8 +100,7 @@ services:
102100
extractors-heartbeat:
103101
image: "clowder/clowder2-heartbeat:main"
104102
build:
105-
context: backend
106-
dockerfile: heartbeat.Dockerfile
103+
dockerfile: backend/heartbeat.Dockerfile
107104
networks:
108105
- clowder2
109106
restart: unless-stopped
@@ -119,8 +116,7 @@ services:
119116
extractors-messages:
120117
image: "clowder/clowder2-messages:main"
121118
build:
122-
context: backend
123-
dockerfile: messages.Dockerfile
119+
dockerfile: backend/messages.Dockerfile
124120
environment:
125121
MONGODB_URL: mongodb://mongo:27017
126122
RABBITMQ_HOST: ${RABBITMQ_HOST:-rabbitmq}

docs/docs/devs/uv.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Building with uv
2+
3+
Migrating to https://docs.astral.sh/uv/.
4+
5+
1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/)
6+
2. Install dependencies: `uv sync --dev`
7+
3. Activate environment: `source .venv/bin/activate`

pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[project]
2+
name = "clowder2"
3+
version = "2.0.0-beta.4"
4+
description = """Clowder is a cloud native data management framework to support any research domain. Clowder was
5+
developed to help researchers and scientists in data intensive domains manage raw data, complex
6+
metadata, and automatic data pipelines."""
7+
readme = "README.md"
8+
requires-python = ">=3.10"
9+
dependencies = ["fastapi==0.95.1", "pydantic==1.10.13", "uvicorn==0.21.1", "motor==3.1.2", "pymongo==4.8.0",
10+
"beanie==1.18.0", "passlib==1.7.4", "bcrypt==4.0.1", "pyjwt==2.6.0", "minio==7.1.14", "python-multipart==0.0.6",
11+
"email-validator==2.0.0.post2", "python-keycloak==2.15.3", "pika==1.3.1", "aio-pika==9.0.5", "elasticsearch==8.7.0",
12+
"rocrate==0.7.0", "itsdangerous==2.1.2", "setuptools"]
13+
14+
[dependency-groups]
15+
dev = [
16+
"requests==2.28.2",
17+
"pytest==7.3.1",
18+
"pytest-asyncio==0.21.0",
19+
"black==23.3.0",
20+
"faker==18.4.0",
21+
"pika-stubs>=0.1.3",
22+
"ruff>=0.8.0",
23+
"pre-commit>=4.0.1",
24+
"shellcheck-py>=0.10.0.1",
25+
]
26+
docs = [
27+
"mkdocs-material"
28+
]

0 commit comments

Comments
 (0)