ARG REPOS_IMAGE=oraclelinux:10
ARG BUILDER_IMAGE=oraclelinux:10

FROM $REPOS_IMAGE as repos
FROM $BUILDER_IMAGE as builder

ARG OCIREG
ARG OCIDOM

RUN echo "$OCIREG" > /etc/yum/vars/ociregion
RUN echo "$OCIDOM" > /etc/yum/vars/ocidomain

RUN dnf -y update
RUN dnf -y install rpm-ostree selinux-policy-targeted python3
ARG MANIFEST=oracle-minimal

COPY . /src
WORKDIR /src

RUN --mount=type=cache,target=/workdir --mount=type=bind,rw,from=repos,src=/,dst=/repos <<EORUN
set -xeuo pipefail

chmod +x install-manifests
./install-manifests

install -m 0755 -t /usr/libexec ./bootc-base-imagectl
/usr/libexec/bootc-base-imagectl list > /dev/null

echo "$OCIREG" > /repos/etc/yum/vars/ociregion
echo "$OCIDOM" > /repos/etc/yum/vars/ocidomain

cp minimal/*.repo /repos/etc/yum.repos.d/

/usr/libexec/bootc-base-imagectl build-rootfs --reinject --manifest=${MANIFEST} /repos /target-rootfs

cp minimal/*.repo /target-rootfs/etc/yum.repos.d/

EORUN

FROM scratch
COPY --from=builder /target-rootfs/ /

LABEL containers.bootc 1
LABEL ostree.bootable 1

RUN bootc container lint
ENV container=oci

# Make systemd the default
STOPSIGNAL SIGRTMIN+3
CMD ["/sbin/init"]

