Skip to content

Commit e88f68e

Browse files
authored
Merge pull request #196 from grillazz/195-switch-project-to-uv
195 switch project to uv
2 parents e975010 + 21de7e2 commit e88f68e

File tree

5 files changed

+1417
-4437
lines changed

5 files changed

+1417
-4437
lines changed

.github/workflows/build-and-test.yml

+11-17
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ on:
77
- main
88

99
jobs:
10-
test:
10+
build:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
fail-fast: false
1414
matrix:
1515
python-version: [ "3.13" ]
16-
poetry-version: [ "1.8.5" ]
1716

1817
env:
1918
PYTHONDONTWRITEBYTECODE: 1
2019
PYTHONUNBUFFERED: 1
2120
POSTGRES_DB: testdb
2221
POSTGRES_HOST: 127.0.0.1
23-
POSTGRES_USER: app-user
22+
POSTGRES_USER: panettone
2423
POSTGRES_PASSWORD: secret
2524
PGPASSWORD: secret
2625
REDIS_HOST: 127.0.0.1
@@ -37,7 +36,7 @@ jobs:
3736
sqldb:
3837
image: postgres:16
3938
env:
40-
POSTGRES_USER: app-user
39+
POSTGRES_USER: panettone
4140
POSTGRES_PASSWORD: secret
4241
POSTGRES_DB: testdb
4342
ports:
@@ -48,18 +47,13 @@ jobs:
4847
steps:
4948
- uses: actions/checkout@v4
5049
- name: Create database schema
51-
run: PGPASSWORD=secret psql -h 127.0.0.1 -d testdb -U app-user -c "CREATE SCHEMA shakespeare; CREATE SCHEMA happy_hog;"
52-
- uses: actions/setup-python@v5
50+
run: PGPASSWORD=secret psql -h 127.0.0.1 -d testdb -U panettone -c "CREATE SCHEMA shakespeare; CREATE SCHEMA happy_hog;"
51+
52+
- name: Install the latest version of uv and set the python version
53+
uses: astral-sh/setup-uv@v5
5354
with:
5455
python-version: ${{ matrix.python-version }}
55-
- name: Install Poetry
56-
uses: abatilo/actions-poetry@v3
57-
with:
58-
poetry-version: ${{ matrix.poetry-version }}
59-
- name: Install dependencies
60-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
61-
run: poetry install --no-interaction --no-root
62-
- name: Test Code
63-
run: poetry run pytest tests/
64-
- name: Lint Code
65-
run: poetry run ruff check .
56+
57+
- name: Test with python ${{ matrix.python-version }}
58+
run: uv run --frozen pytest
59+

Dockerfile

+62-43
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,62 @@
1-
FROM python:3.13-slim-bookworm AS base
2-
RUN apt-get update \
3-
&& apt-get upgrade -y \
4-
&& apt-get install -y --no-install-recommends curl git build-essential \
5-
&& apt-get autoremove -y
6-
ENV POETRY_HOME="/opt/poetry"
7-
RUN curl -sSL https://install.python-poetry.org | python3 -
8-
9-
FROM base AS install
10-
WORKDIR /home/code
11-
12-
# allow controlling the poetry installation of dependencies via external args
13-
ARG INSTALL_ARGS="--no-root --no-interaction --no-ansi"
14-
ENV POETRY_HOME="/opt/poetry"
15-
ENV PATH="$POETRY_HOME/bin:$PATH"
16-
COPY pyproject.toml poetry.lock ./
17-
18-
# install without virtualenv, since we are inside a container
19-
RUN poetry config virtualenvs.create false \
20-
&& poetry install $INSTALL_ARGS
21-
22-
# cleanup
23-
RUN curl -sSL https://install.python-poetry.org | python3 - --uninstall
24-
RUN apt-get purge -y curl git build-essential \
25-
&& apt-get clean -y \
26-
&& rm -rf /root/.cache \
27-
&& rm -rf /var/apt/lists/* \
28-
&& rm -rf /var/cache/apt/*
29-
30-
FROM install AS app-image
31-
32-
ENV PYTHONPATH=/home/code/ PYTHONHASHSEED=0 PYTHONASYNCIODEBUG=1
33-
34-
COPY tests/ tests/
35-
COPY app/ app/
36-
COPY alembic/ alembic/
37-
COPY .env alembic.ini ./
38-
39-
# create a non-root user and switch to it, for security.
40-
RUN addgroup --system --gid 1001 "app-user"
41-
RUN adduser --system --uid 1001 "app-user"
42-
USER "app-user"
43-
1+
FROM ubuntu:oracular AS build
2+
3+
RUN apt-get update -qy && apt-get install -qyy \
4+
-o APT::Install-Recommends=false \
5+
-o APT::Install-Suggests=false \
6+
build-essential \
7+
ca-certificates \
8+
python3-setuptools \
9+
python3.13-dev \
10+
git
11+
12+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
13+
14+
ENV UV_LINK_MODE=copy \
15+
UV_COMPILE_BYTECODE=1 \
16+
UV_PYTHON_DOWNLOADS=never \
17+
UV_PYTHON=python3.13 \
18+
UV_PROJECT_ENVIRONMENT=/panettone
19+
20+
COPY pyproject.toml /_lock/
21+
COPY uv.lock /_lock/
22+
23+
RUN --mount=type=cache,target=/root/.cache
24+
RUN cd /_lock && uv sync \
25+
--locked \
26+
--no-dev \
27+
--no-install-project
28+
##########################################################################
29+
FROM ubuntu:oracular
30+
31+
ENV PATH=/panettone/bin:$PATH
32+
33+
RUN groupadd -r panettone
34+
RUN useradd -r -d /panettone -g panettone -N panettone
35+
36+
STOPSIGNAL SIGINT
37+
38+
RUN apt-get update -qy && apt-get install -qyy \
39+
-o APT::Install-Recommends=false \
40+
-o APT::Install-Suggests=false \
41+
python3.13 \
42+
libpython3.13 \
43+
libpcre3 \
44+
libxml2
45+
46+
RUN apt-get clean
47+
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
48+
49+
COPY --from=build --chown=panettone:panettone /panettone /panettone
50+
51+
USER panettone
52+
WORKDIR /panettone
53+
COPY /app/ app/
54+
COPY /tests/ tests/
55+
COPY .env app/
56+
COPY alembic.ini app/
57+
COPY alembic/ app/alembic/
58+
COPY logging-uvicorn.json /panettone/logging-uvicorn.json
59+
60+
RUN python -V
61+
RUN python -Im site
62+
RUN python -Ic 'import uvicorn'

0 commit comments

Comments
 (0)