Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples with CI and simple e2e tests #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/scripts/ci-helm-install-and-test.sh

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/ci-verify-chart.yml
Original file line number Diff line number Diff line change
@@ -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' .
14 changes: 14 additions & 0 deletions .github/workflows/ci-verify-deployment-custom-admin.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions .github/workflows/ci-verify-deployment-mongodb-store.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions .github/workflows/ci-verify-deployment-web-proxy.yml
Original file line number Diff line number Diff line change
@@ -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
59 changes: 0 additions & 59 deletions .github/workflows/ci.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/helper-verify-deployment-reusable-workflow.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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!!!
Expand All @@ -193,6 +199,9 @@ cms:
customAdminSecret: cms-admin # mount `<Release name>-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:
Expand Down
9 changes: 9 additions & 0 deletions websight-cms/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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!!!
Expand All @@ -135,6 +141,9 @@ cms:
customAdminSecret: cms-admin # mount `<Release name>-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:
Expand Down
17 changes: 17 additions & 0 deletions websight-cms/examples/custom-admin/install-with-prerequisites.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions websight-cms/examples/custom-admin/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Example values for websight-cms with custom admin configuration

cms:
customAdminSecret: admin
10 changes: 10 additions & 0 deletions websight-cms/examples/custom-admin/verify.sh
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions websight-cms/examples/mongodb-store/install-with-prerequisites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
CMS_NAMESPACE=${1:-"websight"}

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
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
10 changes: 10 additions & 0 deletions websight-cms/examples/mongodb-store/values.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions websight-cms/examples/mongodb-store/verify.sh
Original file line number Diff line number Diff line change
@@ -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'
22 changes: 22 additions & 0 deletions websight-cms/examples/web-proxy/install-with-prerequisites.sh
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions websight-cms/examples/web-proxy/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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/assets/images.websight-assets-space-service.publish-assets.action \
-u ${CMS_USER}:${CMS_PASSWORD} \
-F "items=LUNA.svg" \
-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/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/published/luna/assets/images/LUNA.svg/jcr:content/renditions/original.svg)
if [ "$STATUS_CODE" -eq 200 ]; then
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 "Asset not available after $TOTAL_ATTEMPTS attempts"
exit 1
fi
sleep 5
done
Loading
Loading