|
1 | | -FROM python:3.12-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 --only main" |
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 |
33 | | - |
34 | | -COPY greens/ greens/ |
35 | | -COPY tests/ tests/ |
36 | | -COPY .env ./ |
37 | | - |
38 | | -# create a non-root user and switch to it, for security. |
39 | | -RUN addgroup --system --gid 1001 "farmer-eleven" |
40 | | -RUN adduser --system --uid 1001 "farmer-eleven" |
41 | | -USER "farmer-eleven" |
42 | | - |
| 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 | + |
| 11 | +COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv |
| 12 | + |
| 13 | +ENV UV_LINK_MODE=copy \ |
| 14 | + UV_COMPILE_BYTECODE=1 \ |
| 15 | + UV_PYTHON_DOWNLOADS=never \ |
| 16 | + UV_PYTHON=python3.13 \ |
| 17 | + UV_PROJECT_ENVIRONMENT=/app |
| 18 | + |
| 19 | +COPY pyproject.toml /_lock/ |
| 20 | +COPY uv.lock /_lock/ |
| 21 | + |
| 22 | +RUN --mount=type=cache,target=/root/.cache |
| 23 | +RUN cd /_lock && uv sync \ |
| 24 | + --locked \ |
| 25 | + --no-dev \ |
| 26 | + --no-install-project |
| 27 | +########################################################################## |
| 28 | +FROM ubuntu:oracular |
| 29 | + |
| 30 | +ENV PATH=/app/bin:$PATH |
| 31 | + |
| 32 | +RUN groupadd -r app |
| 33 | +RUN useradd -r -d /app -g app -N app |
| 34 | + |
| 35 | +STOPSIGNAL SIGINT |
| 36 | + |
| 37 | +RUN apt-get update -qy && apt-get install -qyy \ |
| 38 | + -o APT::Install-Recommends=false \ |
| 39 | + -o APT::Install-Suggests=false \ |
| 40 | + python3.13 \ |
| 41 | + libpython3.13 \ |
| 42 | + libpcre3 \ |
| 43 | + libxml2 |
| 44 | + |
| 45 | +RUN apt-get clean |
| 46 | +RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
| 47 | + |
| 48 | +COPY --from=build --chown=app:app /app /app |
| 49 | + |
| 50 | +USER app |
| 51 | +WORKDIR /app |
| 52 | +COPY /greens/ greens/ |
| 53 | +COPY /tests/ tests/ |
| 54 | +COPY .env greens/ |
| 55 | + |
| 56 | +RUN python -V |
| 57 | +RUN python -Im site |
| 58 | +RUN python -Ic 'import uvicorn' |
0 commit comments