FROM ubuntu:24.04

# The Poetry shipped by the distribution predates PEP 621 support (1.3 on
# Debian bookworm, 1.8 on Ubuntu 24.04), and Poetry 2.1 emits Metadata 2.3 with
# a free-text License field. The images therefore install the same Poetry release
# that wrote poetry.lock and satisfies the poetry-core>=2.5.0 floor of
# pyproject.toml, which is what produces the PEP 639 metadata of the release.
ENV POETRY_CACHE_DIR=/opt/cache/pypoetry
RUN apt-get update -q \
 && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    build-essential \
    ca-certificates \
    python3 \
    python3-pip \
    python3-venv \
 && python3 -m venv /opt/poetry \
 && /opt/poetry/bin/pip install --no-cache-dir poetry==2.5.1 \
 && ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry \
 && poetry config virtualenvs.in-project true \
 && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD . /elf-checker/
# Warm the download cache of the image with every locked dependency, then drop
# the venv again: each job creates its own in-project venv in its own checkout,
# and installs from that cache without a download. Building the project warms the
# isolated PEP 517 environment of the build backend. The cache directory is fixed
# by the ENV above, so it is the same for the image build and for the jobs.
RUN cd /elf-checker \
 && poetry install --no-root \
 && poetry build -o /tmp/build-warm \
 && rm -rf /tmp/build-warm \
 && poetry env remove --all \
 && rm -rf /elf-checker
