|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +ARG PYTHON_VERSION="3.11.9" |
| 4 | +ARG UV_VERSION="0.4" |
| 5 | +FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build |
| 6 | +FROM python:${PYTHON_VERSION}-slim-bookworm AS base |
| 7 | + |
| 8 | +LABEL maintainer=bisgaard-itis |
| 9 | + |
| 10 | +# NOTE: to list the latest version run `make` inside `scripts/apt-packages-versions` |
| 11 | +ENV DOCKER_APT_VERSION="5:26.1.4-1~debian.12~bookworm" |
| 12 | + |
| 13 | +# -------------------------- Install docker ------------------- |
| 14 | +# for docker apt caching to work this needs to be added: [https://vsupalov.com/buildkit-cache-mount-dockerfile/] |
| 15 | +RUN rm -f /etc/apt/apt.conf.d/docker-clean && \ |
| 16 | + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache |
| 17 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ |
| 18 | + set -eux; \ |
| 19 | + apt-get update; \ |
| 20 | + apt-get install -y --no-install-recommends \ |
| 21 | + gosu \ |
| 22 | + ca-certificates \ |
| 23 | + curl \ |
| 24 | + gnupg \ |
| 25 | + lsb-release \ |
| 26 | + && mkdir -p /etc/apt/keyrings \ |
| 27 | + && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \ |
| 28 | + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ |
| 29 | + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ |
| 30 | + && apt-get update \ |
| 31 | + && apt-get install -y --no-install-recommends \ |
| 32 | + # only the cli is needed and we remove the unnecessary stuff again |
| 33 | + docker-ce-cli=${DOCKER_APT_VERSION} \ |
| 34 | + && apt-get remove -y\ |
| 35 | + gnupg \ |
| 36 | + curl \ |
| 37 | + lsb-release \ |
| 38 | + && apt-get clean -y\ |
| 39 | + # verify that the binary works |
| 40 | + && gosu nobody true |
| 41 | + |
| 42 | +# Sets utf-8 encoding for Python et al |
| 43 | +ENV LANG=C.UTF-8 |
| 44 | + |
| 45 | +# Turns off writing .pyc files; superfluous on an ephemeral container. |
| 46 | +ENV PYTHONDONTWRITEBYTECODE=1 \ |
| 47 | + VIRTUAL_ENV=/home/scu/.venv |
| 48 | + |
| 49 | +# Ensures that the python and pip executables used in the image will be |
| 50 | +# those from our virtualenv. |
| 51 | +ENV PATH="${VIRTUAL_ENV}/bin:$PATH" |
| 52 | + |
| 53 | + |
| 54 | +# -------------------------- Build stage ------------------- |
| 55 | +# Installs build/package management tools and third party dependencies |
| 56 | +# |
| 57 | +# + /build WORKDIR |
| 58 | +# |
| 59 | +FROM base AS build |
| 60 | + |
| 61 | +ENV SC_BUILD_TARGET=build |
| 62 | + |
| 63 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ |
| 64 | + set -eux \ |
| 65 | + && apt-get update \ |
| 66 | + && apt-get install -y --no-install-recommends \ |
| 67 | + build-essential \ |
| 68 | + curl \ |
| 69 | + git \ |
| 70 | + jq |
| 71 | + |
| 72 | +# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv |
| 73 | +COPY --from=uv_build /uv /uvx /bin/ |
| 74 | + |
| 75 | +RUN uv venv "${VIRTUAL_ENV}" |
| 76 | + |
| 77 | +WORKDIR /test |
0 commit comments