FROM almalinux:9.0 as almalinux90
ARG TARGETARCH
ARG BUILD_TOOLS="dnf-plugins-core createrepo mkisofs epel-release"
ARG DIR=almalinux-9.0-${TARGETARCH}-rpms
ARG PKGS=.common[],.rpms[],.almalinux[],.almalinux90[]

RUN dnf install -q -y ${BUILD_TOOLS} \
    && dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo \
    && dnf makecache

WORKDIR package
COPY packages.yaml .
COPY --from=mikefarah/yq:4.11.1 /usr/bin/yq /usr/bin/yq
RUN yq eval ${PKGS} packages.yaml | sed '/^ceph-common$/d' > packages.list

RUN sort -u packages.list | xargs dnf download --resolve --alldeps --downloaddir=${DIR} \
    && createrepo -d ${DIR} \
    && mkisofs -r -o ${DIR}.iso ${DIR}

FROM scratch
COPY --from=almalinux90 /package/*.iso /
