Skip to content

Commit c50ceb8

Browse files
committed
Switch to uv
1 parent 827d0ec commit c50ceb8

9 files changed

Lines changed: 118 additions & 20 deletions

File tree

.diploi/helm/app.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ spec:
4141
command:
4242
- /bin/sh
4343
- -c
44-
- |
45-
python -m venv --copies .venv
46-
. ./.venv/bin/activate
47-
pip install --no-cache-dir -r requirements.txt
44+
- uv sync
4845
workingDir: /app/{{ .Values.identifier }}
4946
volumeMounts:
5047
- name: app-mount

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
layout python-venv .venv
1+
source .venv/bin/activate

.python-version

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

Dockerfile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
FROM python:3.13-slim AS base
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.13-alpine
23

34
# This will be set by the GitHub action to the folder containing this component.
45
ARG FOLDER=/app
56

6-
COPY . /app
77
WORKDIR ${FOLDER}
88

9-
# Install dependencies
10-
RUN pip install --no-cache-dir -r requirements.txt
9+
# Enable bytecode compilation
10+
ENV UV_COMPILE_BYTECODE=1
11+
12+
# Copy from the cache instead of linking since it's a mounted volume
13+
ENV UV_LINK_MODE=copy
14+
15+
# Ensure installed tools can be executed out of the box
16+
ENV UV_TOOL_BIN_DIR=/usr/local/bin
17+
18+
COPY . /app
19+
RUN uv sync --locked --no-dev
20+
21+
# Place executables in the environment at the front of the path
22+
ENV PATH="$FOLDER/.venv/bin:$PATH"
23+
24+
# Reset the entrypoint, don't invoke `uv`
25+
ENTRYPOINT []
1126

1227
EXPOSE 8000
1328
ENV PORT=8000
1429
ENV HOST="0.0.0.0"
1530

16-
CMD ["python", "src/main.py"]
31+
CMD ["uv", "run", "--frozen", "src/main.py"]

Dockerfile.dev

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
FROM python:3.13-slim
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.13-alpine
23

34
# This will be set by the GitHub action to the folder containing this component.
45
ARG FOLDER=/app
56

67
COPY --chown=1000:1000 . /app
78
WORKDIR ${FOLDER}
89

10+
# Enable bytecode compilation
11+
ENV UV_COMPILE_BYTECODE=1
12+
13+
# Copy from the cache instead of linking since it's a mounted volume
14+
ENV UV_LINK_MODE=copy
15+
16+
# Ensure installed tools can be executed out of the box
17+
ENV UV_TOOL_BIN_DIR=/usr/local/bin
18+
19+
# Place executables in the environment at the front of the path
20+
ENV PATH="$FOLDER/.venv/bin:$PATH"
21+
922
# Install Node.js and nodemon for easy watch mode with Python
1023
USER root
1124
RUN apt-get update \
@@ -18,11 +31,11 @@ RUN apt-get update \
1831

1932
USER 1000:1000
2033

21-
# Setup venv
22-
ENV PATH="$FOLDER/.venv/bin:$PATH"
34+
# Reset the entrypoint, don't invoke `uv`
35+
ENTRYPOINT []
2336

2437
EXPOSE 8000
2538
ENV PORT=8000
2639
ENV HOST="0.0.0.0"
2740

28-
CMD ["/usr/bin/nodemon", "--delay", "1", "--exec", ".venv/bin/python", "src/main.py"]
41+
CMD ["/usr/bin/nodemon", "--delay", "1", "--exec", ".venv/bin/python", "src/main.py"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# Python Component for Diploi
44

5-
Uses the official [python](https://hub.docker.com/_/python) Docker image.
5+
Uses [uv](https://docs.astral.sh/uv/) to manage Python versions & packages.
66

77
## Operation
88

99
### Development
1010

11-
Will activate a virtual environment in `.venv` and run `pip install -r requirements.txt` when component is first initialized, and `python src/main.py` when deployment is started.
11+
Will activate a virtual environment in `.venv` and run `uv sync` when component is first initialized, and `python src/main.py` when deployment is started.
1212

1313
### Production
1414

15-
Will build a production ready image. Image runs `pip install -r requirements.txt` when being created. Once the image runs, `python src/main.py` is called.
15+
Will build a production ready image. Image runs `uv sync` when being created. Once the image runs, `python src/main.py` is called.

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "hello-world"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"numpy>=2.3.2",
9+
]

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

uv.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)