Skip to content

Commit 4e65f36

Browse files
committed
Ensure deployments are only triggered if the manifests exist for that environment
refs: TryGhost/Pro#5 Means that we can have services that either only have a staging or production deployment, good for development and tiny apps which only operate in a single environment
1 parent 0d5c78a commit 4e65f36

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,63 @@ jobs:
3333
if: startsWith(github.ref, 'refs/tags/')
3434
run: |
3535
echo "ENVIRONMENT=production" >> $GITHUB_ENV
36+
37+
- name: Checkout code
38+
uses: actions/checkout@v3
39+
40+
- name: Check for folder existence
41+
id: checkfolder
42+
run: |
43+
if [ -d "./k8s/overlays/${{ env.ENVIRONMENT }}" ]; then
44+
echo "::set-output name=manifests_exist::true"
45+
else
46+
echo "::set-output name=manifests_exist::false"
47+
fi
3648
3749
- name: Set project id
50+
if: steps.checkfolder.outputs.manifests_exist == 'true'
3851
run: |
3952
if [[ "${{ env.ENVIRONMENT }}" == "production" ]]; then
4053
echo "PROJECT_ID=${{ env.PRD_PROJECT_ID }}" >> $GITHUB_ENV
4154
elif [[ "${{ env.ENVIRONMENT }}" == "staging" ]]; then
4255
echo "PROJECT_ID=${{ env.STG_PROJECT_ID }}" >> $GITHUB_ENV
4356
fi
4457
45-
- name: Checkout code
46-
uses: actions/checkout@v3
47-
4858
- name: 'Authenticate to Google Cloud'
59+
if: steps.checkfolder.outputs.manifests_exist == 'true'
4960
uses: 'google-github-actions/auth@v1'
5061
with:
5162
# TODO: Use different secret for production and staging
5263
credentials_json: ${{ secrets.GCP_SA_JSON }}
5364

5465
- name: Set up Google Cloud SDK
66+
if: steps.checkfolder.outputs.manifests_exist == 'true'
5567
uses: google-github-actions/[email protected]
5668
with:
5769
project_id: ${{ env.PROJECT_ID }}
5870

5971
- name: Authenticate with GKE
72+
if: steps.checkfolder.outputs.manifests_exist == 'true'
6073
uses: 'google-github-actions/get-gke-credentials@v1'
6174
with:
6275
cluster_name: 'ghost-pro'
6376
location: 'europe-west4-a'
6477

6578
- name: Build final manifest
79+
if: steps.checkfolder.outputs.manifests_exist == 'true'
6680
run: |
6781
kubectl kustomize ./k8s/overlays/${{ env.ENVIRONMENT }} > /tmp/built-manifest.yaml
6882
6983
- name: Setup yq
84+
if: steps.checkfolder.outputs.manifests_exist == 'true'
7085
uses: supplypike/setup-bin@v3
7186
with:
7287
uri: 'https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64'
7388
name: 'yq'
7489
version: '4.35.1'
7590

7691
- name: Extract Deployment Name and Namespace
92+
if: steps.checkfolder.outputs.manifests_exist == 'true'
7793
run: |
7894
deployment_name=$(yq e 'select(.kind == "Deployment") | .metadata.name' /tmp/built-manifest.yaml)
7995
namespace=$(yq e 'select(.kind == "Deployment") | .metadata.namespace' /tmp/built-manifest.yaml | sed 's/^null$/default/')
@@ -84,6 +100,7 @@ jobs:
84100
echo "NAMESPACE=$namespace" >> $GITHUB_ENV
85101
86102
- name: Apply the manifests to the Kubernetes cluster
103+
if: steps.checkfolder.outputs.manifests_exist == 'true'
87104
run: |
88105
kubectl apply -k k8s/overlays/${{ env.ENVIRONMENT }}
89106
kubectl rollout restart deployment ${{ env.DEPLOYMENT_NAME }} --namespace ${{ env.NAMESPACE }}

0 commit comments

Comments
 (0)