generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 13
120 lines (100 loc) · 3.36 KB
/
frontend-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
name: Frontend CD
on:
workflow_call:
inputs:
target:
required: true
type: string
node_version:
type: string
default: "21"
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-latest
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-latest
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, Dockerfile, firebase files to the build
- name: Copy deployment files
uses: bcgov/bcregistry-sre/.github/actions/frontend-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
gcloud builds submit \
--region=northamerica-northeast1 \
--substitutions _SHORT_SHA=$SHORT_SHA,_NODE_VERSION="${{ inputs.node_version }}",_APP_NAME="${{ inputs.app_name }}",_DEPLOYMENT_ENV="${{ needs.setup.outputs.TARGET }}",_DEPLOYMENT_ENV_FROM="${{ needs.setup.outputs.TARGET_FROM }}",_REDEPLOY="${{ inputs.redeploy}}" \
--config cloudbuild.yaml