# SPDX-License-Identifier: BSD-3-Clause

#     Copyright (c) 2025 SUSE LLC

# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
# You can contact the BCI team via https://github.com/SUSE/bci/discussions

#!UseOBSRepositories

#!BuildTag: private-registry/harbor-valkey:%%valkey_version%%-%RELEASE%
#!BuildTag: private-registry/harbor-valkey:%%valkey_version%%
#!BuildTag: private-registry/harbor-valkey:latest
#!BuildName: private-registry-harbor-valkey-%%valkey_version%%
#!BuildVersion: 15.6.8.0
#!BuildRelease: 1
FROM registry.suse.com/bci/bci-micro:15.6 AS target
FROM suse/sle15:15.6 AS builder
COPY --from=target / /target

RUN set -euo pipefail; \
    zypper -n --installroot /target --gpg-auto-import-keys install --no-recommends valkey shadow sed; \
    zypper -n clean; \
    rm -rf {/target,}/var/log/{alternatives.log,lastlog,tallylog,zypper.log,zypp/history,YaST2}
# sanity check that the version from the tag is equal to the version of valkey that we expect
RUN set -euo pipefail; \
    [ "$(rpm --root /target -q --qf '%{version}' valkey | \
    cut -d '.' -f -2)" = "8.0" ]
FROM registry.suse.com/bci/bci-micro:15.6
COPY --from=builder /target /
# Define labels according to https://en.opensuse.org/Building_derived_containers
# labelprefix=com.suse.application.harbor-valkey
LABEL org.opencontainers.image.authors="https://github.com/SUSE/bci/discussions"
LABEL org.opencontainers.image.title="SLE Persistent key-value database for SUSE Private Registry"
LABEL org.opencontainers.image.description="ValKey Container based on bci-micro adapted for SUSE Private Registry"
LABEL org.opencontainers.image.version="%%valkey_version%%"
LABEL org.opencontainers.image.url="https://www.suse.com/products/base-container-images/"
LABEL org.opencontainers.image.created="%BUILDTIME%"
LABEL org.opencontainers.image.vendor="SUSE LLC"
LABEL org.opencontainers.image.source="%SOURCEURL%"
LABEL org.opencontainers.image.ref.name="%%valkey_version%%-%RELEASE%"
LABEL org.opensuse.reference="registry.suse.com/private-registry/harbor-valkey:%%valkey_version%%-%RELEASE%"
LABEL org.openbuildservice.disturl="%DISTURL%"
LABEL com.suse.supportlevel="techpreview"
LABEL com.suse.eula="sle-eula"
LABEL com.suse.lifecycle-url="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"
LABEL com.suse.release-stage="released"
# endlabelprefix
LABEL org.opencontainers.image.base.name="%BASE_REFNAME%"
LABEL org.opencontainers.image.base.digest="%BASE_DIGEST%"
LABEL io.artifacthub.package.readme-url="%SOURCEURL%README.md"
ENTRYPOINT ["/usr/bin/valkey-server"]
CMD ["--protected-mode no", "--dir /var/lib/valkey"]
EXPOSE 6379/tcp

RUN set -euo pipefail; sed -e 's/^protected-mode yes/protected-mode no/' -e 's/^bind .*//' < /etc/valkey/default.conf.example > /etc/valkey/valkey.conf
RUN set -euo pipefail; groupmod -g 999 valkey; usermod -u 999 -g 999 valkey; chown -R valkey:valkey /var/lib/valkey; chgrp -R valkey /etc/valkey
WORKDIR /var/lib/valkey
USER valkey
VOLUME /var/lib/valkey
