From c366ada6dc8cf11cf8560db70133289192e4eae7 Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 09:45:37 +0000 Subject: [PATCH 01/11] add license files --- LICENSE => licenses/LICENSE-rock | 0 licenses/LICENSE-valkey | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) rename LICENSE => licenses/LICENSE-rock (100%) create mode 100644 licenses/LICENSE-valkey diff --git a/LICENSE b/licenses/LICENSE-rock similarity index 100% rename from LICENSE rename to licenses/LICENSE-rock diff --git a/licenses/LICENSE-valkey b/licenses/LICENSE-valkey new file mode 100644 index 0000000..91d1e2c --- /dev/null +++ b/licenses/LICENSE-valkey @@ -0,0 +1,49 @@ +# License 1 + +BSD 3-Clause License + +Copyright (c) 2024-present, Valkey contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the + following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# License 2 + +BSD 3-Clause License + +Copyright (c) 2006-2020, Salvatore Sanfilippo +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the + following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 5dc42fcb7ea4dd4652c8a2ea12b6c8d293ccfa2a Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 09:53:41 +0000 Subject: [PATCH 02/11] add rockcraft.yaml --- rockcraft.yaml | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 rockcraft.yaml diff --git a/rockcraft.yaml b/rockcraft.yaml new file mode 100644 index 0000000..4180bd5 --- /dev/null +++ b/rockcraft.yaml @@ -0,0 +1,51 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE-rock file for licensing details. +--- +name: charmed-valkey # the name of your ROCK +base: ubuntu@22.04 # the base environment for this ROCK +version: '7.2.5' # just for humans. Semantic versioning is recommended +summary: Charmed Valkey ROCK OCI # 79 char long summary +description: | + This is an OCI image that bundles Valkey together with the metrics exporter + in order to be used in Charmed Operators, providing automated operations + management from day 0 to day 2 on Valkey, on top of a Virtual Machine cluster + and K8s cluster. It is an open source, end-to-end, production ready data + platform on top of cloud native technologies. +license: Apache-2.0 # your application's SPDX license + +platforms: # The platforms this ROCK should be built on and run on + amd64: + +services: + redis: + override: replace + startup: enabled + summary: Start Valkey + command: "valkey-server" + redis_exporter: + override: replace + startup: enabled + summary: Start Metrics Exporter + command: "/bin/redis_exporter" + +parts: + valkey-user: + plugin: nil + overlay-script: | + set -x + useradd -R $CRAFT_OVERLAY -M -U -r valkey + valkey: + plugin: nil + after: + - valkey-user + stage-snaps: + - charmed-valkey/latest/edge + redis_exporter: + plugin: go + after: + - valkey + source: https://github.com/canonical/redis_exporter.git + source-type: git + source-branch: "v1.60.0" + build-snaps: + - go/1.21/stable \ No newline at end of file From ac63a1d912b539f213a375389ab4f88af3dbe390 Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 09:58:37 +0000 Subject: [PATCH 03/11] add README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4524ddd --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Charmed Valkey rock +This repository will contain the packaging metadata for creating a rock of Charmed Valkey built from Charmed Valkey +Snap. + +License +The Charmed Valkey rock is free software, distributed under the Apache Software License, version 2.0. See licenses for +more information. \ No newline at end of file From e2405d7eaf0c5e4227ef80bfcaeffb01cf44fdc0 Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 10:13:10 +0000 Subject: [PATCH 04/11] add ci workflows --- .github/workflows/build.yaml | 27 +++++++++++++++++ .github/workflows/release.yaml | 55 ++++++++++++++++++++++++++++++++++ rockcraft.yaml | 2 +- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..91fcd0e --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,27 @@ +name: Build ROCK + +on: + workflow_call: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup LXD + uses: canonical/setup-lxd@main + - name: Install dependencies + run: | + sudo snap install yq + sudo snap install rockcraft --classic + - name: Build ROCK + run: | + rockcraft pack + - name: Upload locally built ROCK artifact + uses: actions/upload-artifact@v3 + with: + name: valkey-rock + path: charmed-valkey_*_amd64.rock \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..70a42c6 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,55 @@ +name: Publish to GHCR + +env: + RELEASE: edge + +on: + push: + branches: + - main + +jobs: + build: + uses: ./.github/workflows/build.yaml + publish: + needs: build + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Docker + run: | + sudo snap install docker + sudo addgroup --system docker; sudo adduser $USER docker + newgrp docker + sudo snap disable docker; sudo snap enable docker + - name: Install skopeo + run: | + sudo snap install --devmode --channel edge skopeo + - name: Install yq + run: | + sudo snap install yq + - uses: actions/download-artifact@v3 + with: + name: valkey-rock + path: . + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USER }} + password: ${{ secrets.GHCR_TOKEN }} + - name: Import and push to GHCR + run: | + version=$(yq '(.version|split("-"))[0]' rockcraft.yaml) + rock_image_version=$(yq '(.version)' rockcraft.yaml) + base=$(yq '(.base|split("@"))[1]' rockcraft.yaml) + tag=${version}-${base}-${{ env.RELEASE }} + echo "Publishing charmed-valkey:${tag}" + sudo skopeo --insecure-policy copy \ + oci-archive:charmed-valkey_${rock_image_version}_amd64.rock \ + docker-daemon:ghcr.io/canonical/charmed-valkey:${tag} + docker push ghcr.io/canonical/charmed-valkey:${tag} \ No newline at end of file diff --git a/rockcraft.yaml b/rockcraft.yaml index 4180bd5..23bab64 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -17,7 +17,7 @@ platforms: # The platforms this ROCK should be built on and run on amd64: services: - redis: + valkey: override: replace startup: enabled summary: Start Valkey From 317a66f6b7307a7bdd88a5ae2a8967e7f5c01a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Radoi?= <103035318+reneradoi@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:59:18 +0200 Subject: [PATCH 05/11] Apply suggestions to README from code review Co-authored-by: Mehdi Bendriss --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4524ddd..fca2b9d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -Charmed Valkey rock +# Charmed Valkey rock This repository will contain the packaging metadata for creating a rock of Charmed Valkey built from Charmed Valkey Snap. -License +## License: The Charmed Valkey rock is free software, distributed under the Apache Software License, version 2.0. See licenses for more information. \ No newline at end of file From 4e904daead77930b62927414817d8b286439ba7a Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 12:11:02 +0000 Subject: [PATCH 06/11] improve README --- README.md | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fca2b9d..4eeb129 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,37 @@ # Charmed Valkey rock -This repository will contain the packaging metadata for creating a rock of Charmed Valkey built from Charmed Valkey -Snap. +[![Release to GHCR](https://github.com/canonical/charmed-valkey-rock/actions/workflows/release.yaml/badge.svg)](https://github.com/canonical/charmed-valkey-rock/actions/workflows/release.yaml) + +This repository contains the packaging metadata for creating a rock of Charmed Valkey built from Charmed Valkey +Snap. For more information on rocks, visit the [rockcraft Github](https://github.com/canonical/rockcraft). + +## Building the rock +The steps outlined below are based on the assumption that you are building the rock with the latest LTS of Ubuntu. +If you are using another version of Ubuntu or another operating system, the process may be different. + +### Clone Repository +```bash +git clone git@github.com:canonical/charmed-valkey-rock.git +cd charmed-valkey-rock +``` +### Installing Prerequisites +```bash +sudo snap install rockcraft --edge --classic +sudo snap install docker +sudo snap install lxd +sudo snap install skopeo --edge --devmode +``` +### Configuring Prerequisites +```bash +sudo usermod -aG docker $USER +sudo lxd init --auto +``` +*_NOTE:_* You will need to open a new shell for the group change to take effect (i.e. `su - $USER`) +### Packing and Running the rock +```bash +rockcraft pack +sudo skopeo --insecure-policy copy oci-archive:charmed-valkey*.rock docker-daemon:/charmed-valkey: +docker run --rm -it /charmed-valkey: +``` ## License: The Charmed Valkey rock is free software, distributed under the Apache Software License, version 2.0. See licenses for From 124e0aa0b79357afc613031e30f421431282e85f Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 13:18:20 +0000 Subject: [PATCH 07/11] run valkey as non-root user --- rockcraft.yaml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/rockcraft.yaml b/rockcraft.yaml index 23bab64..f92598e 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -21,23 +21,18 @@ services: override: replace startup: enabled summary: Start Valkey - command: "valkey-server" + command: "valkey-server --dir /var/lib/valkey" + user: valkey redis_exporter: override: replace startup: enabled summary: Start Metrics Exporter command: "/bin/redis_exporter" + user: valkey parts: - valkey-user: - plugin: nil - overlay-script: | - set -x - useradd -R $CRAFT_OVERLAY -M -U -r valkey valkey: plugin: nil - after: - - valkey-user stage-snaps: - charmed-valkey/latest/edge redis_exporter: @@ -48,4 +43,15 @@ parts: source-type: git source-branch: "v1.60.0" build-snaps: - - go/1.21/stable \ No newline at end of file + - go/1.21/stable + valkey-user: + plugin: nil + after: + - redis_exporter + overlay-script: | + set -x + useradd -R $CRAFT_OVERLAY -M -U -r valkey + override-prime: | + craftctl default + mkdir $CRAFT_PRIME/var/lib/valkey + chown valkey $CRAFT_PRIME/var/lib/valkey \ No newline at end of file From d13b1026ef6f82bb4ad69db5b3b0038a2357d232 Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 13:44:33 +0000 Subject: [PATCH 08/11] adjust parts order --- rockcraft.yaml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rockcraft.yaml b/rockcraft.yaml index f92598e..eef465c 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -31,8 +31,19 @@ services: user: valkey parts: + valkey-user: + plugin: nil + overlay-script: | + set -x + useradd -R $CRAFT_OVERLAY -M -U -r valkey + override-prime: | + craftctl default + mkdir $CRAFT_PRIME/var/lib/valkey + chown valkey $CRAFT_PRIME/var/lib/valkey valkey: plugin: nil + after: + - valkey-user stage-snaps: - charmed-valkey/latest/edge redis_exporter: @@ -43,15 +54,4 @@ parts: source-type: git source-branch: "v1.60.0" build-snaps: - - go/1.21/stable - valkey-user: - plugin: nil - after: - - redis_exporter - overlay-script: | - set -x - useradd -R $CRAFT_OVERLAY -M -U -r valkey - override-prime: | - craftctl default - mkdir $CRAFT_PRIME/var/lib/valkey - chown valkey $CRAFT_PRIME/var/lib/valkey \ No newline at end of file + - go/1.21/stable \ No newline at end of file From 33af4fd9430ac70a94e784d62c317d1a7ffc03b6 Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 13:55:40 +0000 Subject: [PATCH 09/11] move directory creation to valkey-part --- rockcraft.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rockcraft.yaml b/rockcraft.yaml index eef465c..f6ac8d5 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -36,16 +36,16 @@ parts: overlay-script: | set -x useradd -R $CRAFT_OVERLAY -M -U -r valkey - override-prime: | - craftctl default - mkdir $CRAFT_PRIME/var/lib/valkey - chown valkey $CRAFT_PRIME/var/lib/valkey valkey: plugin: nil after: - valkey-user stage-snaps: - charmed-valkey/latest/edge + override-prime: | + craftctl default + mkdir $CRAFT_PRIME/var/lib/valkey + chown valkey $CRAFT_PRIME/var/lib/valkey redis_exporter: plugin: go after: From 6874f38da070f00740bf230e41e0cab58e9a2147 Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 14:01:57 +0000 Subject: [PATCH 10/11] adjust directory creation --- rockcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rockcraft.yaml b/rockcraft.yaml index f6ac8d5..62d833d 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -45,7 +45,7 @@ parts: override-prime: | craftctl default mkdir $CRAFT_PRIME/var/lib/valkey - chown valkey $CRAFT_PRIME/var/lib/valkey + chmod 777 $CRAFT_PRIME/var/lib/valkey redis_exporter: plugin: go after: From 8c834511162f5cd7b26989e71e432c6e4e043aed Mon Sep 17 00:00:00 2001 From: reneradoi Date: Mon, 17 Jun 2024 14:41:55 +0000 Subject: [PATCH 11/11] fix directory creation --- rockcraft.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rockcraft.yaml b/rockcraft.yaml index 62d833d..5164fbc 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -31,25 +31,25 @@ services: user: valkey parts: - valkey-user: - plugin: nil - overlay-script: | - set -x - useradd -R $CRAFT_OVERLAY -M -U -r valkey valkey: plugin: nil - after: - - valkey-user stage-snaps: - charmed-valkey/latest/edge + valkey-user: + plugin: nil + after: + - valkey + overlay-script: | + # Create a user in the $CRAFT_OVERLAY chroot + groupadd -R $CRAFT_OVERLAY -g 584788 valkey + useradd -R $CRAFT_OVERLAY -M -r -g valkey -u 584788 valkey override-prime: | - craftctl default - mkdir $CRAFT_PRIME/var/lib/valkey - chmod 777 $CRAFT_PRIME/var/lib/valkey + mkdir -p $CRAFT_PRIME/var/lib/valkey + chown -R 584788:584788 $CRAFT_PRIME/var/lib/valkey redis_exporter: plugin: go after: - - valkey + - valkey-user source: https://github.com/canonical/redis_exporter.git source-type: git source-branch: "v1.60.0"