-
-
Notifications
You must be signed in to change notification settings - Fork 6
284 lines (262 loc) · 9.59 KB
/
cd-preview-argocd.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: |-
CD - Deploy to EKS Preview envs with Helmfile
Deploy Docker image to ECS Preview envs with Helmfile
### Usage
```yaml
name: Feature Branch
on:
pull_request:
branches: [ 'master' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]
jobs:
cd:
uses: cloudposse/github-actions-workflows/.github/workflows/cd-preview-helmfile.yml@main
if: $\{\{ always() \}\}
with:
image: registry.hub.docker.com/library/nginx
tag: latest
repository: $\{\{ github.event.repository.name \}\}
open: $\{\{ github.event.pull_request.state == 'open' \}\}
labels: $\{\{ toJSON(github.event.pull_request.labels.*.name) \}\}
ref: $\{\{ github.event.pull_request.head.ref \}\}
exclusive: false
env-label: |
preview: deploy
secrets:
secret-outputs-passphrase: $\{\{ secrets.secret-outputs-passphrase \}\}
github-private-actions-pat: $\{\{ secrets.github-private-actions-pat \}\}
```
on:
workflow_call:
inputs:
image:
description: "Docker Image to deploy"
required: true
type: string
tag:
description: "Docker Image tag to deploy"
required: true
type: string
organization:
description: "Repository owner organization (ex. acme for repo acme/example)"
required: true
type: string
repository:
description: "Repository name (ex. example for repo acme/example)"
required: true
type: string
ref:
description: "The fully-formed ref of the branch or tag that triggered the workflow run"
required: true
type: string
open:
description: "Pull Request open/close state. Set true if opened"
required: true
type: boolean
labels:
description: "Pull Request labels"
required: false
type: string
default: "{}"
toolchain:
description: "Toolchain ('helm', 'helmfile')"
required: false
default: "helmfile"
type: string
path:
description: "The path where lives the helmfile or helm chart."
required: true
type: string
values_file:
type: string
description: Helmfile values file, or helm chart values file
default: ""
required: false
exclusive:
description: "Deactivate previous GitHub deployments"
required: false
type: boolean
default: true
env-label:
description: "YAML formatted {environment}: {label} map"
type: string
default: |
preview: deploy
synchronously:
type: boolean
description: "Wait until ArgoCD successfully apply the changes"
default: false
runs-on:
description: "Overrides job runs-on setting (json-encoded list)"
type: string
required: false
default: '["ubuntu-latest"]'
secrets:
secret-outputs-passphrase:
description: "Passphrase to encrypt/decrypt secret outputs with gpg. For more information [read](https://github.com/cloudposse/github-action-secret-outputs)"
required: true
github-private-actions-pat:
description: "Github PAT allow to pull private repos"
required: true
permissions:
pull-requests: write
deployments: write
id-token: write
contents: read
jobs:
preview:
runs-on: ${{ fromJSON(inputs.runs-on) }}
steps:
- name: Preview deployments controller
uses: cloudposse/[email protected]
id: controller
with:
labels: ${{ inputs.labels }}
open: ${{ inputs.open }}
env-label: ${{ inputs.env-label }}
outputs:
namespace: ${{ inputs.ref }}
labels_env: ${{ steps.controller.outputs.labels_env }}
deploy_envs: ${{ steps.controller.outputs.deploy_envs }}
destroy_envs: ${{ steps.controller.outputs.destroy_envs }}
deploy:
runs-on: ubuntu-latest
needs: [ preview ]
if: ${{ needs.preview.outputs.deploy_envs != '[]' }}
strategy:
matrix:
env: ${{ fromJson(needs.preview.outputs.deploy_envs) }}
environment:
name: ${{ matrix.env }}
url: ${{ steps.deploy.outputs.webapp-url }}
steps:
- uses: cloudposse/[email protected]
id: image
with:
secret: ${{ secrets.secret-outputs-passphrase }}
op: decode
in: ${{ inputs.image }}
- name: Deactive environment
uses: bobheadxi/deployments@v1
if: ${{ inputs.exclusive }}
with:
step: deactivate-env
token: ${{ github.token }}
env: ${{ matrix.env }}
desc: Environment purged
- name: Checkout
uses: actions/checkout@v4
- name: Environment Info
uses: cloudposse/[email protected]
id: environment
with:
implementation_repository: cloudposse/actions-private
implementation_path: 'argocd-environments/'
implementation_ref: main
implementation_github_pat: ${{ secrets.github-private-actions-pat }}
environment: ${{ matrix.env }}
namespace: ${{ needs.preview.outputs.namespace }}
repository: ${{ inputs.repository }}
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
aws-region: ${{ steps.environment.outputs.region }}
role-to-assume: ${{ steps.environment.outputs.role }}
role-skip-session-tagging: true
- name: Deploy
uses: cloudposse/[email protected]
id: deploy
with:
toolchain: ${{ inputs.toolchain }}
synchronously: ${{ inputs.synchronously }}
path: ${{ inputs.path }}
values_file: ${{ format(inputs.values_file, steps.environment.outputs.name) }}
application: ${{ inputs.repository }}
ssm-path: ${{ steps.environment.outputs.ssm-path }}
aws-region: ${{ steps.environment.outputs.region }}
cluster: ${{ steps.environment.outputs.cluster }}
environment: ${{ steps.environment.outputs.name }}
namespace: ${{ steps.environment.outputs.namespace }}
image: ${{ steps.image.outputs.out }}
image-tag: ${{ inputs.tag }}
operation: deploy
github-pat: ${{ secrets.github-private-actions-pat }}
repository: ${{ inputs.organization }}/${{ inputs.repository }}
ref: ${{ github.sha }}
destroy:
runs-on: ubuntu-latest
needs: [ preview ]
if: ${{ needs.preview.outputs.destroy_envs != '[]' }}
strategy:
matrix:
env: ${{ fromJson(needs.preview.outputs.destroy_envs) }}
permissions:
pull-requests: write
deployments: write
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Seek deployment
uses: cloudposse/[email protected]
id: deployment
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
environment: ${{ matrix.env }}
ref: ${{ inputs.ref }}
status: success
- name: Environment Info
uses: cloudposse/[email protected]
if: ${{ steps.deployment.outputs.id != '' }}
id: environment
with:
implementation_repository: cloudposse/actions-private
implementation_path: 'argocd-environments/'
implementation_ref: main
implementation_github_pat: ${{ secrets.github-private-actions-pat }}
environment: ${{ matrix.env }}
namespace: ${{ needs.preview.outputs.namespace }}
repository: ${{ inputs.repository }}
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
if: ${{ steps.deployment.outputs.id != '' }}
with:
aws-region: ${{ steps.environment.outputs.region }}
role-to-assume: ${{ steps.environment.outputs.role }}
role-skip-session-tagging: true
- name: Destroy
uses: cloudposse/[email protected]
if: ${{ steps.deployment.outputs.id != '' }}
id: deploy
with:
toolchain: ${{ inputs.toolchain }}
synchronously: ${{ inputs.synchronously }}
path: ${{ inputs.path }}
application: ${{ inputs.repository }}
values_file: ${{ format(inputs.values_file, steps.environment.outputs.name) }}
ssm-path: ${{ steps.environment.outputs.ssm-path }}
aws-region: ${{ steps.environment.outputs.region }}
cluster: ${{ steps.environment.outputs.cluster }}
environment: ${{ steps.environment.outputs.name }}
namespace: ${{ steps.environment.outputs.namespace }}
image: "<none>"
image-tag: "<none>"
operation: destroy
github-pat: ${{ secrets.github-private-actions-pat }}
debug: false
repository: ${{ inputs.organization }}/${{ inputs.repository }}
ref: ${{ github.sha }}
- name: Inactivate deployment
uses: chrnorm/[email protected]
if: ${{ steps.deployment.outputs.id != '' }}
with:
state: inactive
token: ${{ github.token }}
deployment-id: ${{ steps.deployment.outputs.id }}
- name: Cleanup label
uses: cloudposse/[email protected]
if: ${{ ! inputs.open }}
with:
labels_env: ${{ needs.preview.outputs.labels_env }}
env: ${{ matrix.env }}