Skip to content

Commit 2bdc002

Browse files
authored
feat (gha): add kind-localsetup workflow (#181)
* feat (gha): add kind-localsetup workflow --------- On-behalf-of: @SAP angel.kafazov@sap.com Signed-off-by: Angel Kafazov <akafazov@cst-bg.net>
1 parent 682806f commit 2bdc002

File tree

6 files changed

+221
-13
lines changed

6 files changed

+221
-13
lines changed
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Test local setup
2+
on:
3+
pull_request:
4+
branches:
5+
- '**'
6+
7+
concurrency:
8+
group: localsetup-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
kind-localsetup:
13+
runs-on: ubuntu-latest-large
14+
15+
steps:
16+
# Step 1: Checkout the code
17+
- uses: actions/checkout@v4
18+
19+
# Step 2: Install github cli
20+
- name: Install the gh cli
21+
uses: ksivamuthu/actions-setup-gh-cli@v3
22+
with:
23+
version: 2.24.3
24+
- run: |
25+
gh version
26+
27+
# Step 3: Run start.sh
28+
- name: Run start.sh
29+
id: run_start_sh
30+
env:
31+
# GH_TOKEN: ${{ steps.generate-token.outputs.token }}
32+
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
33+
GH_USER: ${{ github.repository_owner }}
34+
DEBUG: true
35+
run: |
36+
chmod +x ./local-setup/scripts/start.sh
37+
./local-setup/scripts/start.sh
38+
continue-on-error: true
39+
40+
- name: Debug
41+
if: steps.run_start_sh.outcome == 'failure'
42+
run: |
43+
set -x
44+
docker ps
45+
curl -s -i http://localhost:8000/ || true
46+
47+
kubectl get pods -A -o wide
48+
kubectl get svc -A
49+
kubectl get helmreleases -A
50+
kubectl get deployments -A
51+
kubectl get secrets -A
52+
kubectl get crds -A
53+
kubectl get nodes -o wide
54+
echo "Describe all pods which are not Running"
55+
kubectl get pods -A --field-selector=status.phase!=Running -o jsonpath='{range .items[*]}{.metadata.namespace} {.metadata.name}{"\n"}{end}' | while read namespace name; do kubectl describe pod $name -n $namespace; done
56+
echo "Describe all helmreleases which are not Ready yet"
57+
kubectl get helmreleases -A -o json | jq -r '.items[] | select(.status.conditions[]? | select(.type == "Ready" and .status != "True")) | "\(.metadata.namespace) \(.metadata.name)"' | while read namespace name; do kubectl describe helmrelease $name -n $namespace; done
58+
echo "Print imagePullSecret"
59+
kubectl get secret ghcr-credentials -n openmfp-system -o yaml
60+
echo "Test docker login and pull"
61+
docker login ghcr.io -u ${{ github.repository_owner }} -p ${{ steps.generate-token.outputs.token }}
62+
docker pull ghcr.io/openmfp/portal:0.287.0
63+
64+
65+
# Step 4: Prepare the NodeJS/playwright environment
66+
- name: Cache node modules
67+
uses: actions/cache@v3
68+
with:
69+
path: ~/node_modules
70+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
71+
restore-keys: |
72+
${{ runner.os }}-node-
73+
74+
# Step 5: Install NodeJS and dependencies
75+
- name: Node ${{ matrix.node-version }}
76+
uses: actions/setup-node@v3
77+
with:
78+
node-version: ${{ matrix.node-version }}
79+
cache: 'npm'
80+
cache-dependency-path: 'local-setup/e2e'
81+
82+
# Step 6: Install npm dependencies
83+
- name: Clean install of npm dependencies
84+
run: |
85+
cd local-setup/e2e
86+
npm install
87+
npm ci
88+
npx playwright install
89+
90+
# Step 7: Run the end-to-end tests
91+
- name: End2End tests
92+
run: |
93+
cd local-setup/e2e/
94+
npx playwright test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vscode/settings.json
33
.secret
44
bin/
5+
node_modules/

local-setup/e2e/package-lock.json

+72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

local-setup/e2e/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@playwright/test": "^1.49.1",
4+
"playwright": "^1.49.1"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import test, { expect } from '@playwright/test';
2+
3+
test.describe('Home Page', () => {
4+
test('Register and navigate to portal', async ({ page }) => {
5+
await page.goto('http://localhost:8000/');
6+
7+
// Interact with the page
8+
await page.click('text=Register');
9+
10+
// Fill in registration form
11+
await page.fill('input[name="email"]', 'username@sap.com');
12+
await page.fill('input[id="password"]', 'MyPass1234');
13+
await page.fill('input[id="password-confirm"]', 'MyPass1234');
14+
await page.fill('input[id="firstName"]', 'Firstname');
15+
await page.fill('input[id="lastName"]', 'Lastname');
16+
await page.click('input[value="Register"]');
17+
18+
await page.waitForURL('http://localhost:8000/home/overview', { timeout: 4000 }).then(() => {
19+
console.log('URL changed to /home/overview');
20+
});
21+
22+
const title = await page.title();
23+
expect(title).toBe('OpenMFP Portal');
24+
});
25+
26+
});

local-setup/scripts/start.sh

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
3+
DEBUG=${DEBUG:-false}
4+
5+
if [ "${DEBUG}" = "true" ]; then
6+
set -x
7+
fi
28

39
set -e
10+
411
COL='\033[92m'
512
RED='\033[91m'
613
COL_RES='\033[0m'
@@ -9,7 +16,7 @@ SCRIPT_DIR=$(dirname "$0")
916

1017
# Check for input argument GH_TOKEN and echo message in case not provided
1118
if [ -z "${GH_TOKEN}" ]; then
12-
echo "Please set the 'GITHUB_TOKEN' environment variable with a GitHub token that has 'read:packages' scope."
19+
echo "Please set the 'GH_TOKEN' environment variable with a GitHub token that has 'read:packages' scope."
1320
exit 1
1421
else
1522
ghToken=$GH_TOKEN
@@ -32,26 +39,26 @@ if [ $(kind get clusters | grep -c openmfp) -gt 0 ]; then
3239
echo -e "${COL}[$(date '+%H:%M:%S')] Kind cluster already running, using existing ${COL_RES}"
3340
kind export kubeconfig --name openmfp
3441
else
35-
echo "${COL}[$(date '+%H:%M:%S')] Creating kind cluster ${COL_RES}"
42+
echo -e "${COL}[$(date '+%H:%M:%S')] Creating kind cluster ${COL_RES}"
3643
kind create cluster --config $SCRIPT_DIR/../kind/kind-config.yaml --name openmfp --image=kindest/node:v1.30.2
3744
fi
3845

39-
echo "${COL}[$(date '+%H:%M:%S')] Installing flux ${COL_RES}"
46+
echo -e "${COL}[$(date '+%H:%M:%S')] Installing flux ${COL_RES}"
4047
helm upgrade -i -n flux-system --create-namespace flux oci://ghcr.io/fluxcd-community/charts/flux2 \
4148
--set imageAutomationController.create=false \
4249
--set imageReflectionController.create=false \
4350
--set kustomizeController.create=false \
4451
--set notificationController.create=false
4552

46-
echo "${COL}[$(date '+%H:%M:%S')] Starting deployments ${COL_RES}"
53+
echo -e "${COL}[$(date '+%H:%M:%S')] Starting deployments ${COL_RES}"
4754
kubectl apply -k $SCRIPT_DIR/../kustomize/overlays/default
4855

49-
echo "${COL}[$(date '+%H:%M:%S')] Creating necessary secrets ${COL_RES}"
56+
echo -e "${COL}[$(date '+%H:%M:%S')] Creating necessary secrets ${COL_RES}"
5057
kubectl create secret docker-registry ghcr-credentials -n openmfp-system --docker-server=ghcr.io --docker-username=$ghUser --docker-password=$ghToken --dry-run=client -o yaml | kubectl apply -f -
5158

5259
kubectl create secret generic keycloak-admin -n openmfp-system --from-literal=secret=admin --dry-run=client -o yaml | kubectl apply -f -
5360

54-
echo "${COL}[$(date '+%H:%M:%S')] Waiting for istio to become ready ${COL_RES}"
61+
echo -e "${COL}[$(date '+%H:%M:%S')] Waiting for istio to become ready ${COL_RES}"
5562
kubectl wait --namespace istio-system \
5663
--for=condition=Ready helmreleases \
5764
--timeout=120s istio-base
@@ -64,18 +71,20 @@ kubectl wait --namespace istio-system \
6471
--for=condition=Ready helmreleases \
6572
--timeout=120s istio-gateway
6673

67-
echo "${COL}[$(date '+%H:%M:%S')] Waiting for OpenMFP to become ready ${COL_RES} (this may take a few minutes)"
74+
echo -e "${COL}[$(date '+%H:%M:%S')] Waiting for OpenMFP CRDs to become ready ${COL_RES} (this may take a few minutes)"
6875

6976
kubectl wait --namespace openmfp-system \
7077
--for=condition=Ready helmreleases \
71-
--timeout=480s openmfp-crds
78+
--timeout=280s openmfp-crds
79+
80+
echo -e "$COL Waiting for OpenMFP to become ready $COL_RES (this may take a while)"
7281

7382
kubectl wait --namespace openmfp-system \
7483
--for=condition=Ready helmreleases \
7584
--timeout=480s openmfp
7685

77-
echo "${COL}-------------------------------------${COL_RES}"
78-
echo "${COL}[$(date '+%H:%M:%S')] Installation Complete ${RED}${COL}!${COL_RES}"
79-
echo "${COL}-------------------------------------${COL_RES}"
80-
echo "${COL}You can access the portal at: http://localhost:8000${COL_RES}"
86+
echo -e "${COL}-------------------------------------${COL_RES}"
87+
echo -e "${COL}[$(date '+%H:%M:%S')] Installation Complete ${RED}${COL}!${COL_RES}"
88+
echo -e "${COL}-------------------------------------${COL_RES}"
89+
echo -e "${COL}You can access the portal at: http://localhost:8000${COL_RES}"
8190
exit 0

0 commit comments

Comments
 (0)