Skip to content

Try Uffizzi

Try Uffizzi #163

Workflow file for this run

name: Uffizzi Cluster Quickstart
on:
pull_request:
types: [opened,reopened,synchronize,closed]
permissions:
contents: read
pull-requests: write
id-token: write
jobs:
# Job to build-push vote image
build-vote:
name: Build and Push `vote` 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
- 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
# Job to build-push worker image
build-worker:
name: Build and Push `worker` 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
- 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
# Job to build-push result image
build-result:
name: Build and Push `result` 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
- 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
uffizzi-cluster:
name: Deploy to Uffizzi Virtual Cluster
needs:
- build-vote
- build-worker
- build-result
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
id: notification
uses: peter-evans/create-or-update-comment@v2
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
- name: Connect to Virtual Cluster
uses: UffizziCloud/cluster-action@main
with:
cluster-name: pr-${{ github.event.pull_request.number }}
server: https://app.uffizzi.com
- name: Kustomize and Apply Manifests
id: prev
run: |
# Change the image name to those just built and pushed.
kustomize edit set image dockersamples/examplevotingapp_vote=${{ needs.build-vote.outputs.tags }}
kustomize edit set image dockersamples/examplevotingapp_result=${{ needs.build-result.outputs.tags }}
kustomize edit set image dockersamples/examplevotingapp_worker=${{ needs.build-worker.outputs.tags }}
if [[ ${RUNNER_DEBUG} == 1 ]]; then
cat kustomization.yaml
echo "`pwd`"
echo "`ls`"
fi
# Apply kustomized manifests to virtual cluster.
kubectl apply --kustomize . --kubeconfig ./kubeconfig
# Allow uffizzi to sync the resources
sleep 5
# Get the hostnames assigned by uffizzi
export VOTE_HOST=$(kubectl get ingress vote --kubeconfig kubeconfig -o json | jq '.spec.rules[0].host' | tr -d '"')
export RESULT_HOST=$(kubectl get ingress result --kubeconfig kubeconfig -o json | jq '.spec.rules[0].host' | tr -d '"')
if [[ ${RUNNER_DEBUG} == 1 ]]; then
kubectl get all --kubeconfig ./kubeconfig
fi
echo "vote_url=${VOTE_HOST}" >> $GITHUB_OUTPUT
echo "result_url=${RESULT_HOST}" >> $GITHUB_OUTPUT
echo "Access the \`vote\` endpoint at [\`${VOTE_HOST}\`](http://${VOTE_HOST})" >> $GITHUB_STEP_SUMMARY
echo "Access the \`result\` endpoint at [\`${RESULT_HOST}\`](http://${RESULT_HOST})" >> $GITHUB_STEP_SUMMARY
- 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]`
Access the `vote` endpoint at [`${{ steps.prev.outputs.vote_url }}`](http://${{ steps.prev.outputs.vote_url }})
Access the `result` endpoint at [`${{ steps.prev.outputs.result_url }}`](http://${{ steps.prev.outputs.result_url }})
edit-mode: replace
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
# 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
- name: Update Comment with Deletion
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Uffizzi Cluster `pr-${{ github.event.pull_request.number }}` was deleted.
edit-mode: replace