Skip to content

Commit 4942546

Browse files
authored
Merge pull request #442 from CodeForPhilly/ci/cd-refactor
ci: refactor pipelines for continuous deployment to sandbox
2 parents 18be6a7 + 1c458f0 commit 4942546

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

.github/workflows/containers-publish.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: "Containers: Publish"
33
on:
44
release:
55
types: [published]
6+
push:
7+
branches: [develop]
68

79
permissions:
810
packages: write
@@ -24,7 +26,13 @@ jobs:
2426
- name: Compute Docker container image addresses
2527
run: |
2628
DOCKER_REPOSITORY="ghcr.io/${GITHUB_REPOSITORY,,}"
27-
DOCKER_TAG="${GITHUB_REF:11}"
29+
30+
if [[ "${{ github.event_name }}" == "release" ]]; then
31+
DOCKER_TAG="${GITHUB_REF:11}"
32+
else
33+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
34+
DOCKER_TAG="dev-${SHORT_SHA}"
35+
fi
2836
2937
echo "DOCKER_REPOSITORY=${DOCKER_REPOSITORY}" >> $GITHUB_ENV
3038
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
@@ -51,3 +59,12 @@ jobs:
5159

5260
- name: "Push Docker container image app:v*"
5361
run: docker push "${DOCKER_REPOSITORY}/app:${DOCKER_TAG}"
62+
63+
- name: Save Docker Tag
64+
run: echo "${DOCKER_TAG}" > docker_tag.txt
65+
66+
- name: Upload Docker Tag
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: docker-tag
70+
path: docker_tag.txt

.github/workflows/deploy-downstream.yml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: "Deploy: Downstream Clusters"
22

33
on:
4-
release:
5-
types: [published]
4+
workflow_run:
5+
workflows: ["Containers: Publish"]
6+
types:
7+
- completed
68
workflow_dispatch:
79
inputs:
810
tag:
@@ -14,6 +16,7 @@ jobs:
1416
update-sandbox:
1517
name: Update Sandbox Cluster
1618
runs-on: ubuntu-latest
19+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'develop') }}
1720
outputs:
1821
tag: ${{ steps.get_tag.outputs.TAG }}
1922
steps:
@@ -26,8 +29,12 @@ jobs:
2629
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
2730
echo "TAG=${{ inputs.tag }}" >> $GITHUB_OUTPUT
2831
else
29-
echo "TAG=${GITHUB_REF:11}" >> $GITHUB_OUTPUT
32+
gh run download ${{ github.event.workflow_run.id }} -n docker-tag
33+
TAG=$(cat docker_tag.txt)
34+
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
3035
fi
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3138

3239
- name: Checkout Sandbox Cluster
3340
uses: actions/checkout@v4
@@ -57,9 +64,25 @@ jobs:
5764

5865
update-live:
5966
name: Update Live Cluster
60-
needs: update-sandbox
6167
runs-on: ubuntu-latest
68+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release') }}
6269
steps:
70+
- name: Checkout App
71+
uses: actions/checkout@v4
72+
73+
- name: Get Release Tag
74+
id: get_tag
75+
run: |
76+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
77+
echo "TAG=${{ inputs.tag }}" >> $GITHUB_OUTPUT
78+
else
79+
gh run download ${{ github.event.workflow_run.id }} -n docker-tag
80+
TAG=$(cat docker_tag.txt)
81+
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
82+
fi
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
6386
- name: Checkout Live Cluster
6487
uses: actions/checkout@v4
6588
with:
@@ -71,17 +94,17 @@ jobs:
7194
working-directory: live/balancer
7295
run: |
7396
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
74-
./kustomize edit set image ghcr.io/codeforphilly/balancer-main/app:${{ needs.update-sandbox.outputs.tag }}
97+
./kustomize edit set image ghcr.io/codeforphilly/balancer-main/app:${{ steps.get_tag.outputs.TAG }}
7598
rm kustomize
7699
77100
- name: Create Live PR
78101
uses: peter-evans/create-pull-request@v6
79102
with:
80103
token: ${{ secrets.BOT_GITHUB_TOKEN }}
81104
path: live
82-
commit-message: "Deploy balancer ${{ needs.update-sandbox.outputs.tag }} to live"
83-
title: "Deploy balancer ${{ needs.update-sandbox.outputs.tag }}"
84-
body: "Updates balancer image tag to ${{ needs.update-sandbox.outputs.tag }}"
85-
branch: "deploy/balancer-${{ needs.update-sandbox.outputs.tag }}"
105+
commit-message: "Deploy balancer ${{ steps.get_tag.outputs.TAG }} to live"
106+
title: "Deploy balancer ${{ steps.get_tag.outputs.TAG }}"
107+
body: "Updates balancer image tag to ${{ steps.get_tag.outputs.TAG }}"
108+
branch: "deploy/balancer-${{ steps.get_tag.outputs.TAG }}"
86109
base: main
87110
delete-branch: true

0 commit comments

Comments
 (0)