Skip to content

Commit 32149ed

Browse files
authored
Use uv instead of poetry (#18)
1 parent 0edf2a5 commit 32149ed

File tree

18 files changed

+983
-1437
lines changed

18 files changed

+983
-1437
lines changed

.devcontainer/devcontainer.json

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

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*
22
!src/
3-
!test/
4-
!poetry.lock
3+
!uv.lock
54
!pyproject.toml
65
!README.md

.github/workflows/quality-assurance.yaml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ concurrency:
1414
cancel-in-progress: true
1515

1616
jobs:
17-
quality-assurance:
18-
name: Check Code Quality
17+
image-build:
18+
name: Check Image Build
1919
timeout-minutes: 10
2020
runs-on: ubuntu-22.04
2121
env:
@@ -39,10 +39,8 @@ jobs:
3939
4040
- name: Build image
4141
uses: docker/build-push-action@v5
42-
id: build-and-push
4342
with:
4443
context: .
45-
target: ci
4644
build-args: |
4745
ARCHIVIST_UID=${{ steps.user-id.outputs.gha_uid }}
4846
ARCHIVIST_GID=${{ steps.user-id.outputs.gha_gid }}
@@ -51,16 +49,33 @@ jobs:
5149
tags: ${{ env.CI_IMAGE_TAG }}
5250
cache-from: type=gha,scope=archivist
5351
cache-to: type=gha,mode=max,scope=archivist
54-
load: true
52+
load: false
53+
54+
code-quality:
55+
name: Check Code Quality
56+
timeout-minutes: 10
57+
runs-on: ubuntu-22.04
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
with:
62+
persist-credentials: false
63+
show-progress: false
64+
65+
- name: Install uv
66+
uses: astral-sh/setup-uv@v5
67+
68+
- name: Install dev and test dependencies
69+
run: uv sync
5570

5671
- name: Check code formatting
57-
run: docker run ${{ env.CI_IMAGE_TAG }} poe format-check
72+
run: uv run poe format-check
5873

5974
- name: Check linting
60-
run: docker run ${{ env.CI_IMAGE_TAG }} poe lint-check
75+
run: uv run poe lint-check
6176

6277
- name: Run static analysis
63-
run: docker run ${{ env.CI_IMAGE_TAG }} poe mypy
78+
run: uv run poe mypy
6479

6580
- name: Run tests
66-
run: docker run ${{ env.CI_IMAGE_TAG }} poe test
81+
run: uv run poe test

.github/workflows/release.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ jobs:
6060
with:
6161
platforms: linux/amd64,linux/arm64
6262
context: .
63-
target: prod
6463
file: Dockerfile
6564
push: true
6665
tags: ${{ steps.params.outputs.tags }}

Dockerfile

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,41 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM python:3.11-slim-bookworm as base
3+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim@sha256:74b8fe8ec5931f3930cfb6c87b46aeb1dbd497a609f6abf860fd0f4390f8b040
44

5-
ARG DEBIAN_FRONTEND=noninteractive
5+
WORKDIR /archivist
66

7-
ENV PYTHONFAULTHANDLER=1 \
8-
PYTHONDONTWRITEBYTECODE=1 \
9-
PYTHONUNBUFFERED=1 \
10-
PYTHONHASHSEED=random \
11-
PIP_NO_CACHE_DIR=off \
12-
PIP_DISABLE_PIP_VERSION_CHECK=on \
13-
PIP_DEFAULT_TIMEOUT=100
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
149

15-
WORKDIR /archivist
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
1612

1713
# fetch container running user from build args
1814
ARG ARCHIVIST_UID=1000
1915
ARG ARCHIVIST_GID=1000
2016

2117
RUN <<EOF
22-
apt-get update
23-
apt-get install --no-install-recommends --yes curl git
2418
# add archivist user that will be used to run container by default
2519
groupadd --gid $ARCHIVIST_GID archivist
2620
useradd --create-home --gid $ARCHIVIST_GID --uid $ARCHIVIST_UID archivist --no-log-init
27-
# make archivist and owner of /opt/venv so it can write to it
28-
mkdir -p /opt/venv
29-
chown -R archivist:archivist /opt/venv /archivist
30-
EOF
31-
32-
ENV POETRY_VERSION=1.7.1 \
33-
POETRY_VIRTUAL_ENV=/opt/venv/poetry
34-
35-
RUN --mount=type=cache,target=/root/.cache/pip/ <<EOF
36-
# create virtual env for poetry
37-
python -m venv $POETRY_VIRTUAL_ENV
38-
# install poetry
39-
$POETRY_VIRTUAL_ENV/bin/pip install poetry~=$POETRY_VERSION
40-
# make poetry available system wide
41-
ln -s $POETRY_VIRTUAL_ENV/bin/poetry /usr/local/bin/poetry
21+
chown -R archivist:archivist /archivist
4222
EOF
4323

4424
USER archivist
4525

46-
# set archivist virtual env path and update PATH to register virtual env binaries
47-
# this will ensure poetry will usie archivist virtual env when installing packages
48-
ENV VIRTUAL_ENV=/opt/venv/archivist
49-
ENV PATH=$VIRTUAL_ENV/bin:$PATH
50-
51-
# create actual virtual env
52-
RUN python -m venv $VIRTUAL_ENV
53-
54-
COPY --chown=archivist:archivist poetry.lock pyproject.toml ./
55-
56-
# install non dev dependencies
57-
RUN --mount=type=cache,uid=$ARCHIVIST_UID,gid=$ARCHIVIST_GID,target=/home/archivist/.cache/pypoetry/ \
58-
poetry install --without dev --no-interaction --no-ansi --no-root --sync
26+
# Install the project's dependencies using the lockfile and settings
27+
RUN --mount=type=cache,uid=$ARCHIVIST_UID,gid=$ARCHIVIST_GID,target=/home/archivist/.cache/uv \
28+
--mount=type=bind,source=uv.lock,target=uv.lock \
29+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
30+
uv sync --locked --no-install-project --no-dev
5931

6032
COPY --chown=archivist:archivist . .
6133

62-
##############################
63-
# Production
64-
##############################
65-
FROM base as prod
34+
RUN --mount=type=cache,uid=$ARCHIVIST_UID,gid=$ARCHIVIST_GID,target=/home/archivist/.cache/uv \
35+
uv sync --locked --no-dev
6636

67-
# install app as binary
68-
RUN --mount=type=cache,uid=$ARCHIVIST_UID,gid=$ARCHIVIST_GID,target=/home/archivist/.cache/pypoetry/ \
69-
poetry install --without dev --no-interaction --no-ansi --sync
37+
ENV PATH="/archivist/.venv/bin:$PATH"
7038

7139
ENTRYPOINT ["archivist"]
7240

7341
CMD ["--help"]
74-
75-
76-
##############################
77-
# CI
78-
##############################
79-
FROM base as ci
80-
81-
# install additional dev dependencies
82-
RUN --mount=type=cache,uid=$ARCHIVIST_UID,gid=$ARCHIVIST_GID,target=/home/archivist/.cache/pypoetry/ \
83-
poetry install --no-interaction --no-ansi --sync
84-
85-
86-
87-
##############################
88-
# Development
89-
##############################
90-
FROM ci as dev
91-
92-
USER root
93-
94-
# Install development tools
95-
RUN <<EOF
96-
apt-get update
97-
apt-get install --no-install-recommends --yes git curl gnupg ssh sudo vim
98-
usermod --shell /usr/bin/bash archivist
99-
echo 'archivist ALL=(root) NOPASSWD:ALL' > /etc/sudoers.d/archivist
100-
chmod 0440 /etc/sudoers.d/archivist
101-
EOF
102-
103-
USER archivist

0 commit comments

Comments
 (0)