Skip to content

Deploy: Downstream Clusters #7

Deploy: Downstream Clusters

Deploy: Downstream Clusters #7

name: "Deploy: Downstream Clusters"
on:
workflow_run:
workflows: ["Containers: Publish"]
types:
- completed
workflow_dispatch:
inputs:
tag:
description: 'Image tag to deploy (e.g. 1.1.0)'
required: true
default: 'latest'
jobs:
update-sandbox:
name: Update Sandbox Cluster
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'develop') }}
outputs:
tag: ${{ steps.get_tag.outputs.TAG }}
steps:
- name: Checkout App
uses: actions/checkout@v4
- name: Get Release Tag
id: get_tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "TAG=${{ inputs.tag }}" >> $GITHUB_OUTPUT
else
gh run download ${{ github.event.workflow_run.id }} -n docker-tag
TAG=$(cat docker_tag.txt)
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Sandbox Cluster
uses: actions/checkout@v4
with:
repository: CodeForPhilly/cfp-sandbox-cluster
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: sandbox
- name: Update Sandbox Image Tag
working-directory: sandbox/balancer
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
./kustomize edit set image ghcr.io/codeforphilly/balancer-main/app:${{ steps.get_tag.outputs.TAG }}
rm kustomize
- name: Create Sandbox PR
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: sandbox
commit-message: "Deploy balancer ${{ steps.get_tag.outputs.TAG }} to sandbox"
title: "Deploy balancer ${{ steps.get_tag.outputs.TAG }}"
body: "Updates balancer image tag to ${{ steps.get_tag.outputs.TAG }}"
branch: "deploy/balancer-${{ steps.get_tag.outputs.TAG }}"
base: main
delete-branch: true
update-live:
name: Update Live Cluster
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release') }}
steps:
- name: Checkout App
uses: actions/checkout@v4
- name: Get Release Tag
id: get_tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "TAG=${{ inputs.tag }}" >> $GITHUB_OUTPUT
else
gh run download ${{ github.event.workflow_run.id }} -n docker-tag
TAG=$(cat docker_tag.txt)
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Live Cluster
uses: actions/checkout@v4
with:
repository: CodeForPhilly/cfp-live-cluster
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: live
- name: Update Live Image Tag
working-directory: live/balancer
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
./kustomize edit set image ghcr.io/codeforphilly/balancer-main/app:${{ steps.get_tag.outputs.TAG }}
rm kustomize
- name: Create Live PR
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: live
commit-message: "Deploy balancer ${{ steps.get_tag.outputs.TAG }} to live"
title: "Deploy balancer ${{ steps.get_tag.outputs.TAG }}"
body: "Updates balancer image tag to ${{ steps.get_tag.outputs.TAG }}"
branch: "deploy/balancer-${{ steps.get_tag.outputs.TAG }}"
base: main
delete-branch: true