From 9f3138f08440a6d69d2a115883ae07f9b660acd3 Mon Sep 17 00:00:00 2001 From: Manuel Fragner Date: Thu, 17 Aug 2023 16:11:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20ci:=20Implement=20test=20pipelin?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-images.yaml | 30 ---------- .github/workflows/test.yaml | 55 +++++++++++++++++++ .../tests/test-frontend-connection.yaml | 22 ++++++++ chart/values.yaml | 36 ++++++------ src/user-simulator/Dockerfile | 2 +- 5 files changed, 96 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/build-images.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 chart/templates/tests/test-frontend-connection.yaml diff --git a/.github/workflows/build-images.yaml b/.github/workflows/build-images.yaml deleted file mode 100644 index 9706b962..00000000 --- a/.github/workflows/build-images.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: Build on PR -on: - pull_request: - paths: - - src/** - - k8s-manifests - - .github/workflows/build-images.yaml -jobs: - build: - name: Skaffold Build - runs-on: ubuntu-22.04 - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - - name: Cache layers - uses: actions/cache@v3 - with: - path: "${{ github.workspace }}/.skaffold/cache" - key: skaffold-${{ hashFiles('**/cache') }} - restore-keys: | - skaffold- - - - name: Run Skaffold build pipeline - uses: hiberbee/github-action-skaffold@1.26.0 - id: build - with: - command: build - skip-tests: true - push: false diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..b4d00271 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,55 @@ +name: Run Skaffold Pipeline, Deploy to Minikube Cluster and run Unguard Helm Test +on: + pull_request: + paths: + - src/** + - skaffold.yaml + - chart/** + +jobs: + lint-build-run-test-unguard: + runs-on: ubuntu-22.04 + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Set up Helm + uses: azure/setup-helm@v3.5 + with: + version: v3.12.3 + + - name: Kubectl tool installer + uses: Azure/setup-kubectl@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + check-latest: true + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + + - name: Run chart-testing (lint) + run: ct lint --chart-dirs . --charts ./chart --validate-maintainers=false --check-version-increment=false --target-branch ${{ github.event.repository.default_branch }} + + - name: Set up Minikube + uses: medyagh/setup-minikube@v0.0.14 + with: + addons: ingress + + - name: Cache Skaffold layers + uses: actions/cache@v3 + with: + path: ~/.skaffold/ + key: fixed-${{ github.sha }} + + - name: Run Skaffold and Deploy to Minikube Cluster + uses: hiberbee/github-action-skaffold@1.27.0 + with: + command: run + skip-tests: true + + - name: Run chart-testing + run: helm test unguard --namespace unguard --timeout 10m0s --logs diff --git a/chart/templates/tests/test-frontend-connection.yaml b/chart/templates/tests/test-frontend-connection.yaml new file mode 100644 index 00000000..6cd19175 --- /dev/null +++ b/chart/templates/tests/test-frontend-connection.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Pod +metadata: + name: unguard-frontend-connection + labels: + app.kubernetes.io/name: unguard-frontend-connection + app.kubernetes.io/part-of: unguard + annotations: + "helm.sh/hook": test +spec: + containers: + - name: unguard-{{.Values.userSimulator.name}} + image: {{.Values.userSimulator.cronJob.jobTemplate.container.image.repository}}:{{.Values.userSimulator.cronJob.jobTemplate.container.image.tag}} + imagePullPolicy: {{.Values.userSimulator.cronJob.jobTemplate.container.image.pullPolicy}} + env: + - name: FRONTEND_ADDR + value: {{quote .Values.userSimulator.cronJob.jobTemplate.container.env.FRONTEND_ADDR}} + - name: SIMULATE_PRIVATE_RANGES + value: {{quote .Values.userSimulator.cronJob.jobTemplate.container.env.SIMULATE_PRIVATE_RANGES}} + command: ["/bin/sh"] + args: ["-c", "node_modules/.bin/element run default-user-sim.perf.ts --export 2>&1 && jq -e '.testScripts[].iterationResults[].stepResults[] | select(.status == \"failed\") | .name' reports/default-user-sim.perf/*/data.json >/dev/null && exit 1 || exit 0"] + restartPolicy: Never diff --git a/chart/values.yaml b/chart/values.yaml index cff94725..572890ed 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -178,7 +178,7 @@ userAuthService: secretKeyRef: name: "{{ .Values.mariaDB.serviceName }}" key: "{{ .Values.mariaDB.password }}" - JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment + JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment JAEGER_SAMPLER_TYPE: const JAEGER_SAMPLER_PARAM: 0 JAEGER_DISABLED: true @@ -207,7 +207,7 @@ adService: ports: containerPort: 8082 env: - JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment + JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment JAEGER_SAMPLER_TYPE: const JAEGER_SAMPLER_PARAM: 0 JAEGER_DISABLED: true @@ -266,7 +266,7 @@ microblogService: containerPort: 8080 env: SERVER_PORT: 8080 - JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment + JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment JAEGER_SAMPLER_TYPE: const JAEGER_SAMPLER_PARAM: 0 OPENTRACING_JAEGER_ENABLED: false @@ -289,12 +289,12 @@ statusService: role: name: status-role rules: - - apiGroups: [ "apps" ] - resources: [ "deployments" ] - verbs: [ "get", "list" ] - - apiGroups: [ "" ] - resources: [ "pods" ] - verbs: [ "get", "list" ] + - apiGroups: ["apps"] + resources: ["deployments"] + verbs: ["get", "list"] + - apiGroups: [""] + resources: ["pods"] + verbs: ["get", "list"] roleBindings: name: status-rolebinding @@ -321,7 +321,7 @@ statusService: SERVER_PORT: 8083 API_PATH: /status-service KUBERNETES_NAMESPACE: unguard - IGNORED_DEPLOYMENTS: unguard-user-simulator # add deployments to ignore separated by spaces + IGNORED_DEPLOYMENTS: unguard-user-simulator # add deployments to ignore separated by spaces MARIADB_SERVICE: "{{ .Values.mariaDB.serviceName }}" MARIADB_PASSWORD: secretKeyRef: @@ -344,12 +344,12 @@ proxyService: role: name: proxy-role rules: - - apiGroups: [ "" ] # "" indicates the core API group - resources: [ "pods" ] - verbs: [ "create", "list", "get" ] - - apiGroups: [ "" ] - resources: [ "pods/exec" ] - verbs: [ "create" ] + - apiGroups: [""] # "" indicates the core API group + resources: ["pods"] + verbs: ["create", "list", "get"] + - apiGroups: [""] + resources: ["pods/exec"] + verbs: ["create"] roleBindings: name: proxy-rolebinding @@ -374,7 +374,7 @@ proxyService: containerPort: 8081 env: SERVER_PORT: 8081 - JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment + JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment JAEGER_SAMPLER_TYPE: const JAEGER_SAMPLER_PARAM: 0 OPENTRACING_JAEGER_ENABLED: false @@ -400,7 +400,7 @@ frontend: ports: containerPort: 3000 env: - JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment + JAEGER_AGENT_HOST: agent # change depending on your jaeger deployment JAEGER_SAMPLER_TYPE: const JAEGER_SAMPLER_PARAM: 0 JAEGER_DISABLED: true diff --git a/src/user-simulator/Dockerfile b/src/user-simulator/Dockerfile index 67f1b12b..7044d1e8 100644 --- a/src/user-simulator/Dockerfile +++ b/src/user-simulator/Dockerfile @@ -8,7 +8,7 @@ RUN apt-get update \ && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ && apt-get update \ - && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 libxshmfence1 \ + && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 libxshmfence1 jq \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/*