From 084bb1b4e61aae152e8c42e5704df43784959f66 Mon Sep 17 00:00:00 2001 From: Bertrand THOMAS Date: Thu, 12 Sep 2024 08:51:14 +0200 Subject: [PATCH] Feature/Use container image and helm charts (#11) * Use new helm chart repo * Do not create a container image if only markdown was modified * Use new container image registry * Add static badge to application README * Cosmetic code changes * Rename go application module * Add missing quantifier in ci * Update PKG * Update CI --- .github/workflows/ci.yml | 6 ++-- .github/workflows/pkg.yml | 14 ++++----- README.md | 4 +-- charts/cow-demo/Chart.yaml | 2 +- charts/cow-demo/values.yaml | 4 +-- charts/game-2048/Chart.yaml | 2 +- charts/game-2048/values.yaml | 4 +-- scripts/kubernetes/certificate-management.sh | 14 ++++----- src/cow-demo/.gitignore | 1 + src/cow-demo/README.md | 30 +++++++++++--------- src/cow-demo/go.mod | 2 +- src/game-2048/README.md | 4 ++- src/rancher-helloworld/README.md | 4 ++- src/rancher-helloworld/go.mod | 2 +- src/rancher-helloworld/main.go | 2 +- 15 files changed, 49 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d94957..53553aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,9 +35,9 @@ jobs: with: base: ${{ github.ref }} filters: | - game-2048: src/game-2048/** - cow-demo: src/cow-demo/** - rancher-helloworld: src/rancher-helloworld/** + game-2048: src/game-2048/**/*.!(md) + cow-demo: src/cow-demo/**/*.!(md) + rancher-helloworld: src/rancher-helloworld/**/*.!(md) code-check: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/pkg.yml b/.github/workflows/pkg.yml index 42b0521..670ab0d 100644 --- a/.github/workflows/pkg.yml +++ b/.github/workflows/pkg.yml @@ -26,9 +26,9 @@ jobs: with: base: ${{ github.ref }} filters: | - game-2048: src/game-2048/** - cow-demo: src/cow-demo/** - rancher-helloworld: src/rancher-helloworld/** + game-2048: src/game-2048/**/*.!(md) + cow-demo: src/cow-demo/**/*.!(md) + rancher-helloworld: src/rancher-helloworld/**/*.!(md) build: if: ${{ github.ref_name == 'main' }} runs-on: ubuntu-latest @@ -51,8 +51,6 @@ jobs: helm repo update - name: Host charts repository on GitHub Pages uses: helm/chart-releaser-action@v1.6.0 - with: - skip_existing: true env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - name: Checkout gh-pages branch @@ -75,12 +73,12 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v1 deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} needs: build if: ${{ github.ref_name == 'main' }} runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} steps: - name: Deploy to GitHub Pages id: deployment diff --git a/README.md b/README.md index 78c2e0f..8f462c2 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Wether you're looking for simple way to automate an infrastructure or running de Download and source the files (targetting `develop` branch): ```bash -curl -sfL https://raw.githubusercontent.com/SUSE/lab-setup/develop/scripts/download.sh | GIT_REVISION=refs/heads/develop sh -s -- -o temp +curl -sfL https://raw.githubusercontent.com/SUSE/lab-setup/develop/scripts/download.sh | sh -s -- -o temp . temp/scripts/index.sh ``` @@ -49,7 +49,7 @@ Browse the [catalog of Helm charts](charts/README.md). Use the container images we provide for our demonstrations, for instance: ```bash -docker run --rm -p 8080:8080 ghcr.io/suse/cow-demo:1.0.10773428519 +docker run --rm -p 8080:8080 ghcr.io/suse/cow-demo ``` Open the [web application](http://localhost:8080/) and enjoy the live display! diff --git a/charts/cow-demo/Chart.yaml b/charts/cow-demo/Chart.yaml index c58f213..6a3e343 100644 --- a/charts/cow-demo/Chart.yaml +++ b/charts/cow-demo/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: cow-demo description: Helm chart for Cow Demo Application type: application -version: 0.1.1 +version: 0.1.2 appVersion: "2.0.0" home: https://github.com/SUSE/lab-setup/tree/main/charts/cow-demo maintainers: diff --git a/charts/cow-demo/values.yaml b/charts/cow-demo/values.yaml index 6267a01..8edee5e 100644 --- a/charts/cow-demo/values.yaml +++ b/charts/cow-demo/values.yaml @@ -1,6 +1,6 @@ name: cow-demo -image: devprofr/cow-demo -tag: 1.0.8830193847 +image: ghcr.io/suse/cow-demo +tag: 1.0.10775272363 replicaCount: 2 port: 80 ingress: diff --git a/charts/game-2048/Chart.yaml b/charts/game-2048/Chart.yaml index 9f76adf..a365c2c 100644 --- a/charts/game-2048/Chart.yaml +++ b/charts/game-2048/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: game-2048 description: Helm chart for Game 2048 type: application -version: 0.1.1 +version: 0.1.2 appVersion: "1.0.0" home: https://github.com/SUSE/lab-setup/tree/main/charts/game-2048 maintainers: diff --git a/charts/game-2048/values.yaml b/charts/game-2048/values.yaml index c25378f..66781ab 100644 --- a/charts/game-2048/values.yaml +++ b/charts/game-2048/values.yaml @@ -1,6 +1,6 @@ name: game-2048 -image: devprofr/game-2048 -tag: "1.0.8328752292" +image: ghcr.io/suse/game-2048 +tag: "1.0.10775272363" replicaCount: 1 port: 80 ingress: diff --git a/scripts/kubernetes/certificate-management.sh b/scripts/kubernetes/certificate-management.sh index 2d2643d..05325a2 100644 --- a/scripts/kubernetes/certificate-management.sh +++ b/scripts/kubernetes/certificate-management.sh @@ -17,8 +17,7 @@ k8s_install_certmanager() { kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${version}/cert-manager.crds.yaml helm upgrade --install cert-manager jetstack/cert-manager \ --namespace cert-manager --create-namespace \ - --version ${version} \ - 2>/dev/null + --version ${version} kubectl wait pods -n cert-manager -l app.kubernetes.io/instance=cert-manager --for condition=Ready 2>/dev/null } @@ -28,20 +27,19 @@ k8s_install_certmanager() { # Ingress class name (traefik, nginx, etc.) # administrator email address (to receive notifications for Let's Encrypt) # Examples: -# k8s_create_letsencryptclusterissuer traefik john.wick@google.com +# k8s_create_letsencryptclusterissuer traefik john.wick@thecontinental.hotel ####################################### k8s_create_letsencryptclusterissuer() { local ingressClassname=$1 local emailAddress=$2 echo "Creating certificate issuers using Let's Encrypt..." - # TODO move charts to this repository - helm repo add devpro https://devpro.github.io/helm-charts + helm repo add suse-lab-setup https://opensource.suse.com/lab-setup helm repo update - helm upgrade --install letsencrypt devpro/letsencrypt --namespace cert-manager \ + helm upgrade --install letsencrypt suse-lab-setup/letsencrypt \ + --namespace cert-manager \ --set ingress.className=${ingressClassname} \ - --set registration.emailAddress=${emailAddress} \ - 2>/dev/null + --set registration.emailAddress=${emailAddress} sleep 5 while kubectl get clusterissuers -o json | jq -e '.items[] | select(.status.conditions[] | select(.type == "Ready" and .status != "True"))' > /dev/null; do sleep 1 diff --git a/src/cow-demo/.gitignore b/src/cow-demo/.gitignore index 59425b7..d965a1c 100644 --- a/src/cow-demo/.gitignore +++ b/src/cow-demo/.gitignore @@ -1,2 +1,3 @@ # generated local binary cow-demo +cow-demo* diff --git a/src/cow-demo/README.md b/src/cow-demo/README.md index af8f4a4..fae9f77 100644 --- a/src/cow-demo/README.md +++ b/src/cow-demo/README.md @@ -1,5 +1,7 @@ # Cow Demo Application +[![Badge](https://badgen.net/static/Container%20Image/GitHub%20Packages/green)](https://github.com/SUSE/lab-setup/pkgs/container/cow-demo) + Cow Demo is a nice web application, written in Go, used for demonstrating Kubernetes and load balancing. 💡 This is a hard fork of [oskapt/rancher-demo](https://github.com/oskapt/rancher-demo) who hasn't been updated since 2021. @@ -11,6 +13,20 @@ It will create a colored icon for each replica within a ReplicaSet and indicate Replicas which haven't been heard from will begin to fade out, until after a configurable number of seconds they will disappear. This is useful for demonstrating scaling up/down an upgraded application. +## Quickstart with a container + +If you have a container engine running, you can start right away with the image: + +```bash +docker run --rm -p 8080:8080 ghcr.io/suse/cow-demo +``` + +Open the [web application](http://localhost:8080/) and enjoy the interactive display! + +## Deploy in an environment + +The recommanded way to run the application is to deploy in a Kubernetes cluster with with the [Helm chart](https://github.com/SUSE/lab-setup/tree/main/charts/cow-demo). + ## Configuration Environment variables: @@ -39,20 +55,6 @@ Environment variables: - chameleons - cowmeleons -## Quickstart with a container - -If you have a container engine running, you can start right away with the image: - -```bash -docker run --rm -p 8080:8080 ghcr.io/suse/cow-demo:1.0.10773428519 -``` - -Open the [web application](http://localhost:8080/) and enjoy the interactive display! - -## Deploy in an environment - -The recommanded way to run the application is to deploy in a Kubernetes cluster with with the [Helm chart](https://github.com/SUSE/lab-setup/tree/main/charts/cow-demo). - ## Local development ### How to test diff --git a/src/cow-demo/go.mod b/src/cow-demo/go.mod index aa44a85..3f92814 100644 --- a/src/cow-demo/go.mod +++ b/src/cow-demo/go.mod @@ -1,4 +1,4 @@ -module github.com/devpro/cow-demo +module github.com/suse/lab-setup/cow-demo go 1.22 diff --git a/src/game-2048/README.md b/src/game-2048/README.md index 6d450fe..097e00a 100644 --- a/src/game-2048/README.md +++ b/src/game-2048/README.md @@ -1,5 +1,7 @@ # 2048 game +[![Badge](https://badgen.net/static/Container%20Image/GitHub%20Packages/green)](https://github.com/SUSE/lab-setup/pkgs/container/game-2048) + Let's play 2048 game in a browser! 💡 This is a hard fork of [gabrielecirulli/2048](https://github.com/gabrielecirulli/2048) which hasn't been updated since 2017. @@ -9,7 +11,7 @@ Let's play 2048 game in a browser! If you have a container engine running, you can start right away with the image: ```bash -docker run --rm -p 8080:80 ghcr.io/suse/game-2048:1.0.10773428519 +docker run --rm -p 8080:80 ghcr.io/suse/game-2048 ``` Open the [web application](http://localhost:8080/) and enjoy the game! diff --git a/src/rancher-helloworld/README.md b/src/rancher-helloworld/README.md index f9f140b..d757f7a 100644 --- a/src/rancher-helloworld/README.md +++ b/src/rancher-helloworld/README.md @@ -1,5 +1,7 @@ # Rancher Hello World +[![Badge](https://badgen.net/static/Container%20Image/GitHub%20Packages/green)](https://github.com/SUSE/lab-setup/pkgs/container/rancher-helloworld) + This small web application is interesting as a first workload to install in a Kubernetes cluster. It shows data about hostname, services and request headers. 💡 This is a hard fork of [rancher/hello-world](https://github.com/rancher/hello-world) which hasn't been updated since 2018. @@ -9,7 +11,7 @@ This small web application is interesting as a first workload to install in a Ku If you have a container engine running, you can start right away with the image: ```bash -docker run --rm -p 8080:80 ghcr.io/suse/rancher-helloworld:1.0.10773428519 +docker run --rm -p 8080:80 ghcr.io/suse/rancher-helloworld ``` Open the [web application](http://localhost:8080/) and look at the information! diff --git a/src/rancher-helloworld/go.mod b/src/rancher-helloworld/go.mod index a7ec46d..e7f2e2d 100644 --- a/src/rancher-helloworld/go.mod +++ b/src/rancher-helloworld/go.mod @@ -1,3 +1,3 @@ -module github.com/devpro/rancher-helloworld +module github.com/suse/lab-setup/rancher-helloworld go 1.22 diff --git a/src/rancher-helloworld/main.go b/src/rancher-helloworld/main.go index 696ea71..5347a7c 100644 --- a/src/rancher-helloworld/main.go +++ b/src/rancher-helloworld/main.go @@ -7,7 +7,7 @@ import ( "regexp" "strings" - "github.com/devpro/rancher-helloworld/templates" + "github.com/suse/lab-setup/rancher-helloworld/templates" ) const defaultListenPort = "80"