Skip to content

Commit

Permalink
Perform smoke tests on GHA/CI
Browse files Browse the repository at this point in the history
  • Loading branch information
danroux committed Apr 15, 2024
1 parent 0b668c7 commit f472f6f
Show file tree
Hide file tree
Showing 12 changed files with 1,261 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .changelog/28.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
gha/ci: Execute smoke tests on GHA/CI
```
100 changes: 87 additions & 13 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,109 @@
name: Build & Push images

on: workflow_dispatch
on:
pull_request:
workflow_dispatch:
workflow_call:
inputs:
image_tag:
required: true
type: string
# push:
# branches:
# - 'main'

permissions:
packages: write

jobs:
production-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
- name: Checkout - set env
run: echo "IMAGE_TAG=$(make version)" >> $GITHUB_ENV
-
name: Set up QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
- name: Build and push release version
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
if: ${{ github.event_name != 'pull_request' && github.event_name != 'workflow_call' && github.event_name != 'workflow_dispatch' }}
with:
context: .
file: production.dockerfile
push: true
tags: |
${{ vars.DOCKERHUB_SK8L_UI_IMAGE_NAME }}:latest
${{ vars.DOCKERHUB_SK8L_UI_IMAGE_NAME }}:${{ env.IMAGE_TAG }}
${{ vars.DOCKERHUB_SK8L_UI_IMAGE_NAME }}:latestx
${{ vars.DOCKERHUB_SK8L_UI_IMAGE_NAME }}:x-${{ env.IMAGE_TAG }}
sk8l-ui-dev-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
submodules: recursive
- name: Checkout - set env
run: echo "IMAGE_TAG=$(make version)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push dev version
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
if: ${{ github.event_name == 'workflow_call' && inputs.image_tag || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }}
with:
context: .
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:dev
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:dev-${{ github.event.pull_request.head.ref }}
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:dev-${{ github.event.pull_request.number }}
sk8l-ui-test-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
submodules: recursive
- name: Checkout - set env
run: echo "IMAGE_TAG=$(make version)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push test version
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
if: ${{ github.event_name == 'workflow_call' && inputs.image_tag || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }}
with:
context: .
file: Dockerfile.test
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:ui-test
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:ui-test-${{ github.event.pull_request.head.ref }}
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:ui-test-${{ github.event.pull_request.number }}
99 changes: 99 additions & 0 deletions .github/workflows/k8s-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: k8s-rwkld

on:
workflow_call:
inputs:
pull_request_number:
required: true
type: number
image_tag:
required: true
type: string
kind_version:
required: true
type: string
k8s_version:
required: true
type: string
k8s_image:
required: true
type: string
jobs:
k8s-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
submodules: recursive
# - name: Set up Go ${{ env.GO_VERSION }}
# uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
# with:
# go-version: ${{ env.GO_VERSION }}
# check-latest: false
# cache: false
# id: go
# - name: Update config files with dev docker image tag
# if:
# run: |
# pr_image_tag=${{ inputs.image_tag }}
# current_version=$(awk -F'"' '/\.Values\.sk8lApi\.imageTag/ {print $2}' charts/sk8l/templates/deployment.yaml)
# sed -i.bak -E "s/.Values.sk8lApi.imageTag \| default \"$current_version\"/.Values.sk8lApi.imageTag | default \"$pr_image_tag\"/" charts/sk8l/templates/deployment.yaml
# cp charts/sk8l/values.yaml charts/sk8l/values.yaml.bak
# yq e -i ".sk8lApi.imageTag = \"$current_version\"" charts/sk8l/values.yaml
# set +e
# echo "after"
# diff -C3 charts/sk8l/templates/deployment.yaml.bak charts/sk8l/templates/deployment.yaml
# diff -C3 charts/sk8l/values.yaml.bak charts/sk8l/values.yaml
# diff_status=$?
# set -e
# if [ $diff_status -eq 0 ]; then
# echo "No differences found between the files."
# exit 1
# fi
- name: Get testdata
run:
curl -o testdata/sk8l-kind.yml https://raw.githubusercontent.com/danroux/sk8l-api/main/testdata/sk8l-kind.yml
- name: Setup Kubernetes cluster ${{ inputs.kind_version }}/${{ inputs.k8s_version }}
uses: engineerd/setup-kind@v0.5.0
with:
name: sk8l
version: ${{ inputs.kind_version }}
image: ${{ inputs.k8s_image }}
config: testdata/sk8l-kind.yaml
- name: Test connection
run: |
kubectl cluster-info > /dev/null
kubectl describe node > /dev/null
- name: Install Helm
uses: azure/setup-helm@v4.1.0
with:
version: 'v3.13.3'
- name: Setup certs
run: |
make setup-certs > /dev/null
- name: Install Chart
run: |
make install-chart-ci > /dev/null
- name: smoke tests
id: smoke_tests
run: |
kubectl apply -f https://raw.githubusercontent.com/danroux/sk8l-api/main/testdata/sk8l-cronjobs.yml -n sk8l > /dev/null
kubectl wait -n sk8l --for=condition=ready pod -l app.kubernetes.io/pod=sk8l-ui --timeout=300s
sleep 60
kubectl apply -f testdata/cypress-job.yml -n sk8l
kubectl wait --for=condition=complete job.batch/cypress-job -n sk8l --timeout=600s
- name: /metrics smoke tests error output
if: ${{ failure() && steps.metrics_smoke_tests.conclusion == 'failure' }}
run: |
echo "----------------------------"
kubectl get pods -n sk8l
kubectl get cronjobs -n sk8l
echo "----------------------------"
cat current_state.txt
echo "----------------------------"
cat expected_output.txt
echo "----------------------------"
cat job_output.txt
exit 1
36 changes: 36 additions & 0 deletions .github/workflows/k8s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: k8s
on:
pull_request:
workflow_dispatch:

env:
GO_VERSION: "1.22.2"

permissions:
packages: write

jobs:
docker-img:
name: Build Docker image dev-${{ github.event.pull_request.number }}
uses: ./.github/workflows/docker.yml
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
with:
image_tag: dev-${{ github.event.pull_request.number }}
secrets: inherit
k8s-tests:
name: k8s ${{ matrix.k8s.version }}/pr#${{ github.event.pull_request.number }} tests
needs: [docker-img]
strategy:
matrix:
k8s:
- image: "kindest/node:v1.29.2@sha256:51a1434a5397193442f0be2a297b488b6c919ce8a3931be0ce822606ea5ca245"
version: v1.29.2
kind:
- version: "v0.22.0"
uses: ./.github/workflows/k8s-test.yml
with:
image_tag: dev-${{ github.event.pull_request.number }}
pull_request_number: ${{ github.event.pull_request.number }}
kind_version: ${{ matrix.kind.version }}
k8s_version: ${{ matrix.k8s.version }}
k8s_image: ${{ matrix.k8s.image }}
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ RUN mkdir -p $(pwd)/node_modules/.cache \
# # RUN yarn install --production

FROM alpine:3.19 AS release
LABEL org.opencontainers.image.source=https://github.com/danroux/sk8l-ui
LABEL org.opencontainers.image.description="sk8l-ui dev image"
LABEL org.opencontainers.image.licenses=MIT

ENV npm_config_cache=/usr/app/node_modules/.cache
ENV V 20.5.1
ENV FILE node-v$V-linux-x64-musl.tar.xz
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ghcr.io/danroux/sk8l-ui:dev AS release

FROM cypress/included:13.7.3
LABEL org.opencontainers.image.source=https://github.com/danroux/sk8l-ui
LABEL org.opencontainers.image.description="sk8l-ui ui-test image"
LABEL org.opencontainers.image.licenses=MIT

# USER 1001

# RUN chown -R 1001:1001 /var/cache
# COPY --chown=1001:1001 --from=release /usr/app ./e2e
COPY --from=release /usr/app ./e2e
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,35 @@ changelog-entry: ## changelog-entry
@changelog-entry -dir .changelog/

.PHONY: version changelog changelog-entry
setup-certs: # setup-certs
helm repo add jetstack https://charts.jetstack.io --force-update
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.4/cert-manager.crds.yaml
helm upgrade --install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace=true \
--version v1.14.4 \
--set prometheus.enabled=false \
--set extraArgs={--feature-gates=AdditionalCertificateOutputFormats=true} \
--set webhook.extraArgs={--feature-gates=AdditionalCertificateOutputFormats=true} \
--set webhook.timeoutSeconds=4
kubectl apply -f testdata/sk8l-cert-manager.yml
helm upgrade --install trust-manager jetstack/trust-manager \
--install \
--namespace cert-manager \
--set app.trust.namespace=sk8l \
--wait
kubectl apply -f testdata/sk8l-trust.yml

install-chart-ci: # install-chart-ci
helm repo add sk8l https://sk8l.io/charts
set +e; \
helm uninstall sk8l -n sk8l; \
kubectl get ns sk8l --ignore-not-found -o name | xargs -r kubectl wait --for=delete namespace/sk8l --timeout=120s; \
set -e
helm upgrade --install sk8l sk8l/sk8l \
-f https://raw.githubusercontent.com/danroux/sk8l-api/main/testdata/sk8l-values.yml \
--namespace sk8l \
--create-namespace=false \
--set namespace.create=false \
--set namespace.name=sk8l
24 changes: 24 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig } from 'cypress'

export default defineConfig({
clientCertificates: [
{
url: 'https://sk8l-ui',
ca: ['testdata/sk8l-certs/ca-cert.pem'],
certs: [
{
cert: 'testdata/sk8l-certs/server-cert.pem',
key: 'testdata/sk8l-certs/server-key.pem',
},
],
}
],
e2e: {
baseUrl: 'https://sk8l-ui:8001',
supportFile: false,
video: false,
specPattern: [
"cypress/**/*.spec.js"
]
}
})
9 changes: 9 additions & 0 deletions cypress/integration/sk8l.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Home Test', () => {
it('visits the homepage', () => {
cy.visit('https://sk8l-ui:8001/')
// cy.contains('It looks like no cronjobs exist for this namespace')
cy.contains('sk8l / download-report-files')
cy.contains('sk8l / process-csv-files')
cy.contains('sk8l / process-videos')
})
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "vite build",
"dev": "vite",
"test:unit": "./node_modules/.bin/vue-cli-service test:unit",
"test:e2e": "cypress run",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore",
"serveprod": "pm2 serve --no-daemon dist 1337"
},
Expand Down Expand Up @@ -34,6 +35,7 @@
"@vue/test-utils": "^2.0.0-0",
"@vue/vue3-jest": "^27.0.0-alpha.1",
"babel-jest": "^27.0.6",
"cypress": "^13.7.3",
"eslint": "^8.49.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.3",
Expand Down
4 changes: 4 additions & 0 deletions production.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ RUN yarn build
# RUN yarn add serve

FROM nginx:1.25.3-alpine3.18-slim as production-stage
LABEL org.opencontainers.image.source=https://github.com/danroux/sk8l-ui
LABEL org.opencontainers.image.description="sk8l-ui image"
LABEL org.opencontainers.image.licenses=MIT

WORKDIR /app

ENV APP_PORT 8001
Expand Down
Loading

0 comments on commit f472f6f

Please sign in to comment.