From a9fc12ed5e7934fa555f23c8e1a222e91c172b2c Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Fri, 16 Aug 2024 12:44:10 +0200 Subject: [PATCH] Add version 7 to valkey-container Signed-off-by: Petr "Stone" Hracek --- 7/.exclude-c8s | 0 7/.exclude-rhel8 | 0 7/Dockerfile.c10s | 90 +++++++ 7/Dockerfile.c8s | 77 ------ 7/Dockerfile.c9s | 78 ------ 7/Dockerfile.fedora | 75 +++--- 7/Dockerfile.rhel8 | 78 ------ 7/Dockerfile.rhel9 | 78 ------ 7/root/usr/bin/run-valkey | 27 +++ 7/root/usr/bin/usage | 3 +- 7/root/usr/libexec/container-setup | 14 +- .../share/container-scripts/redis/README.md | 35 ++- .../share/container-scripts/valkey/README.md | 87 +++++++ .../valkey/base.conf.template | 2 + .../share/container-scripts/valkey/common.sh | 34 +++ .../share/container-scripts/valkey/helpers.sh | 24 ++ .../valkey/password.conf.template | 3 + .../container-scripts/valkey/post-init.sh | 11 + .../valkey/validate-variables.sh | 15 ++ Makefile | 2 +- examples/valkey-ephemeral-template.json | 199 ++++++++++++++++ examples/valkey-persistent-template.json | 223 ++++++++++++++++++ imagestreams/imagestreams.yaml | 34 +-- imagestreams/valkey-centos.json | 68 ++++++ imagestreams/valkey-rhel-aarch64.json | 86 +++++++ imagestreams/valkey-rhel.json | 86 +++++++ test/run | 55 +++-- test/run-openshift-pytest | 2 +- test/run-openshift-remote-cluster | 9 +- test/test-lib-valkey.sh | 48 ++++ test/test_valkey_imagestream.py | 48 ++++ test/test_valkey_imagestream_template.py | 45 ++++ test/test_valkey_latest_imagestreams.py | 26 ++ test/test_valkey_template.py | 53 +++++ test/valkey-persistent-template.json | 1 + 35 files changed, 1282 insertions(+), 434 deletions(-) delete mode 100644 7/.exclude-c8s delete mode 100644 7/.exclude-rhel8 create mode 100644 7/Dockerfile.c10s delete mode 100644 7/Dockerfile.c8s delete mode 100644 7/Dockerfile.c9s delete mode 100644 7/Dockerfile.rhel8 delete mode 100644 7/Dockerfile.rhel9 create mode 100755 7/root/usr/bin/run-valkey create mode 100644 7/root/usr/share/container-scripts/valkey/README.md create mode 100644 7/root/usr/share/container-scripts/valkey/base.conf.template create mode 100644 7/root/usr/share/container-scripts/valkey/common.sh create mode 100644 7/root/usr/share/container-scripts/valkey/helpers.sh create mode 100644 7/root/usr/share/container-scripts/valkey/password.conf.template create mode 100644 7/root/usr/share/container-scripts/valkey/post-init.sh create mode 100644 7/root/usr/share/container-scripts/valkey/validate-variables.sh create mode 100644 examples/valkey-ephemeral-template.json create mode 100644 examples/valkey-persistent-template.json create mode 100644 imagestreams/valkey-centos.json create mode 100644 imagestreams/valkey-rhel-aarch64.json create mode 100644 imagestreams/valkey-rhel.json create mode 100644 test/test-lib-valkey.sh create mode 100644 test/test_valkey_imagestream.py create mode 100644 test/test_valkey_imagestream_template.py create mode 100644 test/test_valkey_latest_imagestreams.py create mode 100644 test/test_valkey_template.py create mode 120000 test/valkey-persistent-template.json diff --git a/7/.exclude-c8s b/7/.exclude-c8s deleted file mode 100644 index e69de29..0000000 diff --git a/7/.exclude-rhel8 b/7/.exclude-rhel8 deleted file mode 100644 index e69de29..0000000 diff --git a/7/Dockerfile.c10s b/7/Dockerfile.c10s new file mode 100644 index 0000000..5585dc7 --- /dev/null +++ b/7/Dockerfile.c10s @@ -0,0 +1,90 @@ +FROM quay.io/sclorg/s2i-core-c10s:c10s + +# Valkey image based on Software Collections packages +# +# Volumes: +# * /var/lib/valkey/data - Datastore for Valkey +# Environment: +# * $VALKEY_PASSWORD - Database password + +ENV VALKEY_VERSION=7 \ + HOME=/var/lib/valkey \ + NAME=valkey + +ENV SUMMARY="Valkey in-memory data structure store, used as database, cache and message broker" \ + DESCRIPTION="Valkey $VALKEY_VERSION available as container, is an advanced key-value store. \ +It is often referred to as a data structure server since keys can contain strings, hashes, lists, \ +sets and sorted sets. You can run atomic operations on these types, like appending to a string; \ +incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; \ +or getting the member with highest ranking in a sorted set. In order to achieve its outstanding \ +performance, Valkey works with an in-memory dataset. Depending on your use case, you can persist \ +it either by dumping the dataset to disk every once in a while, or by appending each command to a log." + +LABEL summary="$SUMMARY" \ + description="$DESCRIPTION" \ + io.k8s.description="$DESCRIPTION" \ + io.k8s.display-name="Valkey $VALKEY_VERSION" \ + io.openshift.expose-services="6379:valkey" \ + io.openshift.tags="database,valkey,valkey,valkey-$VALKEY_VERSION" \ + com.redhat.component="valkey-$VALKEY_VERSION-container" \ + name="sclorg/valkey-$VALKEY_VERSION-c10s" \ + version="$VALKEY_VERSION" \ + com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#rhel" \ + usage="podman run -d --name valkey_database -p 6379:6379 quay.io/sclorg/valkey-$VALKEY_VERSION-c10s" \ + maintainer="SoftwareCollections.org " + +EXPOSE 6379 + +# Get prefix path and path to scripts rather than hard-code them in scripts +ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/valkey \ + VALKEY_PREFIX=/usr \ + VALKEY_CONF=/etc/valkey/valkey.conf \ + VALKEY_SOCK=/run/valkey/valkey.sock \ + VALKEY_LIB=/var/lib/valkey \ + VALKEY_RUN=/run/valkey + + +# Create user for Valkey that has known UID +# We need to do this before installing the RPMs which would create user with random UID +# The UID is the one used by the default user from the parent layer (1001), +# and since the user exists already, do not create a new one, but only rename +# the existing +# This image must forever use UID 1001 for Valkey user so our volumes are +# safe in the future. This should *never* change, the last test is there +# to make sure of that. +RUN getent group valkey &> /dev/null || groupadd -r valkey &> /dev/null && \ + usermod -l valkey -aG valkey -c 'Valkey Server' default &> /dev/null && \ +# Install gettext for envsubst command + INSTALL_PKGS="policycoreutils gettext bind valkey" && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + dnf -y clean all --enablerepo='*' && \ + valkey-server --version | grep -qe "^Server v=$VALKEY_VERSION\." && echo "Found VERSION $VALKEY_VERSION" && \ + mkdir -p $VALKEY_LIB/data && chown -R valkey:0 $VALKEY_LIB && \ + mkdir -p $VALKEY_RUN && chown -R valkey:0 $VALKEY_RUN && \ + chmod -R ug+rwX $VALKEY_RUN && \ + chmod -R ug+rwX $VALKEY_LIB && \ + [[ "$(id valkey)" == "uid=1001(valkey)"* ]] + +# Get prefix path and path to scripts rather than hard-code them in scripts +ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/valkey \ + VALKEY_PREFIX=/usr \ + VALKEY_CONF=/etc/valkey/valkey.conf + +COPY root / + +# this is needed due to issues with squash +# when this directory gets rm'd by the container-setup +# script. +RUN /usr/libexec/container-setup + +VOLUME ["/var/lib/valkey/data"] + +# Using a numeric value because of a comment in [1]: +# If your S2I image does not include a USER declaration with a numeric user, +# your builds will fail by default. +# [1] https://docs.openshift.com/container-platform/4.4/openshift_images/create-images.html#images-create-guide-openshift_create-images +USER 1001 + +ENTRYPOINT ["container-entrypoint"] +CMD ["run-valkey"] diff --git a/7/Dockerfile.c8s b/7/Dockerfile.c8s deleted file mode 100644 index c2d7bee..0000000 --- a/7/Dockerfile.c8s +++ /dev/null @@ -1,77 +0,0 @@ -FROM quay.io/sclorg/s2i-core-c8s:c8s - -# Redis image based on Software Collections packages -# -# Volumes: -# * /var/lib/redis/data - Datastore for Redis -# Environment: -# * $REDIS_PASSWORD - Database password - -ENV REDIS_VERSION=7 \ - HOME=/var/lib/redis - -ENV SUMMARY="Redis in-memory data structure store, used as database, cache and message broker" \ - DESCRIPTION="Redis $REDIS_VERSION available as container, is an advanced key-value store. \ -It is often referred to as a data structure server since keys can contain strings, hashes, lists, \ -sets and sorted sets. You can run atomic operations on these types, like appending to a string; \ -incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; \ -or getting the member with highest ranking in a sorted set. In order to achieve its outstanding \ -performance, Redis works with an in-memory dataset. Depending on your use case, you can persist \ -it either by dumping the dataset to disk every once in a while, or by appending each command to a log." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Redis $REDIS_VERSION" \ - io.openshift.expose-services="6379:redis" \ - io.openshift.tags="database,redis,redis$REDIS_VERSION,redis-$REDIS_VERSION" \ - com.redhat.component="redis-$REDIS_VERSION-container" \ - name="sclorg/redis-$REDIS_VERSION-c8s" \ - version="1" \ - usage="podman run -d --name redis_database -p 6379:6379 sclorg/redis-$REDIS_VERSION-c8s" \ - maintainer="SoftwareCollections.org " - -EXPOSE 6379 - -# Create user for redis that has known UID -# We need to do this before installing the RPMs which would create user with random UID -# The UID is the one used by the default user from the parent layer (1001), -# and since the user exists already, do not create a new one, but only rename -# the existing -# This image must forever use UID 1001 for redis user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN getent group redis &> /dev/null || groupadd -r redis &> /dev/null && \ - usermod -l redis -aG redis -c 'Redis Server' default &> /dev/null && \ -# Install gettext for envsubst command - yum -y module enable redis:$REDIS_VERSION && \ - INSTALL_PKGS="policycoreutils redis" && \ - yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum -y clean all --enablerepo='*' && \ - redis-server --version | grep -qe "^Redis server v=$REDIS_VERSION\." && echo "Found VERSION $REDIS_VERSION" && \ - mkdir -p /var/lib/redis/data && chown -R redis.0 /var/lib/redis && \ - [[ "$(id redis)" == "uid=1001(redis)"* ]] - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/redis \ - REDIS_PREFIX=/usr \ - REDIS_CONF=/etc/redis.conf - -COPY root / - -# this is needed due to issues with squash -# when this directory gets rm'd by the container-setup -# script. -RUN /usr/libexec/container-setup - -VOLUME ["/var/lib/redis/data"] - -# Using a numeric value because of a comment in [1]: -# If your S2I image does not include a USER declaration with a numeric user, -# your builds will fail by default. -# [1] https://docs.openshift.com/container-platform/4.4/openshift_images/create-images.html#images-create-guide-openshift_create-images -USER 1001 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-redis"] diff --git a/7/Dockerfile.c9s b/7/Dockerfile.c9s deleted file mode 100644 index 9b157fc..0000000 --- a/7/Dockerfile.c9s +++ /dev/null @@ -1,78 +0,0 @@ -FROM quay.io/sclorg/s2i-core-c9s:c9s - -# Redis image based on Software Collections packages -# -# Volumes: -# * /var/lib/redis/data - Datastore for Redis -# Environment: -# * $REDIS_PASSWORD - Database password - -ENV REDIS_VERSION=7 \ - HOME=/var/lib/redis - -ENV SUMMARY="Redis in-memory data structure store, used as database, cache and message broker" \ - DESCRIPTION="Redis $REDIS_VERSION available as container, is an advanced key-value store. \ -It is often referred to as a data structure server since keys can contain strings, hashes, lists, \ -sets and sorted sets. You can run atomic operations on these types, like appending to a string; \ -incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; \ -or getting the member with highest ranking in a sorted set. In order to achieve its outstanding \ -performance, Redis works with an in-memory dataset. Depending on your use case, you can persist \ -it either by dumping the dataset to disk every once in a while, or by appending each command to a log." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Redis $REDIS_VERSION" \ - io.openshift.expose-services="6379:redis" \ - io.openshift.tags="database,redis,redis$REDIS_VERSION,redis-$REDIS_VERSION" \ - com.redhat.component="redis-$REDIS_VERSION-container" \ - name="sclorg/redis-$REDIS_VERSION-c9s" \ - version="1" \ - com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#rhel" \ - usage="podman run -d --name redis_database -p 6379:6379 quay.io/sclorg/redis-$REDIS_VERSION-c9s" \ - maintainer="SoftwareCollections.org " - -EXPOSE 6379 - -# Create user for redis that has known UID -# We need to do this before installing the RPMs which would create user with random UID -# The UID is the one used by the default user from the parent layer (1001), -# and since the user exists already, do not create a new one, but only rename -# the existing -# This image must forever use UID 1001 for redis user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN getent group redis &> /dev/null || groupadd -r redis &> /dev/null && \ - usermod -l redis -aG redis -c 'Redis Server' default &> /dev/null && \ -# Install gettext for envsubst command - yum -y module enable redis:$REDIS_VERSION && \ - INSTALL_PKGS="policycoreutils redis" && \ - yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum -y clean all --enablerepo='*' && \ - redis-server --version | grep -qe "^Redis server v=$REDIS_VERSION\." && echo "Found VERSION $REDIS_VERSION" && \ - mkdir -p /var/lib/redis/data && chown -R redis.0 /var/lib/redis && \ - [[ "$(id redis)" == "uid=1001(redis)"* ]] - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/redis \ - REDIS_PREFIX=/usr \ - REDIS_CONF=/etc/redis/redis.conf - -COPY root / - -# this is needed due to issues with squash -# when this directory gets rm'd by the container-setup -# script. -RUN /usr/libexec/container-setup - -VOLUME ["/var/lib/redis/data"] - -# Using a numeric value because of a comment in [1]: -# If your S2I image does not include a USER declaration with a numeric user, -# your builds will fail by default. -# [1] https://docs.openshift.com/container-platform/4.4/openshift_images/create-images.html#images-create-guide-openshift_create-images -USER 1001 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-redis"] diff --git a/7/Dockerfile.fedora b/7/Dockerfile.fedora index 7d10d0c..d51b821 100644 --- a/7/Dockerfile.fedora +++ b/7/Dockerfile.fedora @@ -1,65 +1,70 @@ -FROM quay.io/fedora/s2i-core:38 +FROM quay.io/fedora/s2i-core:40 -# Redis image based on Software Collections packages +# Valkey image based on Software Collections packages # # Volumes: -# * /var/lib/redis/data - Datastore for Redis +# * /var/lib/valkey/data - Datastore for Valkey # Environment: -# * $REDIS_PASSWORD - Database password +# * $VALKEY_PASSWORD - Database password -ENV NAME=redis \ - VERSION=7 +ENV VALKEY_VERSION=7 \ + HOME=/var/lib/valkey \ + NAME=valkey -ENV REDIS_VERSION=$VERSION \ - HOME=/var/lib/redis - -ENV SUMMARY="Redis in-memory data structure store, used as database, cache and message broker" \ - DESCRIPTION="Redis $REDIS_VERSION available as container, is an advanced key-value store. \ +ENV SUMMARY="Valkey in-memory data structure store, used as database, cache and message broker" \ + DESCRIPTION="Valkey $VALKEY_VERSION available as container, is an advanced key-value store. \ It is often referred to as a data structure server since keys can contain strings, hashes, lists, \ sets and sorted sets. You can run atomic operations on these types, like appending to a string; \ incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; \ or getting the member with highest ranking in a sorted set. In order to achieve its outstanding \ -performance, Redis works with an in-memory dataset. Depending on your use case, you can persist \ +performance, Valkey works with an in-memory dataset. Depending on your use case, you can persist \ it either by dumping the dataset to disk every once in a while, or by appending each command to a log." LABEL summary="$SUMMARY" \ description="$DESCRIPTION" \ - io.k8s.description="$SUMMARY" \ - io.k8s.display-name="Redis 7" \ - io.openshift.expose-services="6379:redis" \ - io.openshift.tags="database,redis,redis7" \ + io.k8s.description="$DESCRIPTION" \ + io.k8s.display-name="Valkey $VALKEY_VERSION" \ + io.openshift.expose-services="6379:valkey" \ + io.openshift.tags="database,valkey,valkey$VALKEY_VERSION,valkey-$VALKEY_VERSION" \ com.redhat.component="$NAME" \ - name="fedora/$NAME-$VERSION" \ - version="$VERSION" \ - usage="docker run -d --name redis_database -p 6379:6379 quay.io/fedora/$NAME-$VERSION" \ + name="fedora/$NAME-$VALKEY_VERSION" \ + version="$VALKEY_VERSION" \ + usage="podman run -d --name valkey_database -p 6379:6379 quay.io/fedora/$NAME-$VALKEY_VERSION" \ maintainer="SoftwareCollections.org " EXPOSE 6379 -# Create user for redis that has known UID +# Get prefix path and path to scripts rather than hard-code them in scripts +ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/valkey \ + VALKEY_PREFIX=/usr \ + VALKEY_CONF=/etc/valkey/valkey.conf \ + VALKEY_SOCK=/run/valkey/valkey.sock \ + VALKEY_LIB=/var/lib/valkey \ + VALKEY_RUN=/run/valkey + +# Create user for valkey that has known UID # We need to do this before installing the RPMs which would create user with random UID # The UID is the one used by the default user from the parent layer (1001), # and since the user exists already, do not create a new one, but only rename # the existing -# This image must forever use UID 1001 for redis user so our volumes are +# This image must forever use UID 1001 for valkey user so our volumes are # safe in the future. This should *never* change, the last test is there # to make sure of that. -RUN getent group redis &> /dev/null || groupadd -r redis &> /dev/null && \ - usermod -l redis -aG redis -c 'Redis Server' default &> /dev/null && \ +RUN getent group valkey &> /dev/null || groupadd -r valkey &> /dev/null && \ + usermod -l valkey -aG valkey -c 'Server' default &> /dev/null && \ # Install gettext for envsubst command - dnf install -y yum-utils gettext policycoreutils && \ - INSTALL_PKGS="redis" && \ + dnf install -y dnf-utils gettext policycoreutils && \ + INSTALL_PKGS="valkey" && \ dnf install -y --setopt=tsflags=nodocs --nogpgcheck $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ - dnf clean all && \ - redis-server --version | grep -qe "^Redis server v=$REDIS_VERSION\." && echo "Found VERSION $REDIS_VERSION" && \ - mkdir -p /var/lib/redis/data && chown -R redis.0 /var/lib/redis && \ - [[ "$(id redis)" == "uid=1001(redis)"* ]] + dnf -y clean all --enablerepo='*' && \ + valkey-server --version | grep -qe "^Server v=$VALKEY_VERSION\." && echo "Found VERSION $VALKEY_VERSION" && \ + mkdir -p $VALKEY_LIB/data && chown -R valkey:0 $VALKEY_LIB && \ + mkdir -p $VALKEY_RUN && chown -R valkey:0 $VALKEY_RUN && \ + chmod -R ug+rwX $VALKEY_RUN && \ + chmod -R ug+rwX $VALKEY_LIB && \ + [[ "$(id valkey)" == "uid=1001(valkey)"* ]] -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/redis \ - REDIS_PREFIX=/usr \ - REDIS_CONF=/etc/redis/redis.conf COPY root / @@ -68,7 +73,7 @@ COPY root / # script. RUN /usr/libexec/container-setup -VOLUME ["/var/lib/redis/data"] +VOLUME ["/var/lib/valkey/data"] # Using a numeric value because of a comment in [1]: # If your S2I image does not include a USER declaration with a numeric user, @@ -77,4 +82,4 @@ VOLUME ["/var/lib/redis/data"] USER 1001 ENTRYPOINT ["container-entrypoint"] -CMD ["run-redis"] +CMD ["run-valkey"] diff --git a/7/Dockerfile.rhel8 b/7/Dockerfile.rhel8 deleted file mode 100644 index 2fa21b1..0000000 --- a/7/Dockerfile.rhel8 +++ /dev/null @@ -1,78 +0,0 @@ -FROM ubi8/s2i-core:1 - -# Redis image based on Software Collections packages -# -# Volumes: -# * /var/lib/redis/data - Datastore for Redis -# Environment: -# * $REDIS_PASSWORD - Database password - -ENV REDIS_VERSION=7 \ - HOME=/var/lib/redis - -ENV SUMMARY="Redis in-memory data structure store, used as database, cache and message broker" \ - DESCRIPTION="Redis $REDIS_VERSION available as container, is an advanced key-value store. \ -It is often referred to as a data structure server since keys can contain strings, hashes, lists, \ -sets and sorted sets. You can run atomic operations on these types, like appending to a string; \ -incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; \ -or getting the member with highest ranking in a sorted set. In order to achieve its outstanding \ -performance, Redis works with an in-memory dataset. Depending on your use case, you can persist \ -it either by dumping the dataset to disk every once in a while, or by appending each command to a log." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Redis $REDIS_VERSION" \ - io.openshift.expose-services="6379:redis" \ - io.openshift.tags="database,redis,redis$REDIS_VERSION,redis-$REDIS_VERSION" \ - com.redhat.component="redis-$REDIS_VERSION-container" \ - name="rhel8/redis-$REDIS_VERSION" \ - version="1" \ - com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#rhel" \ - usage="podman run -d --name redis_database -p 6379:6379 rhel8/redis-$REDIS_VERSION" \ - maintainer="SoftwareCollections.org " - -EXPOSE 6379 - -# Create user for redis that has known UID -# We need to do this before installing the RPMs which would create user with random UID -# The UID is the one used by the default user from the parent layer (1001), -# and since the user exists already, do not create a new one, but only rename -# the existing -# This image must forever use UID 1001 for redis user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN getent group redis &> /dev/null || groupadd -r redis &> /dev/null && \ - usermod -l redis -aG redis -c 'Redis Server' default &> /dev/null && \ -# Install gettext for envsubst command - yum -y module enable redis:$REDIS_VERSION && \ - INSTALL_PKGS="policycoreutils redis" && \ - yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum -y clean all --enablerepo='*' && \ - redis-server --version | grep -qe "^Redis server v=$REDIS_VERSION\." && echo "Found VERSION $REDIS_VERSION" && \ - mkdir -p /var/lib/redis/data && chown -R redis.0 /var/lib/redis && \ - [[ "$(id redis)" == "uid=1001(redis)"* ]] - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/redis \ - REDIS_PREFIX=/usr \ - REDIS_CONF=/etc/redis.conf - -COPY root / - -# this is needed due to issues with squash -# when this directory gets rm'd by the container-setup -# script. -RUN /usr/libexec/container-setup - -VOLUME ["/var/lib/redis/data"] - -# Using a numeric value because of a comment in [1]: -# If your S2I image does not include a USER declaration with a numeric user, -# your builds will fail by default. -# [1] https://docs.openshift.com/container-platform/4.4/openshift_images/create-images.html#images-create-guide-openshift_create-images -USER 1001 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-redis"] diff --git a/7/Dockerfile.rhel9 b/7/Dockerfile.rhel9 deleted file mode 100644 index 335cc8c..0000000 --- a/7/Dockerfile.rhel9 +++ /dev/null @@ -1,78 +0,0 @@ -FROM ubi9/s2i-core:1 - -# Redis image based on Software Collections packages -# -# Volumes: -# * /var/lib/redis/data - Datastore for Redis -# Environment: -# * $REDIS_PASSWORD - Database password - -ENV REDIS_VERSION=7 \ - HOME=/var/lib/redis - -ENV SUMMARY="Redis in-memory data structure store, used as database, cache and message broker" \ - DESCRIPTION="Redis $REDIS_VERSION available as container, is an advanced key-value store. \ -It is often referred to as a data structure server since keys can contain strings, hashes, lists, \ -sets and sorted sets. You can run atomic operations on these types, like appending to a string; \ -incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; \ -or getting the member with highest ranking in a sorted set. In order to achieve its outstanding \ -performance, Redis works with an in-memory dataset. Depending on your use case, you can persist \ -it either by dumping the dataset to disk every once in a while, or by appending each command to a log." - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Redis $REDIS_VERSION" \ - io.openshift.expose-services="6379:redis" \ - io.openshift.tags="database,redis,redis$REDIS_VERSION,redis-$REDIS_VERSION" \ - com.redhat.component="redis-$REDIS_VERSION-container" \ - name="rhel9/redis-$REDIS_VERSION" \ - version="1" \ - com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#rhel" \ - usage="podman run -d --name redis_database -p 6379:6379 rhel9/redis-$REDIS_VERSION" \ - maintainer="SoftwareCollections.org " - -EXPOSE 6379 - -# Create user for redis that has known UID -# We need to do this before installing the RPMs which would create user with random UID -# The UID is the one used by the default user from the parent layer (1001), -# and since the user exists already, do not create a new one, but only rename -# the existing -# This image must forever use UID 1001 for redis user so our volumes are -# safe in the future. This should *never* change, the last test is there -# to make sure of that. -RUN getent group redis &> /dev/null || groupadd -r redis &> /dev/null && \ - usermod -l redis -aG redis -c 'Redis Server' default &> /dev/null && \ -# Install gettext for envsubst command - yum -y module enable redis:$REDIS_VERSION && \ - INSTALL_PKGS="policycoreutils redis" && \ - yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum -y clean all --enablerepo='*' && \ - redis-server --version | grep -qe "^Redis server v=$REDIS_VERSION\." && echo "Found VERSION $REDIS_VERSION" && \ - mkdir -p /var/lib/redis/data && chown -R redis.0 /var/lib/redis && \ - [[ "$(id redis)" == "uid=1001(redis)"* ]] - -# Get prefix path and path to scripts rather than hard-code them in scripts -ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/redis \ - REDIS_PREFIX=/usr \ - REDIS_CONF=/etc/redis/redis.conf - -COPY root / - -# this is needed due to issues with squash -# when this directory gets rm'd by the container-setup -# script. -RUN /usr/libexec/container-setup - -VOLUME ["/var/lib/redis/data"] - -# Using a numeric value because of a comment in [1]: -# If your S2I image does not include a USER declaration with a numeric user, -# your builds will fail by default. -# [1] https://docs.openshift.com/container-platform/4.4/openshift_images/create-images.html#images-create-guide-openshift_create-images -USER 1001 - -ENTRYPOINT ["container-entrypoint"] -CMD ["run-redis"] diff --git a/7/root/usr/bin/run-valkey b/7/root/usr/bin/run-valkey new file mode 100755 index 0000000..784252f --- /dev/null +++ b/7/root/usr/bin/run-valkey @@ -0,0 +1,27 @@ +#!/bin/bash + +export_vars=$(cgroup-limits); export $export_vars +source ${CONTAINER_SCRIPTS_PATH}/common.sh +set -eu + +[ -f ${CONTAINER_SCRIPTS_PATH}/validate-variables.sh ] && source ${CONTAINER_SCRIPTS_PATH}/validate-variables.sh + +# Process the Redis configuration files +log_info 'Processing Valkey configuration files ...' +if [[ -v VALKEY_PASSWORD ]]; then + envsubst < ${CONTAINER_SCRIPTS_PATH}/password.conf.template >> "${VALKEY_CONF}" +else + log_info 'WARNING: setting VALKEY_PASSWORD is recommended' +fi + +# Source post-init source if exists +if [ -f ${CONTAINER_SCRIPTS_PATH}/post-init.sh ]; then + log_info 'Sourcing post-init.sh ...' + source ${CONTAINER_SCRIPTS_PATH}/post-init.sh +fi + +# Restart the Redis server with public IP bindings +unset_env_vars +log_volume_info "${VALKEY_DATADIR}" +log_info 'Running final exec -- Only Valkey logs after this point' +exec ${VALKEY_PREFIX}/bin/valkey-server "${VALKEY_CONF}" --daemonize no "$@" 2>&1 diff --git a/7/root/usr/bin/usage b/7/root/usr/bin/usage index d204ed2..46654a0 100755 --- a/7/root/usr/bin/usage +++ b/7/root/usr/bin/usage @@ -1,4 +1,3 @@ #!/bin/bash -cat /usr/share/container-scripts/redis/README.md - +cat /usr/share/container-scripts/valkey/README.md diff --git a/7/root/usr/libexec/container-setup b/7/root/usr/libexec/container-setup index 13ca0da..efbe944 100755 --- a/7/root/usr/libexec/container-setup +++ b/7/root/usr/libexec/container-setup @@ -4,16 +4,16 @@ source ${CONTAINER_SCRIPTS_PATH}/common.sh set -eu # setup directory for data -chown -R redis:0 "${HOME}" "${REDIS_CONF}" -restorecon -R "${HOME}" "${REDIS_CONF}" +chown -R valkey:0 "${HOME}" "${VALKEY_CONF}" +restorecon -R "${HOME}" "${VALKEY_CONF}" # Loosen permission bits for group to avoid problems running container with # arbitrary UID -# When only specifying user, group is 0, that's why /var/lib/redis must have -# owner redis.0; that allows to avoid a+rwx for this dir -chmod 0770 "${HOME}" "${REDIS_DATADIR}" -chmod 0660 "${REDIS_CONF}" +# When only specifying user, group is 0, that's why /var/lib/valkey must have +# owner valkey.0; that allows to avoid a+rwx for this dir +chmod 0770 "${HOME}" "${VALKEY_DATADIR}" +chmod 0660 "${VALKEY_CONF}" # adjust config with changes we do every-time clear_config -envsubst < ${CONTAINER_SCRIPTS_PATH}/base.conf.template >> "${REDIS_CONF}" +envsubst < ${CONTAINER_SCRIPTS_PATH}/base.conf.template >> "${VALKEY_CONF}" diff --git a/7/root/usr/share/container-scripts/redis/README.md b/7/root/usr/share/container-scripts/redis/README.md index 981b1e2..cd6ffb9 100644 --- a/7/root/usr/share/container-scripts/redis/README.md +++ b/7/root/usr/share/container-scripts/redis/README.md @@ -1,7 +1,7 @@ -Redis 7 in-memory data structure store container image +Valkey 7 in-memory data structure store container image ====================================================== -This container image includes Redis 7 in-memory data structure store for OpenShift and general usage. +This container image includes Valkey 7 in-memory data structure store for OpenShift and general usage. Users can choose between RHEL, CentOS Stream, and Fedora based images. The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), the CentOS Stream images are available on [Quay.io](https://quay.io/organization/sclorg), @@ -13,40 +13,40 @@ Note: while the examples in this README are calling `podman`, you can replace an Description ----------- -Redis 7 available as container, is an advanced key-value store. +Valkey 7 available as container, is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. You can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set. In order to achieve its outstanding -performance, Redis works with an in-memory dataset. Depending on your use case, you can persist +performance, Valkey works with an in-memory dataset. Depending on your use case, you can persist it either by dumping the dataset to disk every once in a while, or by appending each command to a log. Usage ----- -For this, we will assume that you are using the `rhel8/redis-7` image. +For this, we will assume that you are using the `rhel8/valkey-7` image. If you want to set only the mandatory environment variables and not store the database in a host directory, execute the following command: ``` -$ podman run -d --name redis_database -p 6379:6379 rhel8/redis-7 +$ podman run -d --name valkey_database -p 6379:6379 rhel8/valkey-7 ``` -This will create a container named `redis_database`. Port 6379 will be exposed and mapped +This will create a container named `valkey_database`. Port 6379 will be exposed and mapped to the host. If you want your database to be persistent across container executions, also add a -`-v /host/db/path:/var/lib/redis/data:Z` argument. This will be the Redis data directory. +`-v /host/db/path:/var/lib/valkey/data:Z` argument. This will be the Valkey data directory. -For protecting Redis data by a password, pass `REDIS_PASSWORD` environment variable +For protecting Valkey data by a password, pass `VALKEY_PASSWORD` environment variable to the container like this: ``` -$ podman run -d --name redis_database -e REDIS_PASSWORD=strongpassword rhel8/redis-7 +$ podman run -d --name valkey_database -e VALKEY_PASSWORD=strongpassword rhel8/valkey-7 ``` -**Warning: since Redis is pretty fast an outside user can try up to +**Warning: since Valkey is pretty fast an outside user can try up to 150k passwords per second against a good box. This means that you should use a very strong password otherwise it will be very easy to break.** @@ -54,7 +54,7 @@ use a very strong password otherwise it will be very easy to break.** Environment variables and volumes ---------------------------------- -**`REDIS_PASSWORD`** +**`VALKEY_PASSWORD`** Password for the server access **`BIND_ADDRESS`** @@ -63,8 +63,8 @@ Environment variables and volumes You can also set the following mount points by passing the `-v /host:/container:Z` flag to podman. -**`/var/lib/redis/data`** - Redis data directory +**`/var/lib/valkey/data`** + Valkey data directory **Notice: When mouting a directory from the host into the container, ensure that the mounted @@ -74,7 +74,7 @@ matches the user UID or name which is running inside the container.** Troubleshooting --------------- -Redis logs into standard output, so the log is available in the container log. The log can be examined by running: +Valkey logs into standard output, so the log is available in the container log. The log can be examined by running: podman logs @@ -82,7 +82,6 @@ Redis logs into standard output, so the log is available in the container log. T See also -------- Dockerfile and other sources for this container image are available on -https://github.com/sclorg/redis-container. +https://github.com/sclorg/valkey-container. In that repository you also can find another versions of Python environment Dockerfiles. -Dockerfile for RHEL8 it's `Dockerfile.rhel8`, for RHEL9 it's `Dockerfile.rhel9`, -for CentOS Stream 9 it's `Dockerfile.c9s` and the Fedora Dockerfile is called Dockerfile.fedora. +Dockerfile for CentOS Stream 10 it's `Dockerfile.c10s` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/7/root/usr/share/container-scripts/valkey/README.md b/7/root/usr/share/container-scripts/valkey/README.md new file mode 100644 index 0000000..cd6ffb9 --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/README.md @@ -0,0 +1,87 @@ +Valkey 7 in-memory data structure store container image +====================================================== + +This container image includes Valkey 7 in-memory data structure store for OpenShift and general usage. +Users can choose between RHEL, CentOS Stream, and Fedora based images. +The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), +the CentOS Stream images are available on [Quay.io](https://quay.io/organization/sclorg), +and the Fedora images are available in [Fedora Registry](https://quay.io/organization/fedora). +The resulting image can be run using [podman](https://github.com/containers/libpod). + +Note: while the examples in this README are calling `podman`, you can replace any such calls by `docker` with the same arguments + +Description +----------- + +Valkey 7 available as container, is an advanced key-value store. +It is often referred to as a data structure server since keys can contain strings, hashes, lists, +sets and sorted sets. You can run atomic operations on these types, like appending to a string; +incrementing the value in a hash; pushing to a list; computing set intersection, union and difference; +or getting the member with highest ranking in a sorted set. In order to achieve its outstanding +performance, Valkey works with an in-memory dataset. Depending on your use case, you can persist +it either by dumping the dataset to disk every once in a while, or by appending each command to a log. + + +Usage +----- + +For this, we will assume that you are using the `rhel8/valkey-7` image. +If you want to set only the mandatory environment variables and not store +the database in a host directory, execute the following command: + +``` +$ podman run -d --name valkey_database -p 6379:6379 rhel8/valkey-7 +``` + +This will create a container named `valkey_database`. Port 6379 will be exposed and mapped +to the host. + +If you want your database to be persistent across container executions, also add a +`-v /host/db/path:/var/lib/valkey/data:Z` argument. This will be the Valkey data directory. + +For protecting Valkey data by a password, pass `VALKEY_PASSWORD` environment variable +to the container like this: + +``` +$ podman run -d --name valkey_database -e VALKEY_PASSWORD=strongpassword rhel8/valkey-7 +``` + +**Warning: since Valkey is pretty fast an outside user can try up to +150k passwords per second against a good box. This means that you should +use a very strong password otherwise it will be very easy to break.** + + +Environment variables and volumes +---------------------------------- + +**`VALKEY_PASSWORD`** + Password for the server access + +**`BIND_ADDRESS`** + IP address for the server to listen on + + +You can also set the following mount points by passing the `-v /host:/container:Z` flag to podman. + +**`/var/lib/valkey/data`** + Valkey data directory + + +**Notice: When mouting a directory from the host into the container, ensure that the mounted +directory has the appropriate permissions and that the owner and group of the directory +matches the user UID or name which is running inside the container.** + + +Troubleshooting +--------------- +Valkey logs into standard output, so the log is available in the container log. The log can be examined by running: + + podman logs + + +See also +-------- +Dockerfile and other sources for this container image are available on +https://github.com/sclorg/valkey-container. +In that repository you also can find another versions of Python environment Dockerfiles. +Dockerfile for CentOS Stream 10 it's `Dockerfile.c10s` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/7/root/usr/share/container-scripts/valkey/base.conf.template b/7/root/usr/share/container-scripts/valkey/base.conf.template new file mode 100644 index 0000000..2dc3815 --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/base.conf.template @@ -0,0 +1,2 @@ +dir ${VALKEY_DATADIR} +unixsocket ${VALKEY_SOCK} diff --git a/7/root/usr/share/container-scripts/valkey/common.sh b/7/root/usr/share/container-scripts/valkey/common.sh new file mode 100644 index 0000000..73c2f32 --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/common.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +source ${CONTAINER_SCRIPTS_PATH}/helpers.sh + +# Data directory where Valkey database files live. The data subdirectory is here +# because .bashrc lives in /var/lib/valkey/ and we don't want a +# volume to override it. +export VALKEY_DATADIR=/var/lib/valkey/data + +# Be paranoid and stricter than we should be. +valkey_password_regex='^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$' + +# Make sure env variables don't propagate to valkey process. +function unset_env_vars() { + log_info 'Cleaning up environment variable VALKEY_PASSWORD ...' + unset VALKEY_PASSWORD +} + +# Comment out settings that we'll set in container specifically +function clear_config() { + sed -e "s/^bind/#bind/" \ + -e "s/^logfile/#logfile/" \ + -e "s/^dir /#dir /" \ + -e "/^protected-mode/s/yes/no/" \ + -i "${VALKEY_CONF}" +} + +function setup_bind_address() { + # Function sets bind + if [[ -v BIND_ADDRESS ]]; then + log_info "Configuring valkey to listen on $BIND_ADDRESS only ..." + echo "bind $BIND_ADDRESS" >> "${VALKEY_CONF}" + fi +} diff --git a/7/root/usr/share/container-scripts/valkey/helpers.sh b/7/root/usr/share/container-scripts/valkey/helpers.sh new file mode 100644 index 0000000..4e832fc --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/helpers.sh @@ -0,0 +1,24 @@ +function log_info { + echo "---> `date +%T` $@" +} + +function log_and_run { + log_info "Running $@" + "$@" +} + +function log_volume_info { + CONTAINER_DEBUG=${CONTAINER_DEBUG:-} + if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then + return + fi + + log_info "Volume info for $@:" + set +e + log_and_run mount + while [ $# -gt 0 ]; do + log_and_run ls -alZ $1 + shift + done + set -e +} diff --git a/7/root/usr/share/container-scripts/valkey/password.conf.template b/7/root/usr/share/container-scripts/valkey/password.conf.template new file mode 100644 index 0000000..81b5ebb --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/password.conf.template @@ -0,0 +1,3 @@ +# password for the server +requirepass "${VALKEY_PASSWORD}" + diff --git a/7/root/usr/share/container-scripts/valkey/post-init.sh b/7/root/usr/share/container-scripts/valkey/post-init.sh new file mode 100644 index 0000000..62e13ab --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/post-init.sh @@ -0,0 +1,11 @@ +# This file serves for extending the container image, typically by changing +# the configuration, loading some data etc. + +# Feel free to add content to this file or rewrite it at all. +# You may also start redis server locally to load some data for example, +# but do not forget to stop it after it, so it can be restarted after it. + +source "${CONTAINER_SCRIPTS_PATH}/common.sh" +set -eu + +setup_bind_address diff --git a/7/root/usr/share/container-scripts/valkey/validate-variables.sh b/7/root/usr/share/container-scripts/valkey/validate-variables.sh new file mode 100644 index 0000000..436de68 --- /dev/null +++ b/7/root/usr/share/container-scripts/valkey/validate-variables.sh @@ -0,0 +1,15 @@ +function usage() { + [ $# == 1 ] && echo "error: $1" + echo "You can specify the following environment variables:" + echo " VALKEY_PASSWORD (regex: '$valkey_password_regex')" + exit 1 +} + +function validate_variables() { + # Check basic sanity of specified variables + if [[ -v VALKEY_PASSWORD ]]; then + [[ "$VALKEY_PASSWORD" =~ $valkey_password_regex ]] || usage "Invalid password" + fi +} + +validate_variables diff --git a/Makefile b/Makefile index 3d7dd11..6d67be0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Variables are documented in common/build.sh. -BASE_IMAGE_NAME = redis +BASE_IMAGE_NAME = valkey VERSIONS = 7 OPENSHIFT_NAMESPACES = diff --git a/examples/valkey-ephemeral-template.json b/examples/valkey-ephemeral-template.json new file mode 100644 index 0000000..6f7f16c --- /dev/null +++ b/examples/valkey-ephemeral-template.json @@ -0,0 +1,199 @@ +{ + "kind": "Template", + "apiVersion": "template.openshift.io/v1", + "metadata": { + "name": "valkey-ephemeral", + "annotations": { + "openshift.io/display-name": "Valkey (Ephemeral)", + "description": "Valkey in-memory data structure store, without persistent storage. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/valkey-container/blob/master/5.\n\nWARNING: Any data stored will be lost upon pod destruction. Only use this template for testing", + "iconClass": "icon-valkey", + "tags": "database,valkey", + "openshift.io/long-description": "This template provides a standalone Valkey server. The data is not stored on persistent storage, so any restart of the service will result in all data being lost.", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "openshift.io/documentation-url": "https://github.com/sclorg/valkey-container/tree/master/5", + "openshift.io/support-url": "https://access.redhat.com" + } + }, + "message": "The following service(s) have been created in your project: ${DATABASE_SERVICE_NAME}.\n\n Password: ${VALKEY_PASSWORD}\n Connection URL: valkey://${DATABASE_SERVICE_NAME}:6379/\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/valkey-container/blob/master/5.", + "labels": { + "template": "valkey-ephemeral-template" + }, + "objects": [ + { + "kind": "Secret", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "template.openshift.io/expose-password": "{.data['database-password']}" + } + }, + "stringData" : { + "database-password" : "${VALKEY_PASSWORD}" + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "template.openshift.io/expose-uri": "valkey://{.spec.clusterIP}:{.spec.ports[?(.name==\"valkey\")].port}" + } + }, + "spec": { + "ports": [ + { + "name": "valkey", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379, + "nodePort": 0 + } + ], + "selector": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "type": "ClusterIP", + "sessionAffinity": "None" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"valkey:${VALKEY_VERSION}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + } + }, + "spec": { + "strategy": { + "type": "Recreate" + }, + "replicas": 1, + "selector": { + "matchLabels": { + "name": "${DATABASE_SERVICE_NAME}" + } + }, + "template": { + "metadata": { + "labels": { + "name": "${DATABASE_SERVICE_NAME}" + } + }, + "spec": { + "containers": [ + { + "name": "valkey", + "image": " ", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "readinessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 5, + "exec": { + "command": [ "/bin/sh", "-i", "-c", "test \"$(valkey-cli -h 127.0.0.1 -a $VALKEY_PASSWORD ping)\" == \"PONG\""] + } + }, + "livenessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 30, + "tcpSocket": { + "port": 6379 + } + }, + "env": [ + { + "name": "VALKEY_PASSWORD", + "valueFrom": { + "secretKeyRef" : { + "name" : "${DATABASE_SERVICE_NAME}", + "key" : "database-password" + } + } + } + ], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + }, + "volumeMounts": [ + { + "name": "${DATABASE_SERVICE_NAME}-data", + "mountPath": "/var/lib/valkey/data" + } + ], + "terminationMessagePath": "/dev/termination-log", + "imagePullPolicy": "IfNotPresent", + "capabilities": {}, + "securityContext": { + "capabilities": {}, + "privileged": false + } + } + ], + "volumes": [ + { + "name": "${DATABASE_SERVICE_NAME}-data", + "emptyDir": { + "medium": "" + } + } + ], + "restartPolicy": "Always", + "dnsPolicy": "ClusterFirst" + } + } + }, + "status": {} + } + ], + "parameters": [ + { + "name": "MEMORY_LIMIT", + "displayName": "Memory Limit", + "description": "Maximum amount of memory the container can use.", + "value": "512Mi", + "required": true + }, + { + "name": "NAMESPACE", + "displayName": "Namespace", + "description": "The OpenShift Namespace where the ImageStream resides.", + "value": "openshift" + }, + { + "name": "DATABASE_SERVICE_NAME", + "displayName": "Database Service Name", + "description": "The name of the OpenShift Service exposed for the database.", + "value": "valkey", + "required": true + }, + { + "name": "VALKEY_PASSWORD", + "displayName": "Valkey Connection Password", + "description": "Password for the Valkey connection user.", + "generate": "expression", + "from": "[a-zA-Z0-9]{16}", + "required": true + }, + { + "name": "VALKEY_VERSION", + "displayName": "Version of Valkey Image", + "description": "Version of Valkey image to be used (5-el7, 5-el8, 6-el7, 6-el8, or latest).", + "value": "6-el8", + "required": true + } + ] +} diff --git a/examples/valkey-persistent-template.json b/examples/valkey-persistent-template.json new file mode 100644 index 0000000..a51b5d9 --- /dev/null +++ b/examples/valkey-persistent-template.json @@ -0,0 +1,223 @@ +{ + "kind": "Template", + "apiVersion": "template.openshift.io/v1", + "metadata": { + "name": "valkey-persistent", + "annotations": { + "openshift.io/display-name": "Valkey", + "description": "Valkey in-memory data structure store, with persistent storage. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/valkey-container/blob/master/5.\n\nNOTE: You must have persistent volumes available in your cluster to use this template.", + "iconClass": "icon-valkey", + "tags": "database,valkey", + "openshift.io/long-description": "This template provides a standalone Valkey server. The data is stored on persistent storage.", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "openshift.io/documentation-url": "https://github.com/sclorg/valkey-container/tree/master/5", + "openshift.io/support-url": "https://access.redhat.com" + } + }, + "message": "The following service(s) have been created in your project: ${DATABASE_SERVICE_NAME}.\n\n Password: ${VALKEY_PASSWORD}\n Connection URL: valkey://${DATABASE_SERVICE_NAME}:6379/\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/valkey-container/blob/master/5.", + "labels": { + "template": "valkey-persistent-template" + }, + "objects": [ + { + "kind": "Secret", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "template.openshift.io/expose-password": "{.data['database-password']}" + } + }, + "stringData" : { + "database-password" : "${VALKEY_PASSWORD}" + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "template.openshift.io/expose-uri": "valkey://{.spec.clusterIP}:{.spec.ports[?(.name==\"valkey\")].port}" + } + }, + "spec": { + "ports": [ + { + "name": "valkey", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379, + "nodePort": 0 + } + ], + "selector": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "type": "ClusterIP", + "sessionAffinity": "None" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "${VOLUME_CAPACITY}" + } + } + } + }, + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"valkey:${VALKEY_VERSION}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + } + }, + "spec": { + "strategy": { + "type": "Recreate" + }, + "replicas": 1, + "selector": { + "matchLabels": { + "name": "${DATABASE_SERVICE_NAME}" + } + }, + "template": { + "metadata": { + "labels": { + "name": "${DATABASE_SERVICE_NAME}" + } + }, + "spec": { + "containers": [ + { + "name": "valkey", + "image": " ", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "readinessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 5, + "exec": { + "command": [ "/bin/sh", "-i", "-c", "test \"$(valkey-cli -h 127.0.0.1 -a $VALKEY_PASSWORD ping)\" == \"PONG\""] + } + }, + "livenessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 30, + "tcpSocket": { + "port": 6379 + } + }, + "env": [ + { + "name": "VALKEY_PASSWORD", + "valueFrom": { + "secretKeyRef" : { + "name" : "${DATABASE_SERVICE_NAME}", + "key" : "database-password" + } + } + } + ], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + }, + "volumeMounts": [ + { + "name": "${DATABASE_SERVICE_NAME}-data", + "mountPath": "/var/lib/valkey/data" + } + ], + "terminationMessagePath": "/dev/termination-log", + "imagePullPolicy": "IfNotPresent", + "capabilities": {}, + "securityContext": { + "capabilities": {}, + "privileged": false + } + } + ], + "volumes": [ + { + "name": "${DATABASE_SERVICE_NAME}-data", + "persistentVolumeClaim": { + "claimName": "${DATABASE_SERVICE_NAME}" + } + } + ], + "restartPolicy": "Always", + "dnsPolicy": "ClusterFirst" + } + } + }, + "status": {} + } + ], + "parameters": [ + { + "name": "MEMORY_LIMIT", + "displayName": "Memory Limit", + "description": "Maximum amount of memory the container can use.", + "value": "512Mi", + "required": true + }, + { + "name": "NAMESPACE", + "displayName": "Namespace", + "description": "The OpenShift Namespace where the ImageStream resides.", + "value": "openshift" + }, + { + "name": "DATABASE_SERVICE_NAME", + "displayName": "Database Service Name", + "description": "The name of the OpenShift Service exposed for the database.", + "value": "valkey", + "required": true + }, + { + "name": "VALKEY_PASSWORD", + "displayName": "Valkey Connection Password", + "description": "Password for the Valkey connection user.", + "generate": "expression", + "from": "[a-zA-Z0-9]{16}", + "required": true + }, + { + "name": "VOLUME_CAPACITY", + "displayName": "Volume Capacity", + "description": "Volume space available for data, e.g. 512Mi, 2Gi.", + "value": "1Gi", + "required": true + }, + { + "name": "VALKEY_VERSION", + "displayName": "Version of Valkey Image", + "description": "Version of Valkey image to be used (5-el7, 5-el8, 6-el7, 6-el8, or latest).", + "value": "6-el8", + "required": true + } + ] +} diff --git a/imagestreams/imagestreams.yaml b/imagestreams/imagestreams.yaml index c7af244..9c3504e 100644 --- a/imagestreams/imagestreams.yaml +++ b/imagestreams/imagestreams.yaml @@ -1,33 +1,15 @@ --- -- name: redis - pretty_name: Redis +- name: valkey + pretty_name: Valkey sample_repo: "" category: database description: >- - Provides a Redis APP_VERSION database on DISTRO_NAME. For more information + Provides a Valkey APP_VERSION database on DISTRO_NAME. For more information about using this database image, including OpenShift considerations, see - https://github.com/sclorg/redis-container/tree/master/APP_VERSION/README.md. + https://github.com/sclorg/valkey-container/tree/master/APP_VERSION/README.md. imagestream_files: - - filename: redis-centos.json - latest: "6-el9" + - filename: valkey-centos.json + latest: "7-el10" distros: - - name: CentOS Stream 9 - app_versions: [6, 7] - - - filename: redis-rhel.json - latest: "6-el8" - distros: - - name: RHEL 8 - app_versions: [6] - - - name: RHEL 9 - app_versions: [6, 7] - - - filename: redis-rhel-aarch64.json - latest: "6-el8" - distros: - - name: RHEL 8 - app_versions: [6] - - - name: RHEL 9 - app_versions: [6, 7] + - name: CentOS Stream 10 + app_versions: [7] diff --git a/imagestreams/valkey-centos.json b/imagestreams/valkey-centos.json new file mode 100644 index 0000000..7be4221 --- /dev/null +++ b/imagestreams/valkey-centos.json @@ -0,0 +1,68 @@ +{ + "kind": "ImageStream", + "apiVersion": "image.openshift.io/v1", + "metadata": { + "name": "valkey", + "annotations": { + "openshift.io/display-name": "Valkey" + } + }, + "spec": { + "tags": [ + { + "name": "6-el9", + "annotations": { + "openshift.io/display-name": "Valkey 6 (CentOS Stream 9)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Valkey 6 database on CentOS Stream 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/valkey-container/tree/master/6/README.md.", + "iconClass": "icon-valkey", + "tags": "database,valkey", + "version": "6" + }, + "from": { + "kind": "DockerImage", + "name": "quay.io/sclorg/valkey-6-c9s:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "7-el9", + "annotations": { + "openshift.io/display-name": "Valkey 7 (CentOS Stream 9)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Valkey 7 database on CentOS Stream 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/valkey-container/tree/master/7/README.md.", + "iconClass": "icon-valkey", + "tags": "database,valkey", + "version": "7" + }, + "from": { + "kind": "DockerImage", + "name": "quay.io/sclorg/valkey-7-c9s:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "latest", + "annotations": { + "openshift.io/display-name": "Valkey 6 (Latest)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Valkey 6 database on CentOS Stream 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/valkey-container/tree/master/6/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version available on OpenShift, including major version updates.\n", + "iconClass": "icon-valkey", + "tags": "database,valkey", + "version": "6" + }, + "from": { + "kind": "ImageStreamTag", + "name": "6-el9" + }, + "referencePolicy": { + "type": "Local" + } + } + ] + } +} diff --git a/imagestreams/valkey-rhel-aarch64.json b/imagestreams/valkey-rhel-aarch64.json new file mode 100644 index 0000000..8361939 --- /dev/null +++ b/imagestreams/valkey-rhel-aarch64.json @@ -0,0 +1,86 @@ +{ + "kind": "ImageStream", + "apiVersion": "image.openshift.io/v1", + "metadata": { + "name": "redis", + "annotations": { + "openshift.io/display-name": "Redis" + } + }, + "spec": { + "tags": [ + { + "name": "6-el8", + "annotations": { + "openshift.io/display-name": "Redis 6 (RHEL 8)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 6 database on RHEL 8. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/6/README.md.", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "6" + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel8/redis-6:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "6-el9", + "annotations": { + "openshift.io/display-name": "Redis 6 (RHEL 9)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 6 database on RHEL 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/6/README.md.", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "6" + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel9/redis-6:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "7-el9", + "annotations": { + "openshift.io/display-name": "Redis 7 (RHEL 9)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 7 database on RHEL 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/7/README.md.", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "7" + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel9/redis-7:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "latest", + "annotations": { + "openshift.io/display-name": "Redis 6 (Latest)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 6 database on RHEL 8. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/6/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version available on OpenShift, including major version updates.\n", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "6" + }, + "from": { + "kind": "ImageStreamTag", + "name": "6-el8" + }, + "referencePolicy": { + "type": "Local" + } + } + ] + } +} diff --git a/imagestreams/valkey-rhel.json b/imagestreams/valkey-rhel.json new file mode 100644 index 0000000..8361939 --- /dev/null +++ b/imagestreams/valkey-rhel.json @@ -0,0 +1,86 @@ +{ + "kind": "ImageStream", + "apiVersion": "image.openshift.io/v1", + "metadata": { + "name": "redis", + "annotations": { + "openshift.io/display-name": "Redis" + } + }, + "spec": { + "tags": [ + { + "name": "6-el8", + "annotations": { + "openshift.io/display-name": "Redis 6 (RHEL 8)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 6 database on RHEL 8. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/6/README.md.", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "6" + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel8/redis-6:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "6-el9", + "annotations": { + "openshift.io/display-name": "Redis 6 (RHEL 9)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 6 database on RHEL 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/6/README.md.", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "6" + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel9/redis-6:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "7-el9", + "annotations": { + "openshift.io/display-name": "Redis 7 (RHEL 9)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 7 database on RHEL 9. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/7/README.md.", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "7" + }, + "from": { + "kind": "DockerImage", + "name": "registry.redhat.io/rhel9/redis-7:latest" + }, + "referencePolicy": { + "type": "Local" + } + }, + { + "name": "latest", + "annotations": { + "openshift.io/display-name": "Redis 6 (Latest)", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "description": "Provides a Redis 6 database on RHEL 8. For more information about using this database image, including OpenShift considerations, see https://github.com/sclorg/redis-container/tree/master/6/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version available on OpenShift, including major version updates.\n", + "iconClass": "icon-redis", + "tags": "database,redis", + "version": "6" + }, + "from": { + "kind": "ImageStreamTag", + "name": "6-el8" + }, + "referencePolicy": { + "type": "Local" + } + } + ] + } +} diff --git a/test/run b/test/run index 161c6b9..383bc07 100755 --- a/test/run +++ b/test/run @@ -26,24 +26,23 @@ run_doc_test run_bind_address_test run_no_bind_address_test " - THISDIR=$(dirname ${BASH_SOURCE[0]}) source "${THISDIR}"/test-lib.sh function connection_works() { local container_ip="$1"; shift local password="$1"; shift - if [ "$(redis_cmd "$container_ip" "$password" ping)" == "PONG" ] ; then + if [ "$(valkey_cmd "$container_ip" "$password" ping)" == "PONG" ] ; then return 0 fi return 1 } -function redis_cmd() { +function valkey_cmd() { local container_ip="$1"; shift local password="$1"; shift # if empty password is given, then no password will be specified - docker run --rm "$IMAGE_NAME" redis-cli -h "$container_ip" ${password:+-a "$password"} "$@" + docker run --rm "$IMAGE_NAME" valkey-cli -h "$container_ip" ${password:+-a "$password"} "$@" } function test_connection() { @@ -51,7 +50,7 @@ function test_connection() { local password=$1 ; shift local ip ip=$(ct_get_cip $name) - echo " Testing Redis connection to $ip (password='${password:-}')..." + echo " Testing Valkey connection to $ip (password='${password:-}')..." local max_attempts=10 local sleep_time=2 local i @@ -69,16 +68,16 @@ function test_connection() { return 1 } -function test_redis() { +function test_valkey() { local container_ip="$1" local password="$2" - echo " Testing Redis (password='${password:-}')" - redis_cmd "$container_ip" "$password" set a 1 >/dev/null + echo " Testing Valkey (password='${password:-}')" + valkey_cmd "$container_ip" "$password" set a 1 >/dev/null ct_check_testcase_result $? - redis_cmd "$container_ip" "$password" set b 2 >/dev/null + valkey_cmd "$container_ip" "$password" set b 2 >/dev/null ct_check_testcase_result $? - test "$(redis_cmd "$container_ip" "$password" get b)" == '2' + test "$(valkey_cmd "$container_ip" "$password" get b)" == '2' echo " Success!" echo } @@ -98,17 +97,17 @@ function run_change_password_test() { local tmpdir=$(mktemp -d) mkdir "${tmpdir}/data" && chmod -R a+rwx "${tmpdir}" - # Create Redis container with persistent volume and set the initial password - create_container "testpass1" -e REDIS_PASSWORD=foo \ - -v ${tmpdir}:/var/lib/redis/data:Z + # Create Valkey container with persistent volume and set the initial password + create_container "testpass1" -e VALKEY_PASSWORD=foo \ + -v ${tmpdir}:/var/lib/valkey/data:Z ct_check_testcase_result $? test_connection testpass1 foo ct_check_testcase_result $? docker stop $(ct_get_cid testpass1) >/dev/null # Create second container with changed password - create_container "testpass2" -e REDIS_PASSWORD=bar \ - -v ${tmpdir}:/var/lib/redis/data:Z + create_container "testpass2" -e VALKEY_PASSWORD=bar \ + -v ${tmpdir}:/var/lib/valkey/data:Z ct_check_testcase_result $? test_connection testpass2 bar ct_check_testcase_result $? @@ -140,23 +139,23 @@ function assert_login_access() { function assert_local_access() { local id="$1" ; shift - docker exec $(ct_get_cid "$id") bash -c 'redis-cli ping' + docker exec $(ct_get_cid "$id") bash -c 'valkey-cli ping' } function assert_bind_address() { local name="$1" - local run_cmd="[ -f \${REDIS_CONF} ] && grep \"^bind 127.0.0.1\" \${REDIS_CONF}" + local run_cmd="[ -f \${VALKEY_CONF} ] && grep \"^bind 127.0.0.1\" \${VALKEY_CONF}" - echo "Checking if bind is set to 127.0.0.1 in redis.conf file." + echo "Checking if bind is set to 127.0.0.1 in valkey.conf file." docker exec $(ct_get_cid "$name") /bin/bash -c "${run_cmd}" } function assert_no_bind_address() { local name="$1" - local run_cmd="[ -f \${REDIS_CONF} ] && ! grep \"^bind 127.0.0.1\" \${REDIS_CONF}" + local run_cmd="[ -f \${VALKEY_CONF} ] && ! grep \"^bind 127.0.0.1\" \${VALKEY_CONF}" - echo "Checking if bind is not set in redis.conf file." + echo "Checking if bind is not set in valkey.conf file." docker exec $(ct_get_cid "$name") /bin/bash -c "${run_cmd}" } @@ -164,7 +163,7 @@ function assert_no_bind_address() { function assert_container_creation_fails() { # Time the docker run command. It should fail. If it doesn't fail, - # redis will keep running so we kill it with SIGKILL to make sure + # valkey will keep running so we kill it with SIGKILL to make sure # timeout returns a non-zero value. local ret=0 timeout -s 9 --preserve-status 60s docker run --rm "$@" $IMAGE_NAME >/dev/null || ret=$? @@ -176,7 +175,7 @@ function assert_container_creation_fails() { } function try_image_invalid_combinations() { - assert_container_creation_fails -e REDIS_PASSWORD="pass with space" "$@" + assert_container_creation_fails -e VALKEY_PASSWORD="pass with space" "$@" ct_check_testcase_result $? } @@ -219,14 +218,14 @@ test_scl_usage() { } run_doc_test() { - ct_doc_content_old 6379 "REDIS.*PASSWORD" volume + ct_doc_content_old 6379 "VALKEY.*PASSWORD" volume return $? } function run_tests() { local name=$1 ; shift local ret - envs=${PASS:+"-e REDIS_PASSWORD=$PASS"} + envs=${PASS:+"-e VALKEY_PASSWORD=$PASS"} PASS=${PASS:-} create_container $name $envs ret=$? @@ -234,14 +233,14 @@ function run_tests() { # Only check version on rhel/centos builds if [ "$OS" != "fedora" ]; then echo " Testing scl usage" - test_scl_usage "$name" 'redis-server --version' "$VERSION" + test_scl_usage "$name" 'valkey-server --version' "$VERSION" ct_check_testcase_result $? fi if [ "$name" == "bind_address_test" ]; then echo " Testing bind_address test" assert_bind_address "$name" ct_check_testcase_result $? - # Quit test suite. redis container will not response. bind is set to localhost + # Quit test suite. valkey container will not response. bind is set to localhost return fi if [ "$name" == "no_bind_address_test" ]; then @@ -271,7 +270,7 @@ function run_tests() { echo " Local access SUCCESS." fi echo - test_redis "$container_ip" "$PASS" + test_valkey "$container_ip" "$PASS" ct_check_testcase_result $? } @@ -305,5 +304,5 @@ function run_no_bind_address_test() { ct_init -TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "redis_tests" +TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "valkey_tests" # vim: set tabstop=2:shiftwidth=2:expandtab: diff --git a/test/run-openshift-pytest b/test/run-openshift-pytest index fc739e8..acfac84 100755 --- a/test/run-openshift-pytest +++ b/test/run-openshift-pytest @@ -10,4 +10,4 @@ THISDIR=$(dirname ${BASH_SOURCE[0]}) git show -s -cd "${THISDIR}" && python3.12 -m pytest -s -rA --showlocals -vv test_redis_*.py +cd "${THISDIR}" && python3.12 -m pytest -s -rA --showlocals -vv test_valkey_*.py diff --git a/test/run-openshift-remote-cluster b/test/run-openshift-remote-cluster index 1fea8ae..287aa50 100755 --- a/test/run-openshift-remote-cluster +++ b/test/run-openshift-remote-cluster @@ -10,11 +10,11 @@ THISDIR=$(dirname ${BASH_SOURCE[0]}) -source ${THISDIR}/test-lib-redis.sh +source ${THISDIR}/test-lib-valkey.sh TEST_LIST="\ -test_redis_integration -test_redis_imagestream +test_valkey_integration +test_valkey_imagestream test_latest_imagestreams " @@ -24,7 +24,7 @@ ct_os_set_ocp4 || exit $OC_ERR ct_os_check_compulsory_vars || exit $OC_ERR -ct_os_tag_image_for_cvp "redis" +ct_os_tag_image_for_cvp "valkey" ct_os_check_login || exit $OC_ERR @@ -37,4 +37,3 @@ TEST_SUMMARY='' TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "openshift-remote-cluster" # vim: set tabstop=2:shiftwidth=2:expandtab: - diff --git a/test/test-lib-valkey.sh b/test/test-lib-valkey.sh new file mode 100644 index 0000000..0a43628 --- /dev/null +++ b/test/test-lib-valkey.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Functions for tests for the Redis image in OpenShift. +# +# IMAGE_NAME specifies a name of the candidate image used for testing. +# The image has to be available before this script is executed. +# + +THISDIR=$(dirname ${BASH_SOURCE[0]}) + +source "${THISDIR}/test-lib.sh" +source "${THISDIR}/test-lib-openshift.sh" +source "${THISDIR}/test-lib-remote-openshift.sh" + +#function test_valkey_integration() { +# local service_name=valkey +# namespace_image="${OS}/valkey-${VERSION}" +# TEMPLATES="valkey-ephemeral-template.json +# valkey-persistent-template.json" +# for template in $TEMPLATES; do +# ct_os_test_template_app_func "${IMAGE_NAME}" \ +# "${THISDIR}/examples/${template}" \ +# "${service_name}" \ +# "ct_os_check_cmd_internal 'registry.redhat.io/${namespace_image}' '${service_name}-testing' 'timeout 15 valkey-cli -h -a testp ping' 'PONG'" \ +# "-p REDIS_VERSION=${VERSION} \ +# -p DATABASE_SERVICE_NAME="${service_name}-testing" \ +# -p REDIS_PASSWORD=testp" +# done +#} + +# Check the imagestream +#function test_valkey_imagestream() { +# TEMPLATES="valkey-ephemeral-template.json +# valkey-persistent-template.json" +# for template in $TEMPLATES; do +# ct_os_test_image_stream_template "${THISDIR}/imagestreams/valkey-${OS%[0-9]*}.json" "${THISDIR}/examples/${template}" valkey "-p REDIS_VERSION=${VERSION}${tag}" +# done +#} + +function test_latest_imagestreams() { + info "Testing the latest version in imagestreams" + # Switch to root directory of a container + pushd "${THISDIR}/../.." >/dev/null + ct_check_latest_imagestreams + popd >/dev/null +} + +# vim: set tabstop=2:shiftwidth=2:expandtab: diff --git a/test/test_valkey_imagestream.py b/test/test_valkey_imagestream.py new file mode 100644 index 0000000..93b00cb --- /dev/null +++ b/test/test_valkey_imagestream.py @@ -0,0 +1,48 @@ +import os +import sys + +import pytest + +from container_ci_suite.openshift import OpenShiftAPI +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + + +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") +TAGS = { + "rhel9": "-el9" +} +TAG = TAGS.get(OS, None) + + +class TestValkeyImagestreamTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="valkey", version=VERSION) + + def teardown_method(self): + self.oc_api.delete_project() + + @pytest.mark.parametrize( + "template", + [ + "valkey-ephemeral-template.json", + "valkey-persistent-template.json" + ] + ) + def test_valkey_imagestream_template(self, template): + os_name = ''.join(i for i in OS if not i.isdigit()) + assert self.oc_api.deploy_image_stream_template( + imagestream_file=f"imagestreams/valkey-{os_name}.json", + template_file=f"examples/{template}", + app_name=self.oc_api.pod_name_prefix, + openshift_args=[ + f"VALKEY_VERSION={VERSION}{TAG}" + ] + ) + assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) diff --git a/test/test_valkey_imagestream_template.py b/test/test_valkey_imagestream_template.py new file mode 100644 index 0000000..739684c --- /dev/null +++ b/test/test_valkey_imagestream_template.py @@ -0,0 +1,45 @@ +import os +import sys + +import pytest + +from container_ci_suite.openshift import OpenShiftAPI +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + + +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") +TAGS = { + "rhel9": "-el9" +} +TAG = TAGS.get(OS, None) + + +class TestValkeyImagestreamTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="valkey", version=VERSION) + + def teardown_method(self): + self.oc_api.delete_project() + + @pytest.mark.parametrize( + "template", + [ + "valkey-ephemeral-template.json", + "valkey-persistent-template.json" + ] + ) + def test_valkey_imagestream_template(self, template): + os_name = ''.join(i for i in OS if not i.isdigit()) + assert self.oc_api.deploy_image_stream_template( + imagestream_file=f"imagestreams/valkey-{os_name}.json", + template_file=f"examples/{template}", + app_name=self.oc_api.pod_name_prefix + ) + assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) diff --git a/test/test_valkey_latest_imagestreams.py b/test/test_valkey_latest_imagestreams.py new file mode 100644 index 0000000..f01d442 --- /dev/null +++ b/test/test_valkey_latest_imagestreams.py @@ -0,0 +1,26 @@ +import os +import sys + +import pytest + +from pathlib import Path + +from container_ci_suite.imagestreams import ImageStreamChecker +from container_ci_suite.utils import check_variables + +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + + +class TestLatestImagestreams: + + def setup_method(self): + self.isc = ImageStreamChecker(working_dir=TEST_DIR.parent) + + def test_latest_imagestream(self): + self.latest_version = self.isc.get_latest_version() + assert self.latest_version != "" + self.isc.check_imagestreams(self.latest_version) diff --git a/test/test_valkey_template.py b/test/test_valkey_template.py new file mode 100644 index 0000000..29d4ca4 --- /dev/null +++ b/test/test_valkey_template.py @@ -0,0 +1,53 @@ +import os +import sys + +import pytest + +from container_ci_suite.openshift import OpenShiftAPI +from container_ci_suite.utils import check_variables + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + + +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") + + +class TestRedisDeployTemplate: + + def setup_method(self): + self.oc_api = OpenShiftAPI(pod_name_prefix="valkey", version=VERSION) + + def teardown_method(self): + self.oc_api.delete_project() + + @pytest.mark.parametrize( + "template", + [ + "valkey-ephemeral-template.json", + "valkey-persistent-template.json" + ] + ) + def test_valkey_template_inside_cluster(self, template): + short_version = VERSION.replace(".", "") + assert self.oc_api.deploy_template_with_image( + image_name=IMAGE_NAME, + template=f"examples/{template}", + name_in_template="valkey", + openshift_args=[ + f"VALKEY_VERSION={VERSION}", + f"DATABASE_SERVICE_NAME={self.oc_api.pod_name_prefix}", + f"VALKEY_PASSWORD=testp" + ] + ) + + assert self.oc_api.is_pod_running(pod_name_prefix=self.oc_api.pod_name_prefix) + assert self.oc_api.check_command_internal( + image_name=f"registry.redhat.io/{OS}/valkey-{short_version}", + service_name=self.oc_api.pod_name_prefix, + cmd="timeout 15 valkey-cli -h -a testp ping", + expected_output="PONG" + ) diff --git a/test/valkey-persistent-template.json b/test/valkey-persistent-template.json new file mode 120000 index 0000000..3c6b52f --- /dev/null +++ b/test/valkey-persistent-template.json @@ -0,0 +1 @@ +../examples/valkey-persistent-template.json \ No newline at end of file