Skip to content

Cypress test

Cypress test #277

Workflow file for this run

name: Harbor Test Workflow
on:
pull_request:
types: [opened,reopened,synchronize,closed]
permissions:
contents: read
pull-requests: write
id-token: write
jobs:
# Job to build-push harbor-core image
build-harbor-core:
name: Build and Push `harbor-core` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Make versions dir
run: |
make compile
- name: Make harbor_core
run: |
make compile_core
- name: Generate UUID image name
id: uuid
run: echo "UUID_CORE=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_CORE }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
no-cache: true
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/core/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
# Job to build-push harbor-portal image
build-harbor-portal:
name: Build and Push `harbor-portal` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Generate UUID image name
id: uuid
run: echo "UUID_PORTAL=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_PORTAL }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/portal/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
- name: Echo image
run: echo ${{ steps.meta.outputs.images }}
# Job to build-push harbor-jobservice image
build-harbor-jobservice:
name: Build and Push `harbor-jobservice` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Make harbor_jobservice file
run: |
make compile
- name: Generate UUID image name
id: uuid
run: echo "UUID_JS=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_JS }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/jobservice/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
# Job to build-push harbor-registry image
build-harbor-registry:
name: Build and Push `harbor-registry` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Make registry file
run: |
make build -e BUILDTARGET="_build_registry"
- name: Generate UUID image name
id: uuid
run: echo "UUID_REG=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_REG }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/registry/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
# Job to build-push harbor-registryctl image
build-harbor-registryctl:
name: Build and Push `harbor-registryctl` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Make registry file
run: |
make build -e BUILDTARGET="_build_registry"
- name: Compile registryctl file
run: |
make compile_registryctl
- name: Generate UUID image name
id: uuid
run: echo "UUID_REGCTL=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_REGCTL }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/registryctl/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
build-harbor-db:
name: Build and Push `harbor-db` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Build DB
run: |
make build -e BUILDTARGET="_build_db"
- name: Generate UUID image name
id: uuid
run: echo "UUID_DB=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_DB }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
no-cache: true
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/db/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
build-harbor-redis:
name: Build and Push `harbor-redis` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
repository: goharbor/harbor
- name: Build DB
run: |
make build -e BUILDTARGET="_build_redis"
- name: Generate UUID image name
id: uuid
run: echo "UUID_RDS=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_RDS }}
tags: type=raw,value=60d
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
no-cache: true
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./make/photon/redis/Dockerfile
context: .
build-args: |
harbor_base_image_version=dev
harbor_base_namespace=goharbor
npm_registry=https://registry.npmjs.org
uffizzi-cluster:
name: Deploy to Uffizzi uCluster
outputs:
HARBOR_HOST: ${{ steps.ingress.outputs.HARBOR_HOST }}
needs:
- build-harbor-core
- build-harbor-portal
- build-harbor-jobservice
- build-harbor-registry
- build-harbor-registryctl
- build-harbor-db
- build-harbor-redis
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# Identify comment to be updated
- name: Find comment for Ephemeral Environment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: pr-${{ github.event.pull_request.number }}
direction: last
# Create/Update comment with action deployment status
- name: Create or Update Comment with Deployment Notification
uses: peter-evans/create-or-update-comment@v2
id: notification
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Uffizzi Ephemeral Environment - Virtual Cluster
:cloud: deploying ...
:gear: Updating now by workflow run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
Download the Uffizzi CLI to interact with the upcoming virtual cluster
https://docs.uffizzi.com/install
edit-mode: replace
# Create/Connect to Uffizzi Virtual Cluster
- name: Connect to Virtual Cluster
uses: UffizziCloud/cluster-action@main
with:
cluster-name: pr-${{ github.event.pull_request.number }}
server: https://app.qa-gke.uffizzi.com/
# Create/Update comment with action deployment status
- name: Create or Update Comment with Deployment URL
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.notification.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Uffizzi Ephemeral Environment - Virtual Cluster
Your cluster `pr-${{ github.event.pull_request.number }}` was successfully created. Learn more about [Uffizzi virtual clusters](https://docs.uffizzi.com/virtual-clusters)
To connect to this cluster, follow these steps:
1. Download and install the Uffizzi CLI from https://docs.uffizzi.com/install
2. Login to Uffizzi: `uffizzi login`
3. Update your kubeconfig: `uffizzi cluster update-kubeconfig pr-${{ github.event.pull_request.number }}`. This command will update your local `~/.kube/config`.
If you want to provide an alternate location follow the optional step (the next step) instead.
Optional: Update your kubeconfig: `uffizzi cluster update-kubeconfig pr-${{ github.event.pull_request.number }} --kubeconfig=[KUBECONFIG]`, replacing `[KUBECONFIG]` with the path to your kubeconfig file.
After updating your kubeconfig, you can manage your cluster with `kubectl`, `kustomize`, `helm`, and other tools that use kubeconfig files: `kubectl get namespace --kubeconfig [KUBECONFIG]`
edit-mode: replace
# Apply Harbor Helm Chart
- name: Apply Helm Chart
id: helm
run: |
export REPO_core=$(echo ${{ needs.build-harbor-core.outputs.tags }} | cut -f1 -d":")
export REPO_portal=$(echo ${{ needs.build-harbor-portal.outputs.tags }} | cut -f1 -d":")
export REPO_jobservice=$(echo ${{ needs.build-harbor-jobservice.outputs.tags }} | cut -f1 -d":")
export REPO_registry=$(echo ${{ needs.build-harbor-registry.outputs.tags }} | cut -f1 -d":")
export REPO_registryctl=$(echo ${{ needs.build-harbor-registryctl.outputs.tags }} | cut -f1 -d":")
export REPO_db=$(echo ${{ needs.build-harbor-db.outputs.tags }} | cut -f1 -d":")
export REPO_redis=$(echo ${{ needs.build-harbor-redis.outputs.tags }} | cut -f1 -d":")
yq eval ".expose.tls.certSource = \"none\"" -i values.yaml
yq eval ".core.image.repository = \"$REPO_core\"" -i values.yaml
yq eval ".core.image.tag |= \"60d\"" -i values.yaml
yq eval ".portal.image.repository = \"$REPO_portal\"" -i values.yaml
yq eval ".portal.image.tag |= \"60d\"" -i values.yaml
yq eval ".jobservice.image.repository = \"$REPO_jobservice\"" -i values.yaml
yq eval ".jobservice.image.tag |= \"60d\"" -i values.yaml
yq eval ".registry.registry.image.repository = \"$REPO_registry\"" -i values.yaml
yq eval ".registry.registry.image.tag |= \"60d\"" -i values.yaml
yq eval ".registry.controller.image.repository |= \"$REPO_registryctl\"" -i values.yaml
yq eval ".registry.controller.image.tag |= \"60d\"" -i values.yaml
yq eval ".database.internal.image.repository = \"$REPO_db\"" -i values.yaml
yq eval ".database.internal.image.tag |= \"60d\"" -i values.yaml
yq eval ".redis.internal.image.repository = \"$REPO_redis\"" -i values.yaml
yq eval ".redis.internal.image.tag |= \"60d\"" -i values.yaml
export KUBECONFIG="`pwd`/kubeconfig"
helm repo add harbor https://helm.goharbor.io
helm upgrade --install my-release harbor/harbor -f values.yaml
# Create ingress
- name: Create ingress
id: ingress
run: |
sleep 20
echo "HARBOR_HOST=$(kubectl get ingress my-release-harbor-ingress --kubeconfig kubeconfig -o json | jq '.spec.rules[0].host' | tr -d '"')" >> "$GITHUB_OUTPUT"
- name: Update Comment with Harbor URL
id: harbor_notify
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.notification.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
---
Please wait for several minutes for Harbor deployment to complete.
Then you should be able to visit the Harbor portal at https://${{ steps.ingress.outputs.HARBOR_HOST }}
Use credentials admin/Harbor12345 to login.
For more details, please visit https://github.com/goharbor/harbor
edit-mode: append
- name: Upload kubeconfig file
uses: actions/upload-artifact@v3
with:
name: kubeconfig
path: kubeconfig
- name: Update Harbor URL for Cypress
env:
HARBOR_HOST: ${{ steps.ingress.outputs.HARBOR_HOST }}
run: |
sed -i "s#harbor_url#https://${{ steps.ingress.outputs.HARBOR_HOST }}#g" cypress/cypress.config.js
testkube:
name: Run test on Harbor
needs:
- uffizzi-cluster
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download kubeconfig
uses: actions/download-artifact@v3
with:
name: kubeconfig
- name: Install Testkube helm chart
run: |
export KUBECONFIG="`pwd`/kubeconfig"
helm repo add kubeshop https://kubeshop.github.io/helm-charts
if $(helm ls | grep -q my-testkube); then
helm upgrade --install my-testkube kubeshop/testkube
else
helm install my-testkube kubeshop/testkube
fi
sleep 10
- name: Create Ingress for Testkube
id: test
run: |
if $(kubectl get ingress my-testkube-ingress --kubeconfig="`pwd`/kubeconfig" | grep -q "my-testkube-ingress"); then
kubectl delete ingress my-testkube-ingress --kubeconfig="`pwd`/kubeconfig"
fi
kubectl create ingress my-testkube-ingress --kubeconfig="`pwd`/kubeconfig" \
--rule="testkube.uclusters.app.uffizzi.com/*=testkube-dashboard:8080,tls"
if $(kubectl get ingress my-testkube-api-server --kubeconfig="`pwd`/kubeconfig" | grep -q "my-testkube-api-server"); then
kubectl delete ingress my-testkube-api-server --kubeconfig="`pwd`/kubeconfig"
fi
kubectl create ingress my-testkube-api-server --kubeconfig="`pwd`/kubeconfig" \
--rule="testkube-api-server.uclusters.app.uffizzi.com/*=testkube-api-server:8088,tls"
sleep 20
echo "API_SERVER=$(kubectl get ingress my-testkube-api-server --kubeconfig="`pwd`/kubeconfig" -o json | jq '.spec.rules[0].host' | tr -d '"')" >> "$GITHUB_OUTPUT"
echo "TK_DASHBOARD=$(kubectl get ingress my-testkube-ingress --kubeconfig="`pwd`/kubeconfig" -o json | jq '.spec.rules[0].host' | tr -d '"')" >> "$GITHUB_OUTPUT"
- shell: bash
env:
API_SERVER: ${{ steps.test.outputs.API_SERVER }}
run: |
export KUBECONFIG=`pwd`/kubeconfig
helm upgrade my-testkube kubeshop/testkube --set testkube-dashboard.apiServerEndpoint=${{ steps.test.outputs.API_SERVER }}
- name: Get test with Testkube
id: get_test
uses: kubeshop/testkube-docker-action@v1
with:
command: get
resource: test
api-uri: https://${{ steps.test.outputs.API_SERVER }}
parameters: "cypress-test"
- name: Create test with Testkube
id: create_test
if: always() && (steps.get_test.outcome == 'failure')
uses: kubeshop/testkube-docker-action@v1
env:
KUBECONFIG: kubeconfig
KUBERNETES_MASTER: kubeconfig
API_SERVER: ${{ steps.test.outputs.API_SERVER }}
with:
command: create
resource: test
api-uri: https://${{ steps.test.outputs.API_SERVER }}
parameters: "--name cypress-test --type cypress/project --test-content-type git-dir --git-uri https://github.com/UffizziCloud/harbor-test/ --git-branch testkube --git-path cypress/ --variable CYPRESS_BASE_URL=https://${{ needs.uffizzi-cluster.outputs.HARBOR_HOST }} --job-template job.yaml"
- name: Run test with Testkube
id: run_test
if: always()
uses: kubeshop/testkube-docker-action@v1
with:
command: run
resource: test
api-uri: https://${{ steps.test.outputs.API_SERVER }}
parameters: "cypress-test"
- name: Update comment with Testkube
if: always()
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ needs.uffizzi-cluster.harbor_notify.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
---
Check out Testkube at -- https://${{ steps.test.outputs.TK_DASHBOARD }}
edit-mode: append
# cypress-run:
# needs:
# - uffizzi-cluster
# name: Cypress run
# runs-on: ubuntu-22.04
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# path: 'cypress/'
# - name: Cypress run
# id: cypress
# uses: gopuman/cypress-github-action@feat/add-test-reults-output
# with:
# working-directory: cypress/cypress
# config-file: cypress.config.js
# build: npx cypress info
# config: baseUrl=https://${{ needs.uffizzi-cluster.outputs.HARBOR_HOST }}
# - name: Cypress output
# uses: actions/[email protected]
# with:
# script: |
# if (${{ steps.cypress.outputs.testResultsObject }} == "") {
# console.log('No test results found')
# return
# }
# const testResults = JSON.parse('${{ steps.cypress.outputs.testResultsObject }}')
# console.log("Success: " + testResults.success)
# console.log("TotalPassed: " + testResults.totalPassed)
# console.log("TotalFailed: " + testResults.totalFailed)
# console.log("TotalPending: " + testResults.totalPending)
# console.log("TotalSkipped: " + testResults.totalSkipped)
# console.log("TotalDuration: " + testResults.totalDuration)
# const headers = [
# { data: 'Result', header: true },
# { data: 'Passed :white_check_mark:', header: true },
# { data: 'Failed :x:', header: true },
# { data: 'Pending :hand:', header: true },
# { data: 'Skipped :leftwards_arrow_with_hook:', header: true },
# { data: 'Duration :clock8:', header: true }
# ]
# const status =
# testResults.totalFailed === 0
# ? 'Passing :white_check_mark:'
# : 'Failing :red_circle:'
# const summaryRows = [
# status,
# `${testResults.totalPassed}`,
# `${testResults.totalFailed}`,
# `${testResults.totalPending}`,
# `${testResults.totalSkipped}`,
# `${testResults.totalDuration / 1000}s` || ''
# ]
# const tableRows = [headers.map(h => h.data), summaryRows].map(row => '|' + row.join('|') + '|').join('\\n');
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body:`
# Here are the test results:
# | Result | Passed ✅ | Failed ❌ | Pending ✋ | Skipped ↩️ | Duration 🕗 |
# | -------------- | --------- | --------- | --------- | ---------- | ------------------ |
# | ${status} | ${testResults.totalPassed} | ${testResults.totalFailed} | ${testResults.totalPending} | ${testResults.totalSkipped} | ${testResults.totalDuration / 1000}s |
# `,
# })
uffizzi-cluster-delete:
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Delete Virtual Cluster
uses: UffizziCloud/cluster-action@main
with:
action: delete
cluster-name: pr-${{ github.event.pull_request.number }}
server: https://app.uffizzi.com/