# SPDX-License-Identifier: Apache-2.0
#!BuildTag: %%IMG_PREFIX%%sriov-network-config-daemon:v%%sriov-network-config-daemon_version%%
#!BuildTag: %%IMG_PREFIX%%sriov-network-config-daemon:v%%sriov-network-config-daemon_version%%-%RELEASE%
ARG SLE_VERSION
FROM registry.suse.com/bci/bci-micro:$SLE_VERSION AS micro

FROM registry.suse.com/bci/bci-base:$SLE_VERSION AS base
COPY --from=micro / /installroot/
RUN zypper --installroot /installroot --non-interactive install --no-recommends sriov-network-operator-config-dm hwdata mstflint; \
    zypper -n clean; \
    rm -rf /var/log/*

# Adding "util-linux" package; it provides the blkid command required in sriov-network-operator-config-daemon image (platform=openstack);
# see https://jira.suse.com/browse/SEL3-47 and related https://bugzilla.suse.com/show_bug.cgi?id=1247914  
#
# CHKSTAT_ALLOW_INSECURE_MODE_IF_NO_PROC var setting is required when zypper-installing the "util-linux" package;
# see https://bugzilla.suse.com/show_bug.cgi?id=1219736#c54
#
# Finally, to avoid blkid waiting on udev (which is not running in the container image), a proper blkid.conf file is needed;
# see https://bugzilla.suse.com/show_bug.cgi?id=1247914
#
RUN export CHKSTAT_ALLOW_INSECURE_MODE_IF_NO_PROC=1; \
    export BLKID_CONF_TMP="/installroot/etc/blkid.conf"; \
    zypper --installroot /installroot --non-interactive install --no-recommends util-linux; \
    zypper -n clean; \
    rm -rf /var/log/*; \
    [ -e "${BLKID_CONF_TMP}" ] && sed -i -e 's/^EVALUATE=.*/EVALUATE=scan/g' ${BLKID_CONF_TMP} || echo "EVALUATE=scan" > ${BLKID_CONF_TMP}

FROM micro AS final
# Define labels according to https://en.opensuse.org/Building_derived_containers
# labelprefix=com.suse.application.sriov-network-config-daemon
LABEL org.opencontainers.image.authors="SUSE LLC (https://www.suse.com/)"
LABEL org.opencontainers.image.title="SLE sriov-network-config-daemon Container Image"
LABEL org.opencontainers.image.description="sriov-network-config-daemon based on the SLE Base Container Image."
LABEL org.opencontainers.image.version="%%sriov-network-config-daemon_version%%"
LABEL org.opencontainers.image.url="https://www.suse.com/products/server/"
LABEL org.opencontainers.image.created="%BUILDTIME%"
LABEL org.opencontainers.image.vendor="SUSE LLC"
LABEL org.opensuse.reference="%%IMG_REPO%%/%%IMG_PREFIX%%sriov-network-config-daemon:%%sriov-network-config-daemon_version%%-%RELEASE%"
LABEL org.openbuildservice.disturl="%DISTURL%"
LABEL com.suse.supportlevel="%%SUPPORT_LEVEL%%"
LABEL com.suse.eula="SUSE Combined EULA February 2024"
LABEL com.suse.lifecycle-url="https://www.suse.com/lifecycle"
LABEL com.suse.image-type="application"
LABEL com.suse.release-stage="released"
# endlabelprefix

COPY --from=base /installroot /
ENTRYPOINT ["/usr/bin/sriov-network-config-daemon"]
