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 16, 2024
1 parent 0b668c7 commit 181c11f
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 16 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
```
140 changes: 124 additions & 16 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,143 @@
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:
sk8l-ui-production-img:
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
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to Docker Hub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
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-img:
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@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to Docker Hub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
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-pre-img:
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@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to Docker Hub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
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: production.dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:pre
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:pre-${{ github.event.pull_request.head.ref }}
${{ vars.GHCR_SK8L_UI_IMAGE_NAME }}:pre-${{ github.event.pull_request.number }}
sk8l-ui-test-img:
runs-on: ubuntu-latest
name: sk8l-ui:ui-test-${{ github.event.pull_request.number }}
needs: [sk8l-ui-pre-img]
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@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to Docker Hub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
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 }}
71 changes: 71 additions & 0 deletions .github/workflows/k8s-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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: Setup Kubernetes cluster ${{ inputs.kind_version }}/${{ inputs.k8s_version }}
uses: engineerd/[email protected]
with:
name: sk8l
version: ${{ inputs.kind_version }}
image: ${{ inputs.k8s_image }}
config: testdata/sk8l-kind.yml
- name: Test connection
run: |
kubectl cluster-info > /dev/null
kubectl describe node > /dev/null
- name: Install Helm
uses: azure/[email protected]
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: ui smoke tests
id: ui_smoke_tests
run: |
./ci/ui_smoke_tests.sh
- name: ui smoke tests error output
if: ${{ failure() && steps.ui_smoke_tests.conclusion == 'failure' }}
run: |
echo "----------------------------"
kubectl get pods -n sk8l
kubectl get cronjobs -n sk8l
echo "----------------------------"
kubectl get jobs cypress-job -n sk8l
kubectl logs job.batch/cypress-job -n sk8l
echo "----------------------------"
curl -vvv http://0.0.0.0:9901/clusters
exit 1
- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-job-ss
path: cypress/sk8l.js/screenshots/
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 https://raw.githubusercontent.com/danroux/sk8l-api/main/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 https://raw.githubusercontent.com/danroux/sk8l-api/main/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 testdata/sk8l-values.yml \
--namespace sk8l \
--create-namespace=false \
--set namespace.create=false \
--set namespace.name=sk8l
17 changes: 17 additions & 0 deletions ci/ui_smoke_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

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 30
kubectl apply -f testdata/cypress-job.yml -n sk8l
kubectl wait --for=condition=complete job.batch/cypress-job -n sk8l --timeout=600s

failed=$(kubectl get jobs cypress-job -n sk8l -o jsonpath='{.status.failed}')
kubectl logs job.batch/cypress-job -n sk8l
if [[ "$failed" -gt 0 ]]; then
echo "Failed jobs found. Failing the step."
find cypress/ -type f
exit 1
fi
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"
]
}
})
Loading

0 comments on commit 181c11f

Please sign in to comment.