-
Notifications
You must be signed in to change notification settings - Fork 8
249 lines (245 loc) · 9.21 KB
/
plugin-deploy.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: Build and Deploy to Cloud Run
on:
push:
branches:
- main
workflow_dispatch:
env:
GCP_PROJECT_ID: klaviyo-ct-plugin
GAR_LOCATION: us-central1
REPOSITORY: docker-repo
SERVICE: klaviyo-ct-plugin
REGION: us-central1
jobs:
infrastructure:
name: "[dev] Infrastructure"
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run terraform
uses: ./.github/actions/terraform
with:
tf_environment: dev
gcp_credentials: ${{ secrets.GCP_CREDENTIALS }}
ct_tf_client_id: ${{ secrets.CT_TF_CLIENT_ID }}
ct_tf_secret: ${{ secrets.CT_TF_SECRET }}
klaviyo_auth_key: ${{ secrets.KLAVIYO_AUTH_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
build_test:
name: 'Build and test'
runs-on: ubuntu-latest
needs: [ infrastructure ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: yarn
cache-dependency-path: ./plugin/yarn.lock
- name: Dependencies install
working-directory: ./plugin
run: yarn install --frozen-lockfile
- name: Linting
working-directory: ./plugin
run: yarn lint
- name: Test
working-directory: ./plugin
run: yarn test
docker_image:
name: "Build and push docker image"
runs-on: ubuntu-latest
needs: [ build_test ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker Auth to Google Artifact Registry
id: docker-auth
uses: 'docker/login-action@v2'
with:
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS }}
- name: Build image from docker file
run: |-
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}" ./plugin/
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}"
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Push docker image to Google Artifact Registry
run: |-
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}"
deployment_realtime:
name: "[dev] Deploy realtime events to Cloud Run"
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
needs: [ docker_image, infrastructure ]
environment: dev
env:
ENV_STAGE: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy image to Cloud Run
uses: ./.github/actions/cloudrun
with:
gcp_credentials: ${{ secrets.GCP_CREDENTIALS }}
service: ${{ env.ENV_STAGE }}-${{ env.SERVICE }}-realtime-events
region: ${{ env.REGION }}
port: 8080
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}
ct_api_url: ${{ vars.CT_API_URL }}
ct_auth_url: ${{ vars.CT_AUTH_URL }}
ct_project_id: ${{ vars.CT_PROJECT_ID }}
ct_scope: ${{ vars.CT_SCOPE }}
klaviyo_auth_key_secret: ${{ env.ENV_STAGE }}-klaviyo_auth_key:latest
klaviyo_company_id: ${{ vars.KLAVIYO_COMPANY_ID }}
ct_api_client_secret: ${{ env.ENV_STAGE }}-commercetools_api_client:latest
deployment_bulk_import:
name: "[dev] Deploy bulk import to Cloud Run"
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
needs: [ docker_image, infrastructure ]
environment: dev
env:
ENV_STAGE: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy image to Cloud Run
uses: ./.github/actions/cloudrun
with:
gcp_credentials: ${{ secrets.GCP_CREDENTIALS }}
service: ${{ env.ENV_STAGE }}-${{ env.SERVICE }}-bulk-import
region: ${{ env.REGION }}
port: 6779
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}
ct_api_url: ${{ vars.CT_API_URL }}
ct_auth_url: ${{ vars.CT_AUTH_URL }}
ct_project_id: ${{ vars.CT_PROJECT_ID }}
ct_scope: ${{ vars.CT_SCOPE }}
klaviyo_auth_key_secret: ${{ env.ENV_STAGE }}-klaviyo_auth_key:latest
klaviyo_company_id: ${{ vars.KLAVIYO_COMPANY_ID }}
ct_api_client_secret: ${{ env.ENV_STAGE }}-commercetools_api_client:latest
e2e_tests:
name: "[dev] End to end tests"
runs-on: ubuntu-latest
needs: [ deployment_realtime, deployment_bulk_import ]
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run postman collection
uses: ./.github/actions/postman
with:
ct_client_id: ${{ secrets.CT_E2E_CLIENT_ID }}
ct_secret: ${{ secrets.CT_E2E_SECRET }}
klaviyo_auth_key: ${{ secrets.KLAVIYO_AUTH_KEY }}
postman_collection_json: "klaviyo-e2e-tests.postman_collection.json"
ct_api_url: ${{ vars.CT_API_URL }}
ct_auth_url: ${{ vars.CT_AUTH_URL }}
ct_project_id: ${{ vars.CT_PROJECT_ID }}
infrastructure_prod:
name: "[prod] Infrastructure"
runs-on: ubuntu-latest
needs: [ e2e_tests ]
environment: prod
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run terraform
uses: ./.github/actions/terraform
with:
tf_environment: prod
gcp_credentials: ${{ secrets.GCP_CREDENTIALS }}
ct_tf_client_id: ${{ secrets.CT_TF_CLIENT_ID }}
ct_tf_secret: ${{ secrets.CT_TF_SECRET }}
klaviyo_auth_key: ${{ secrets.KLAVIYO_AUTH_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
deployment_realtime_prod:
name: "[prod] Deploy realtime events to Cloud Run"
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
needs: [ infrastructure_prod ]
environment: prod
env:
ENV_STAGE: prod
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy image to Cloud Run
uses: ./.github/actions/cloudrun
with:
gcp_credentials: ${{ secrets.GCP_CREDENTIALS }}
service: ${{ env.ENV_STAGE }}-${{ env.SERVICE }}-realtime-events
region: ${{ env.REGION }}
port: 8080
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}
ct_api_url: ${{ vars.CT_API_URL }}
ct_auth_url: ${{ vars.CT_AUTH_URL }}
ct_project_id: ${{ vars.CT_PROJECT_ID }}
ct_scope: ${{ vars.CT_SCOPE }}
klaviyo_auth_key_secret: ${{ env.ENV_STAGE }}-klaviyo_auth_key:latest
klaviyo_company_id: ${{ vars.KLAVIYO_COMPANY_ID }}
ct_api_client_secret: ${{ env.ENV_STAGE }}-commercetools_api_client:latest
deployment_bulk_import_prod:
name: "[prod] Deploy bulk import to Cloud Run"
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
needs: [ infrastructure_prod ]
environment: prod
env:
ENV_STAGE: prod
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy image to Cloud Run
uses: ./.github/actions/cloudrun
with:
gcp_credentials: ${{ secrets.GCP_CREDENTIALS }}
service: ${{ env.ENV_STAGE }}-${{ env.SERVICE }}-bulk-import
region: ${{ env.REGION }}
port: 6779
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}
ct_api_url: ${{ vars.CT_API_URL }}
ct_auth_url: ${{ vars.CT_AUTH_URL }}
ct_project_id: ${{ vars.CT_PROJECT_ID }}
ct_scope: ${{ vars.CT_SCOPE }}
klaviyo_auth_key_secret: ${{ env.ENV_STAGE }}-klaviyo_auth_key:latest
klaviyo_company_id: ${{ vars.KLAVIYO_COMPANY_ID }}
ct_api_client_secret: ${{ env.ENV_STAGE }}-commercetools_api_client:latest
e2e_tests_prod:
name: "[prod] End to end tests"
runs-on: ubuntu-latest
needs: [ deployment_realtime_prod, deployment_bulk_import_prod ]
environment: prod
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run postman collection
uses: ./.github/actions/postman
with:
ct_client_id: ${{ secrets.CT_E2E_CLIENT_ID }}
ct_secret: ${{ secrets.CT_E2E_SECRET }}
klaviyo_auth_key: ${{ secrets.KLAVIYO_AUTH_KEY }}
postman_collection_json: "klaviyo-e2e-tests.postman_collection.json"
ct_api_url: ${{ vars.CT_API_URL }}
ct_auth_url: ${{ vars.CT_AUTH_URL }}
ct_project_id: ${{ vars.CT_PROJECT_ID }}