From 075a5bb43955a5d7ec03ea323834d3450f913a66 Mon Sep 17 00:00:00 2001 From: Maciej Laskowski <19705838+malaskowski@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:02:51 +0200 Subject: [PATCH 1/3] examples with CI --- .github/scripts/ci-helm-install-and-test.sh | 13 ---- .github/workflows/ci-verify-chart.yml | 29 +++++++++ .../ci-verify-deployment-custom-admin.yml | 14 +++++ .../ci-verify-deployment-mongodb-store.yml | 14 +++++ .../ci-verify-deployment-web-proxy.yml | 14 +++++ .github/workflows/ci.yml | 59 ------------------- ...r-verify-deployment-reusable-workflow.yaml | 38 ++++++++++++ README.md | 9 +++ websight-cms/README.md.gotmpl | 9 +++ .../install-with-prerequisites.sh | 17 ++++++ .../examples/custom-admin/values.yaml | 4 ++ websight-cms/examples/custom-admin/verify.sh | 10 ++++ .../install-with-prerequisites.sh | 19 ++++++ .../examples/mongodb-store/values.yaml | 10 ++++ websight-cms/examples/mongodb-store/verify.sh | 10 ++++ .../web-proxy/install-with-prerequisites.sh | 22 +++++++ .../luna-site.conf.template | 0 .../{luna-proxy => web-proxy}/values.yaml | 0 websight-cms/examples/web-proxy/verify.sh | 45 ++++++++++++++ .../templates/tests/healthcheck-test.yaml | 15 +++++ 20 files changed, 279 insertions(+), 72 deletions(-) delete mode 100755 .github/scripts/ci-helm-install-and-test.sh create mode 100644 .github/workflows/ci-verify-chart.yml create mode 100644 .github/workflows/ci-verify-deployment-custom-admin.yml create mode 100644 .github/workflows/ci-verify-deployment-mongodb-store.yml create mode 100644 .github/workflows/ci-verify-deployment-web-proxy.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/helper-verify-deployment-reusable-workflow.yaml create mode 100755 websight-cms/examples/custom-admin/install-with-prerequisites.sh create mode 100644 websight-cms/examples/custom-admin/values.yaml create mode 100755 websight-cms/examples/custom-admin/verify.sh create mode 100755 websight-cms/examples/mongodb-store/install-with-prerequisites.sh create mode 100644 websight-cms/examples/mongodb-store/values.yaml create mode 100755 websight-cms/examples/mongodb-store/verify.sh create mode 100755 websight-cms/examples/web-proxy/install-with-prerequisites.sh rename websight-cms/examples/{luna-proxy => web-proxy}/luna-site.conf.template (100%) rename websight-cms/examples/{luna-proxy => web-proxy}/values.yaml (100%) create mode 100755 websight-cms/examples/web-proxy/verify.sh create mode 100644 websight-cms/templates/tests/healthcheck-test.yaml diff --git a/.github/scripts/ci-helm-install-and-test.sh b/.github/scripts/ci-helm-install-and-test.sh deleted file mode 100755 index 1be4495..0000000 --- a/.github/scripts/ci-helm-install-and-test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -x -e - -kubectl create namespace websight || true -kubectl -n websight delete secret websight-cms-admin || true -kubectl -n websight create secret generic websight-cms-admin --from-literal=WS_ADMIN_PASSWORD=pass4test - -cd websight-cms - -helm -n websight upgrade --install websight-cms . --set cms.customAdminSecret=admin --wait --timeout 600s - -helm -n websight test websight-cms diff --git a/.github/workflows/ci-verify-chart.yml b/.github/workflows/ci-verify-chart.yml new file mode 100644 index 0000000..5dfe21a --- /dev/null +++ b/.github/workflows/ci-verify-chart.yml @@ -0,0 +1,29 @@ +name: 'CI: verify chart' + +permissions: + id-token: write + +on: + pull_request: + push: + branches: + - main + +jobs: + verify-template: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: azure/setup-helm@v3 + with: + version: v3.13.2 + + - name: Test with template + run: helm template --output-dir generated mycms websight-cms + + - name: Run chart helm-unittest + run: | + cd websight-cms + helm plugin install https://github.com/helm-unittest/helm-unittest.git + helm unittest -f 'tests/unit/*.yaml' . diff --git a/.github/workflows/ci-verify-deployment-custom-admin.yml b/.github/workflows/ci-verify-deployment-custom-admin.yml new file mode 100644 index 0000000..8d538be --- /dev/null +++ b/.github/workflows/ci-verify-deployment-custom-admin.yml @@ -0,0 +1,14 @@ +name: 'CI: verify CMS with custom admin deployment' + +on: + pull_request: + push: + branches: + - main + +jobs: + verify-custom-admin-deployment: + uses: ./.github/workflows/helper-verify-deployment-reusable-workflow.yaml + secrets: inherit + with: + example: custom-admin diff --git a/.github/workflows/ci-verify-deployment-mongodb-store.yml b/.github/workflows/ci-verify-deployment-mongodb-store.yml new file mode 100644 index 0000000..85e1649 --- /dev/null +++ b/.github/workflows/ci-verify-deployment-mongodb-store.yml @@ -0,0 +1,14 @@ +name: 'CI: verify CMS with MongoDB store deployment' + +on: + pull_request: + push: + branches: + - main + +jobs: + verify-mongodb-store-deployment: + uses: ./.github/workflows/helper-verify-deployment-reusable-workflow.yaml + secrets: inherit + with: + example: mongodb-store diff --git a/.github/workflows/ci-verify-deployment-web-proxy.yml b/.github/workflows/ci-verify-deployment-web-proxy.yml new file mode 100644 index 0000000..7f93acb --- /dev/null +++ b/.github/workflows/ci-verify-deployment-web-proxy.yml @@ -0,0 +1,14 @@ +name: 'CI: verify CMS with web proxy deployment' + +on: + pull_request: + push: + branches: + - main + +jobs: + verify-web-proxy-deployment: + uses: ./.github/workflows/helper-verify-deployment-reusable-workflow.yaml + secrets: inherit + with: + example: web-proxy diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index e5e4577..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: 'CI: verify chart' - -permissions: - id-token: write - -on: - pull_request: - push: - branches: - - main - -jobs: - verify-template: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: azure/setup-helm@v3 - with: - version: v3.13.2 - - - name: Test with template - run: helm template --output-dir generated mycms websight-cms - - - name: Run chart helm-unittest - run: | - cd websight-cms - helm plugin install https://github.com/helm-unittest/helm-unittest.git - helm unittest -f 'tests/unit/*.yaml' . - - verify-chart-deployment: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: '1.21.6' - - - name: Setup Kind - run: go install sigs.k8s.io/kind@v0.20.0 - - - name: Create K8s cluster with Kind - run: kind create cluster --config .github/cluster/kind-cluster.yaml - - - uses: azure/setup-helm@v3 - with: - version: v3.13.2 - - - name: Install Nginx Ingress Controller - run: | - kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml - kubectl -n ingress-nginx rollout status deployment ingress-nginx-controller - - - name: Install WebSight CMS and verify deployment - run: .github/scripts/ci-helm-install-and-test.sh diff --git a/.github/workflows/helper-verify-deployment-reusable-workflow.yaml b/.github/workflows/helper-verify-deployment-reusable-workflow.yaml new file mode 100644 index 0000000..43bfa7a --- /dev/null +++ b/.github/workflows/helper-verify-deployment-reusable-workflow.yaml @@ -0,0 +1,38 @@ +name: 'Test: Verify WebSight CMS Helm chart installation' + +on: + workflow_call: + inputs: + example: + description: 'The example to run and test' + type: string + required: true + +jobs: + verify-chart-deployment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '1.21.6' + + - name: Setup Kind + run: go install sigs.k8s.io/kind@v0.20.0 + + - name: Create K8s cluster with Kind + run: kind create cluster --config .github/cluster/kind-cluster.yaml + + - uses: azure/setup-helm@v3 + with: + version: v3.13.2 + + - name: Install WebSight CMS example with prerequisites + run: websight-cms/examples/${{ inputs.example }}/install-with-prerequisites.sh + + - name: Verify installation + run: websight-cms/examples/${{ inputs.example }}/verify.sh diff --git a/README.md b/README.md index 660f2fb..7d826b8 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,9 @@ The command removes all the Kubernetes components associated with the chart and -n websight --create-namespace ``` +**Example:** +See the [mongodb-store](websight-cms/examples/mongodb-store) example `values.yaml` file for more details on how to run CMS with MongoDB as NodeStore. + #### Running CMS with Ngninx proxy To run CMS with Nginx proxy you need to enable it by setting `proxy.enabled` to `true`. @@ -170,6 +173,9 @@ To run the example, clone this repository and follow the steps below: CMS should start in 1-2 minutes. The information about available CMS Panel and Luna site should be printed. +**Example:** +See the [web-proxy](websight-cms/examples/web-proxy) example `values.yaml` file for more details on how to configure Nginx to proxy a particular CMS site. + #### Custom CMS admin username and password > Important!!! @@ -193,6 +199,9 @@ cms: customAdminSecret: cms-admin # mount `-cms-admin` secret for CMS pod and add value from `WS_ADMIN_PASSWORD` key as a secret file (this is how CMS reads custom password) ``` +**Example:** +See the [custom-admin](websight-cms/examples/custom-admin) example `values.yaml` file for more details on how to set custom CMS admin username and password. + ### Local development To run WebSight CMS locally with Kind, clone the repository and follow the steps below: diff --git a/websight-cms/README.md.gotmpl b/websight-cms/README.md.gotmpl index 507883c..bad2807 100644 --- a/websight-cms/README.md.gotmpl +++ b/websight-cms/README.md.gotmpl @@ -89,6 +89,9 @@ The command removes all the Kubernetes components associated with the chart and -n websight --create-namespace ``` +**Example:** +See the [mongodb-store](websight-cms/examples/mongodb-store) example `values.yaml` file for more details on how to run CMS with MongoDB as NodeStore. + #### Running CMS with Ngninx proxy To run CMS with Nginx proxy you need to enable it by setting `proxy.enabled` to `true`. @@ -112,6 +115,9 @@ To run the example, clone this repository and follow the steps below: CMS should start in 1-2 minutes. The information about available CMS Panel and Luna site should be printed. +**Example:** +See the [web-proxy](websight-cms/examples/web-proxy) example `values.yaml` file for more details on how to configure Nginx to proxy a particular CMS site. + #### Custom CMS admin username and password > Important!!! @@ -135,6 +141,9 @@ cms: customAdminSecret: cms-admin # mount `-cms-admin` secret for CMS pod and add value from `WS_ADMIN_PASSWORD` key as a secret file (this is how CMS reads custom password) ``` +**Example:** +See the [custom-admin](websight-cms/examples/custom-admin) example `values.yaml` file for more details on how to set custom CMS admin username and password. + ### Local development To run WebSight CMS locally with Kind, clone the repository and follow the steps below: diff --git a/websight-cms/examples/custom-admin/install-with-prerequisites.sh b/websight-cms/examples/custom-admin/install-with-prerequisites.sh new file mode 100755 index 0000000..6e849c6 --- /dev/null +++ b/websight-cms/examples/custom-admin/install-with-prerequisites.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +CMS_NAMESPACE=${1:-"websight"} + +echo "Installing WebSight CMS with prerequisites in: $CMS_NAMESPACE" + +set -x -e + +# Create namespace and secret with admin password +kubectl create namespace $CMS_NAMESPACE || true +kubectl -n $CMS_NAMESPACE delete secret websight-cms-admin || true +kubectl -n $CMS_NAMESPACE create secret generic websight-cms-admin --from-literal=WS_ADMIN_PASSWORD=pass4test + +cd websight-cms +helm -n $CMS_NAMESPACE upgrade --install websight-cms . \ + -f examples/custom-admin/values.yaml \ + --wait --timeout 600s diff --git a/websight-cms/examples/custom-admin/values.yaml b/websight-cms/examples/custom-admin/values.yaml new file mode 100644 index 0000000..4f3776a --- /dev/null +++ b/websight-cms/examples/custom-admin/values.yaml @@ -0,0 +1,4 @@ +# Example values for websight-cms with custom admin configuration + +cms: + customAdminSecret: admin diff --git a/websight-cms/examples/custom-admin/verify.sh b/websight-cms/examples/custom-admin/verify.sh new file mode 100755 index 0000000..4dceaa6 --- /dev/null +++ b/websight-cms/examples/custom-admin/verify.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +CMS_NAMESPACE=${1:-"websight"} + +echo "Testing WebSight CMS in: $CMS_NAMESPACE" + +set -x -e + +cd websight-cms +helm -n $CMS_NAMESPACE test websight-cms diff --git a/websight-cms/examples/mongodb-store/install-with-prerequisites.sh b/websight-cms/examples/mongodb-store/install-with-prerequisites.sh new file mode 100755 index 0000000..1a8be2e --- /dev/null +++ b/websight-cms/examples/mongodb-store/install-with-prerequisites.sh @@ -0,0 +1,19 @@ +#!/bin/bash +CMS_NAMESPACE=${1:-"websight"} + +set -x -e + +# Install and expose MongoDB +kubectl create namespace mongo +kubectl -n mongo run mongodb --image=mongo:7 \ + --env MONGO_INITDB_ROOT_USERNAME=mongoadmin \ + --env MONGO_INITDB_ROOT_PASSWORD=mongoadmin +kubectl -n mongo expose pod mongodb --port=27017 --name=mongodb + +# Wait for mongo pod to be ready +kubectl -n mongo wait --for=condition=ready pod --all --timeout=300s + +cd websight-cms +helm -n $CMS_NAMESPACE upgrade --install websight-cms . \ + -f examples/mongodb-store/values.yaml \ + --wait --timeout 600s --create-namespace diff --git a/websight-cms/examples/mongodb-store/values.yaml b/websight-cms/examples/mongodb-store/values.yaml new file mode 100644 index 0000000..68f6c1f --- /dev/null +++ b/websight-cms/examples/mongodb-store/values.yaml @@ -0,0 +1,10 @@ +# Example values for websight-cms with MongoDB persistence mode + +cms: + persistence: + mode: mongo + mongo: + hosts: mongodb.mongo:27017 + livelinessProbe: + # give more time to start with MongoDB + initialDelaySeconds: 60 diff --git a/websight-cms/examples/mongodb-store/verify.sh b/websight-cms/examples/mongodb-store/verify.sh new file mode 100755 index 0000000..2623016 --- /dev/null +++ b/websight-cms/examples/mongodb-store/verify.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +CMS_NAMESPACE=${1:-"websight"} + +echo "Testing WebSight CMS in: $CMS_NAMESPACE" + +set -x -e + +cd websight-cms +helm -n $CMS_NAMESPACE test websight-cms --filter 'name=healthcheck' diff --git a/websight-cms/examples/web-proxy/install-with-prerequisites.sh b/websight-cms/examples/web-proxy/install-with-prerequisites.sh new file mode 100755 index 0000000..1c01e85 --- /dev/null +++ b/websight-cms/examples/web-proxy/install-with-prerequisites.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +CMS_NAMESPACE=${1:-"websight"} + +echo "Installing WebSight CMS with prerequisites in: $CMS_NAMESPACE" + +set -x -e + +# Install Kind-dedicated NgInx Ingress Controller and wait until it's ready +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml +kubectl -n ingress-nginx rollout status deployment ingress-nginx-controller + +# Create namespace and configure Nginx proxy via ConfigMap +kubectl create namespace $CMS_NAMESPACE || true + +cd websight-cms +kubectl -n $CMS_NAMESPACE create configmap luna-site-config \ + --from-file=examples/web-proxy/luna-site.conf.template + +helm -n $CMS_NAMESPACE upgrade --install websight-cms . \ + -f examples/web-proxy/values.yaml \ + --wait --timeout 600s diff --git a/websight-cms/examples/luna-proxy/luna-site.conf.template b/websight-cms/examples/web-proxy/luna-site.conf.template similarity index 100% rename from websight-cms/examples/luna-proxy/luna-site.conf.template rename to websight-cms/examples/web-proxy/luna-site.conf.template diff --git a/websight-cms/examples/luna-proxy/values.yaml b/websight-cms/examples/web-proxy/values.yaml similarity index 100% rename from websight-cms/examples/luna-proxy/values.yaml rename to websight-cms/examples/web-proxy/values.yaml diff --git a/websight-cms/examples/web-proxy/verify.sh b/websight-cms/examples/web-proxy/verify.sh new file mode 100755 index 0000000..deeab8f --- /dev/null +++ b/websight-cms/examples/web-proxy/verify.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +CMS_NAMESPACE=${1:-"websight"} +CMS_USER=${2:-"wsadmin"} +CMS_PASSWORD=${3:-"wsadmin"} + +echo "Testing WebSight CMS in: $CMS_NAMESPACE" + +set -x -e + +# Publish Luna Homepage +RESPONSE=$(curl -X POST http://cms.127.0.0.1.nip.io/content/luna/pages.websight-pages-space-service.publish-pages.action \ + -u ${CMS_USER}:${CMS_PASSWORD} \ + -F "forceAction=false" \ + -F "publishAllReferences=false" \ + -F "items=Homepage" \ + -H "accept: application/json" \ + -H "Content-Type: multipart/form-data") + +echo "$RESPONSE" | jq +PUBLICATION_STATUS=$(echo "$RESPONSE" | jq -r '.status') + +if [ "$PUBLICATION_STATUS" == "SUCCESS" ]; then + echo "Publication successful" +else + echo "Failed to publish /content/luna/pages/Homepage" + exit 1 +fi + +# Check http://luna.127.0.0.1.nip.io/ up to 10 times until 200 returned +TOTAL_ATTEMPTS=10 +for i in $(seq 1 $TOTAL_ATTEMPTS); do + STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://luna.127.0.0.1.nip.io/test.html) + if [ "$STATUS_CODE" -eq 200 ]; then + echo "Page http://luna.127.0.0.1.nip.io/homepage.html is up and running" + break + else + echo "Attempt ${i}/${TOTAL_ATTEMPTS}: Expected 200, got $STATUS_CODE" + fi + if [ "$i" == "${TOTAL_ATTEMPTS}" ]; then + echo "Page not available after $TOTAL_ATTEMPTS attempts" + exit 1 + fi + sleep 5 +done diff --git a/websight-cms/templates/tests/healthcheck-test.yaml b/websight-cms/templates/tests/healthcheck-test.yaml new file mode 100644 index 0000000..72793e8 --- /dev/null +++ b/websight-cms/templates/tests/healthcheck-test.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: healthcheck + annotations: + "helm.sh/hook": test + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + restartPolicy: Never + containers: + - name: job-test-cms-healthcheck + image: curlimages/curl:8.4.0 + command: [ 'sh', '-c'] + args: + - "curl -f http://websight-cms-cms:8080/system/health" From 924f0e39f2559e56111803166b0dfccabaeabafd Mon Sep 17 00:00:00 2001 From: Maciej Laskowski <19705838+malaskowski@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:09:35 +0200 Subject: [PATCH 2/3] wait for mongodb sa --- .../examples/mongodb-store/install-with-prerequisites.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/websight-cms/examples/mongodb-store/install-with-prerequisites.sh b/websight-cms/examples/mongodb-store/install-with-prerequisites.sh index 1a8be2e..c232272 100755 --- a/websight-cms/examples/mongodb-store/install-with-prerequisites.sh +++ b/websight-cms/examples/mongodb-store/install-with-prerequisites.sh @@ -5,6 +5,9 @@ set -x -e # Install and expose MongoDB kubectl create namespace mongo + +kubectl -n mongo create serviceaccount default || true + kubectl -n mongo run mongodb --image=mongo:7 \ --env MONGO_INITDB_ROOT_USERNAME=mongoadmin \ --env MONGO_INITDB_ROOT_PASSWORD=mongoadmin From dc9ab925cbcc81469b89a02bc999c9c63bc01ca9 Mon Sep 17 00:00:00 2001 From: Maciej Laskowski <19705838+malaskowski@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:26:57 +0200 Subject: [PATCH 3/3] verify asset instead of page due to unpublished references --- websight-cms/examples/web-proxy/verify.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/websight-cms/examples/web-proxy/verify.sh b/websight-cms/examples/web-proxy/verify.sh index deeab8f..6e72c4e 100755 --- a/websight-cms/examples/web-proxy/verify.sh +++ b/websight-cms/examples/web-proxy/verify.sh @@ -9,11 +9,9 @@ echo "Testing WebSight CMS in: $CMS_NAMESPACE" set -x -e # Publish Luna Homepage -RESPONSE=$(curl -X POST http://cms.127.0.0.1.nip.io/content/luna/pages.websight-pages-space-service.publish-pages.action \ +RESPONSE=$(curl -X POST http://cms.127.0.0.1.nip.io/content/luna/assets/images.websight-assets-space-service.publish-assets.action \ -u ${CMS_USER}:${CMS_PASSWORD} \ - -F "forceAction=false" \ - -F "publishAllReferences=false" \ - -F "items=Homepage" \ + -F "items=LUNA.svg" \ -H "accept: application/json" \ -H "Content-Type: multipart/form-data") @@ -27,18 +25,18 @@ else exit 1 fi -# Check http://luna.127.0.0.1.nip.io/ up to 10 times until 200 returned +# Check http://luna.127.0.0.1.nip.io/published/luna/assets/images/LUNA.svg/jcr:content/renditions/original.svg up to 10 times until 200 returned TOTAL_ATTEMPTS=10 for i in $(seq 1 $TOTAL_ATTEMPTS); do - STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://luna.127.0.0.1.nip.io/test.html) + STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://luna.127.0.0.1.nip.io/published/luna/assets/images/LUNA.svg/jcr:content/renditions/original.svg) if [ "$STATUS_CODE" -eq 200 ]; then - echo "Page http://luna.127.0.0.1.nip.io/homepage.html is up and running" + echo "Asset LUNA.svg is pubilc!" break else echo "Attempt ${i}/${TOTAL_ATTEMPTS}: Expected 200, got $STATUS_CODE" fi if [ "$i" == "${TOTAL_ATTEMPTS}" ]; then - echo "Page not available after $TOTAL_ATTEMPTS attempts" + echo "Asset not available after $TOTAL_ATTEMPTS attempts" exit 1 fi sleep 5