# SPDX-License-Identifier: Apache-2.0
#!BuildTag: %%IMG_PREFIX%%suse-edge-components-versions:0.2.2
#!BuildTag: %%IMG_PREFIX%%suse-edge-components-versions:0.2.2-%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 sed -i -e 's%^# rpm.install.excludedocs = no.*%rpm.install.excludedocs = yes%g' /etc/zypp/zypp.conf
RUN zypper --installroot /installroot --non-interactive install --no-recommends python311-suse-edge-components-versions

# https://opensource.suse.com/bci-docs/guides/adding-users/
ARG USERNAME=suse
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME

# build actual image
FROM micro AS final

MAINTAINER SUSE LLC (https://www.suse.com/)
# Define labels according to https://en.opensuse.org/Building_derived_containers
LABEL org.opencontainers.image.title="SUSE Edge components-versions Container Image"
LABEL org.opencontainers.image.description="Gather and display component versions for various SUSE Edge products"
LABEL org.opencontainers.image.url="https://github.com/suse-edge/support-tools/tree/main/components-versions"
LABEL org.opencontainers.image.created="%BUILDTIME%"
LABEL org.opencontainers.image.vendor="SUSE LLC"
LABEL org.opencontainers.image.version="0.2.2"
LABEL org.opensuse.reference="%%IMG_REPO%%/%%IMG_PREFIX%%suse-edge-components-versions:0.2.2-%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 /

# https://opensource.suse.com/bci-docs/guides/adding-users/
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
COPY --from=base /etc/shadow /etc/shadow
COPY --from=base /home/$USERNAME /home/$USERNAME

USER ${USERNAME}
    
ENTRYPOINT ["/usr/bin/suse-edge-components-versions"]
