Skip to content

Commit 2404c12

Browse files
committed
wip: refactor dockerfile for uv and drop poetry.lock
1 parent 87f8dab commit 2404c12

File tree

2 files changed

+62
-4331
lines changed

2 files changed

+62
-4331
lines changed

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)