-
Notifications
You must be signed in to change notification settings - Fork 112
148 lines (135 loc) · 4.64 KB
/
deploy-viz.yml
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Deploy Viz
on:
workflow_dispatch:
inputs:
regions:
description: "Regions to deploy to"
required: true
default: "us-central1"
type: choice
options:
- "us-central1"
- "europe-west1"
- "all"
check_deployment_blocked:
description: "Check #deployment locks or force deploy"
required: true
default: "check"
type: choice
options:
- "check"
- "force (dangerous)"
concurrency:
group: deploy_viz
cancel-in-progress: false
env:
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
IMAGE_NAME: viz
jobs:
notify-start:
runs-on: ubuntu-latest
outputs:
thread_ts: ${{ steps.build_message.outputs.thread_ts }}
steps:
- uses: actions/checkout@v3
- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Notify Build And Deploy Start
id: build_message
uses: ./.github/actions/slack-notify
with:
step: "start"
component: "viz"
image_tag: ${{ steps.short_sha.outputs.short_sha }}
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Slack Check Deployment Blocked
if: ${{ github.event.inputs.check_deployment_blocked != 'force (dangerous)' }}
id: check_deployment_blocked
uses: ./.github/actions/slack-check-deployment-blocked
with:
component: "viz"
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}
create-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
if [ "${{ github.event.inputs.regions }}" = "all" ]; then
echo "matrix=[\"us-central1\",\"europe-west1\"]" >> $GITHUB_OUTPUT
else
echo "matrix=[\"${{ github.event.inputs.regions }}\"]" >> $GITHUB_OUTPUT
fi
build:
needs: [notify-start, create-matrix]
runs-on: ubuntu-latest
strategy:
matrix:
region: ${{ fromJson(needs.create-matrix.outputs.matrix) }}
fail-fast: true
steps:
- uses: actions/checkout@v3
- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: "Authenticate with Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCLOUD_SA_KEY }}"
- name: Build image for ${{ matrix.region }}
run: |
chmod +x ./k8s/cloud-build.sh
./k8s/cloud-build.sh \
--image-name=$IMAGE_NAME \
--dockerfile-path=./viz/Dockerfile \
--working-dir=./ \
--region=${{ matrix.region }}
deploy:
needs: [notify-start, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.INFRA_DISPATCH_APP_ID }}
private-key: ${{ secrets.INFRA_DISPATCH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: |
dust-infra
- name: Trigger dust-infra workflow
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
await github.rest.repos.createDispatchEvent({
owner: '${{ github.repository_owner }}',
repo: 'dust-infra',
event_type: 'trigger-component-deploy',
client_payload: {
regions: '${{ github.event.inputs.regions }}',
component: 'viz',
image_tag: '${{ steps.short_sha.outputs.short_sha }}',
slack_thread_ts: "${{ needs.notify-start.outputs.thread_ts }}",
slack_channel: '${{ secrets.SLACK_CHANNEL_ID }}'
}
});
- name: Notify Failure
if: failure()
uses: ./.github/actions/slack-notify
with:
step: "failure"
blocked: ${{ steps.check_deployment_blocked.outputs.blocked }}
component: "viz"
image_tag: ${{ steps.short_sha.outputs.short_sha }}
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}
thread_ts: "${{ needs.notify-start.outputs.thread_ts }}"