Deploy Uffizzi Virtual Clusters (uClusters) for every pull request.
Similar to the concept of virtual machines, Uffizzi virtual clusters are virtualized instances of Kubernetes clusters running on top of a host cluster. Uffizzi virtual clusters provide all the same functionality of real Kubernetes clusters, while being more convenient and efficient.
Uffizzi integrates as a step in your GitHub Actions pipeline to manage on-demand, ephemeral test environments for every feature branch/pull request. Virtual Cluster Environments are deployed on Uffizzi Cloud (SaaS) or your own installation of Uffizzi Enterprise or open-source Uffizzi.
If you wish to use this action by itself outside of the reusable workflow described above, you can. The action can create or delete uClusters.
(Optional) https://app.uffizzi.com/
or the URL of your Uffizzi installation.
(Required) The name of the cluster spun up by the uffizzi cluster create
command.
(Optional) Uffizzi CLI Image. Default value is "uffizzi/cli:v2".
(Optional) Path to kubeconfig file.
(Optional) Specify whether to create or delete a cluster. Default value is "create".
(Optional) Version of the kubernetes cluster to be created. Only works with "create" action.
(Optional) Name of the kubeconfig file which is created
We've published a Reusable Workflow for your GitHub Actions. This can handle creating, updating, and deleting Uffizzi Ephemeral Cluster Environments. It will also publish instructions for connecting to your cluster in a comment to your pull requests.
- name: Create cluster
id: create-cluster
if: ${{ env.UFFIZZI_ACTION == 'create' }} || ${{ env.UFFIZZI_ACTION == 'update' }}
uses: UffizziCloud/cluster-action@reusable
with:
action: create
cluster-name: pr-$PR_NUMBER
k8s-manifest-file: ${{ inputs.k8s-manifest-cache-path }}
server: ${{ inputs.server }}
In this example, three images (vote
, result
, and worker
) are built and published to a temporary image registry exclusively for pull request events. The details of the built image is then updated within the Kubernetes manifest using Kustomize
. By following this process, the Uffizzi Cluster is created, and the Kubernetes manifests from the repository are applied.
For more information see Uffizzi Quickstart for K8s.
name: Uffizzi Cluster Example
on:
pull_request:
types: [opened,reopened,synchronize,closed]
permissions:
id-token: write
jobs:
build-vote:
name: Build and Push `vote`
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
- name: Generate UUID image name
id: uuid
run: echo "UUID_VOTE=$(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_VOTE }}
tags: type=raw,value=24h
- 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 }}
context: ./vote
build-worker:
name: Build and Push `worker`
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
- name: Generate UUID image name
id: uuid
run: echo "UUID_WORKER=$(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_WORKER }}
tags: type=raw,value=24h
- 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 }}
context: ./worker
build-result:
name: Build and Push `result`
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
- name: Generate UUID image name
id: uuid
run: echo "UUID_RESULT=$(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_RESULT }}
tags: type=raw,value=24h
- 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 }}
context: ./result
cluster-setup:
name: Setup ucluster
uses: UffizziCloud/cluster-action/.github/workflows/reusable.yaml@main
permissions:
contents: read
pull-requests: write
id-token: write
apply-manifests:
runs-on: ubuntu-latest
needs:
- build-vote
- build-worker
- build-result
- cluster-setup
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: my-artifact
- name: Kustomize and apply
run: |
kustomize edit set image vote-image=${{ needs.build-vote.outputs.tags }}
kustomize edit set image result-image=${{ needs.build-result.outputs.tags }}
kustomize edit set image worker-image=${{ needs.build-worker.outputs.tags }}
kustomize build . | kubectl apply --kubeconfig kubeconfig -f -
if kubectl get ingress vote-${{ github.event.number }} --kubeconfig kubeconfig >/dev/null 2>&1; then
echo "Ingress vote-${{ github.event.number }} already exists"
else
kubectl create ingress vote-${{ github.event.number }} \
--class=nginx \
--rule="pr-${{ github.event.number }}-vote.app.qa-gke.uffizzi.com/*=vote:5000" \
--kubeconfig kubeconfig
fi
if kubectl get ingress result-${{ github.event.number }} --kubeconfig kubeconfig >/dev/null 2>&1; then
echo "Ingress result-${{ github.event.number }} already exists"
else
kubectl create ingress result-${{ github.event.number }} \
--class=nginx \
--rule="pr-${{ github.event.number }}-result.app.qa-gke.uffizzi.com/*=result:5001" \
--kubeconfig kubeconfig
fi
echo "Access the vote endpoint at \`pr-${{ github.event.number }}-vote.app.qa-gke.uffizzi.com\`." | tee --append $GITHUB_STEP_SUMMARY
echo "Access the result endpoint at \`pr-${{ github.event.number }}-result.app.qa-gke.uffizzi.com\`." | tee --append $GITHUB_STEP_SUMMARY
(Optional) Uffizzi username for login, usually an email address.
(Optional) Uffizzi server URL. Default value is "https://app.uffizzi.com".
(Optional) Uffizzi project name. Default value is "default".
(Optional) GitHub Pull Request Number
(Optional) Branch or other git reference to checkout
(Optional) URL Path to the Uffizzi Cluster URL where healthcheck would be performed. The URL Path has to start with a '/'.
(Optional) Text string added to comment on pull request issue. Default value is "What is Uffizzi? Learn more".
(Optional) Custom environment for the deployed cluster. Default value is "uffizzi".
(Optional) Uffizzi CLI Image. Default value is "uffizzi/cli:v2".