FROM archlinux

# Pinned to the same Poetry release that wrote poetry.lock and satisfies the
# poetry-core>=2.5.0 floor of pyproject.toml, so that the image does not drift
# with the rolling repository and builds the same metadata as the release.
ENV POETRY_CACHE_DIR=/opt/cache/pypoetry
RUN pacman -Syu --noconfirm --needed \
    base-devel \
    python \
    python-pip \
 && python -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 \
 && yes | pacman -Scc
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
