# The image under test. Not Alloy: a minimal bootc image carrying one
# stand-in component, so a run costs a 200 MB build rather than a 5 GB one.
# What is being measured is rpm-ostree and bootc behaviour, which does not
# depend on what else the image holds.
#
# SHAPE is the whole point. The three values are the three ways a first-party
# component can reach an image, and they behave differently enough that the
# answer to "can we hotfix this" changes with them:
#
#   rpm    the component is an RPM installed at build time, so it is a base
#          package. This is what an RPM channel would want.
#   loose  the component is a file copied into /usr/bin owned by no package.
#          What Alloy did until 2026-08-14, and what this measurement ended.
#   none   the image does not carry the component at all, so a hotfix is a
#          plain layered package rather than a replacement.
#   carry  the image carries the component's RPM as a FILE, in a file:// repo
#          under /usr/share, and does not install it. The component is still
#          absent from @System, so it is layered exactly as in `none`, but the
#          package it layers from travels with the image and needs no network.
#          This is the shape Alloy takes: it makes an offline install work, and
#          because @System never holds the component there is no version of it
#          for a layer to conflict with, which is the wedge that `rpm` and the
#          n4 case run into.
#
# The build context is state/, which holds the RPMs and the ssh key that
# build.sh puts there. Nothing in the context is tracked.
FROM quay.io/fedora/fedora-bootc:43

ARG SHAPE=none
ARG DEMO_VERSION=0.0.1
ARG BASE_MARK=n1

COPY alloy-demo.repo /etc/yum.repos.d/alloy-demo.repo
COPY registries.conf /etc/containers/registries.conf.d/010-alloy-demo.conf

COPY rpms /tmp/rpms
# Per-version repos, each holding one RPM and its metadata. `carry` takes the
# one matching DEMO_VERSION, so moving the base from one carry variant to
# another is what "the image shipped a newer component" looks like.
COPY repos /tmp/repos
RUN case "$SHAPE" in \
      rpm) \
        dnf -y install "/tmp/rpms/alloy-demo-${DEMO_VERSION}-1.fc43.x86_64.rpm" ;; \
      loose) \
        printf '#!/bin/sh\necho "alloy-demo %s"\n' "$DEMO_VERSION" > /usr/bin/alloy-demo \
        && chmod 0755 /usr/bin/alloy-demo ;; \
      carry) \
        mkdir -p /usr/share/alloy-demo \
        && cp -r "/tmp/repos/$DEMO_VERSION" /usr/share/alloy-demo/rpm \
        && printf '[alloy-demo-local]\nname=carried on the medium\nbaseurl=file:///usr/share/alloy-demo/rpm\nenabled=1\ngpgcheck=0\n' \
             > /etc/yum.repos.d/alloy-demo-local.repo ;; \
      none) \
        : ;; \
      *) echo "unknown SHAPE: $SHAPE" >&2; exit 1 ;; \
    esac \
 && rm -rf /tmp/rpms /tmp/repos \
 && dnf clean all

# Which base is running, readable from the guest without trusting a tag. The
# registry tag is rewritten on every case, so the tag says nothing about what
# actually booted.
RUN echo "$BASE_MARK" > /usr/share/base-mark

# Key-only root ssh, because the harness drives the guest from outside. The
# authorized keys file lives under /usr rather than in /root: on an ostree
# system /root is /var/roothome, which is not part of the image.
COPY authorized_keys /usr/share/alloy-demo/authorized_keys
RUN printf 'PermitRootLogin prohibit-password\nAuthorizedKeysFile /usr/share/alloy-demo/authorized_keys\n' \
      > /etc/ssh/sshd_config.d/10-alloy-demo.conf \
 && systemctl enable sshd
