generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 13
128 lines (104 loc) · 3.65 KB
/
backend-cd.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Backend App CD
on:
workflow_call:
inputs:
target:
required: true
type: string
app_name:
required: true
type: string
working_directory:
type: string
default: "."
redeploy:
type: string
default: "false"
secrets:
WORKLOAD_IDENTIFY_POOLS_PROVIDER:
required: true
GCP_SERVICE_ACCOUNT:
required: true
jobs:
setup:
# Only allow run the CD flow in protected branch
if: github.ref_protected == true
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
# Allow add the tag in the repo.
# Add "id-token" with the intended permissions.
permissions:
contents: 'write'
id-token: 'none'
outputs:
TARGETS: ${{ steps.setenv.outputs.TARGETS }}
TARGET: ${{ steps.setenv.outputs.TARGET }}
TARGET_FROM: ${{ steps.setenv.outputs.TARGET_FROM }}
PIPELINE: ${{ steps.setenv.outputs.PIPELINE }}
steps:
# Checkout code
- name: Checkout out the code
uses: actions/checkout@v4
- name: Setup targets
uses: bcgov/bcregistry-sre/.github/actions/setup-deployment-target@main
with:
environment: ${{ inputs.target }}
app_name: ${{ inputs.app_name }}
- id: setenv
run: |
echo "TARGETS=${{ env.DEPLOY_TARGETS }}" >> "$GITHUB_OUTPUT"
echo "TARGET=${{ env.DEPLOY_TARGET }}" >> "$GITHUB_OUTPUT"
echo "TARGET_FROM=${{ env.DEPLOY_TARGET_FROM }}" >> "$GITHUB_OUTPUT"
echo "PIPELINE=${{ env.DEPLOY_PIPELINE }}" >> "$GITHUB_OUTPUT"
deploy:
needs: setup
runs-on: ubuntu-22.04
environment:
name: "${{ needs.setup.outputs.TARGET }}"
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
# Allow add the tag in the repo.
# Add "id-token" with the intended permissions.
permissions:
contents: 'write'
id-token: 'write'
steps:
# Checkout code
- name: Checkout out the code
uses: actions/checkout@v4
# Copy cloud build, cloud deploy and skaffold yaml files to the build
- name: Copy deployment files
uses: bcgov/bcregistry-sre/.github/actions/backend-deploy@main
with:
working-directory: ${{ inputs.working_directory }}
# GCP authentication
- name: 'Authenticate to Google Cloud'
id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTIFY_POOLS_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
# Trigger Cloud Deploy
- name: Deployment
working-directory: ${{ inputs.working_directory }}
run: |-
SHORT_SHA=$(git rev-parse --short HEAD)
echo "SHORT_SHA: $SHORT_SHA"
TARGET_FROM="${{ needs.setup.outputs.TARGET_FROM }}"
if [ -z ${{ needs.setup.outputs.TARGET_FROM }}]; then
TARGET_FROM="${{ needs.setup.outputs.TARGET }}"
fi
echo "TARGET_FROM: $TARGET_FROM"
pwd
ls -la
gcloud builds submit \
--region=northamerica-northeast1 \
--substitutions _SHORT_SHA=$SHORT_SHA,_APP_NAME="${{ inputs.app_name }}",_DEPLOYMENT_ENVS="${{ needs.setup.outputs.TARGETS }}",_DEPLOYMENT_ENV="${{ needs.setup.outputs.TARGET }}",_DEPLOYMENT_ENV_FROM="$TARGET_FROM",_DEPLOYMENT_PIPELINE="${{ needs.setup.outputs.PIPELINE }}",_REDEPLOY="${{ inputs.redeploy}}" \
--config devops/gcp/cloudbuild.yaml