-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
321 lines (290 loc) · 13.7 KB
/
action.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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: 'Runtimes Tasks Integrated Action'
description: 'Unified Action for running Runtimes all deployment Tasks within a single runner'
inputs:
TASK_LIST:
description: List of tasks
type: string
required: true
FEATURES_LEVEL_LOG:
description: "Log Level"
type: string
required: true
REPOSITORY_NAME:
description: "Git Repository Name"
type: string
required: true
AWS_REGION:
description: "AWS REGION"
type: string
required: true
CONTAINER_URL_IAC:
description: "IAC Container url"
type: string
default: stackspot/runtime-job-iac:latest
required: false
CONTAINER_URL_DEPLOY:
description: "Deploy Container url"
type: string
default: stackspot/runtime-job-deploy:latest
required: false
CONTAINER_URL_DESTROY:
description: "Destroy Container url"
type: string
default: stackspot/runtime-job-destroy:latest
required: false
CONTAINER_URL_UNIFIED:
description: "Unified Tasks Container url"
type: string
default: stackspot/runtime-job-unified:latest
required: false
TF_PARALLELISM:
description: "Terraform parallelism ordem"
type: string
default: 10
required: false
FEATURES_TERRAFORM_MODULES:
type: string
description: "Terraform Modules"
required: false
PATH_TO_MOUNT:
type: string
description: "Path to mount inside the docker"
required: true
OUTPUT_FILE:
description: "File name to save outputs: {plugin-alias}_{OUTPUT_FILE}"
type: string
required: false
default: outputs.json
LOCALEXEC_ENABLED:
description: "If Runtimes will allow execution of the local-exec command within terraform"
type: boolean
required: false
default: "false"
TF_LOG_PROVIDER:
description: "Level tf log provider - info, debug, warn or trace"
type: string
required: false
CHECKOUT_BRANCH:
description: "Whether or not checkout is enabled."
type: string
required: false
default: "true"
BASE_PATH_OUTPUT:
description: "Base Path Output"
type: string
required: false
CLIENT_ID:
description: "CLIENT ID"
required: true
CLIENT_KEY:
description: "CLIENT KEY"
required: true
CLIENT_REALM:
description: "CLIENT REALM"
required: true
AWS_ACCESS_KEY_ID:
description: "AWS ACCESS KEY ID from console"
required: false
AWS_SECRET_ACCESS_KEY:
description: "AWS SECRET ACCESS KEY from console"
required: false
AWS_SESSION_TOKEN:
description: "AWS SESSION TOKEN from console"
required: false
AWS_ROLE_ARN:
description: "AWS ROLE ARN"
required: false
RUN_ID:
description: "Run ID that contains its tasks"
required: true
BETA_CLI_ENVIRONMENT:
description: Environment in which cli will be executed. (default, stg, dev).
required: false
type: string
default: default
runs:
using: "composite"
steps:
- name: Check Runner
run: echo 🤖 OS runner is $(uname)
shell: bash
- name: Configure aws credentials
env:
role_arn: ${{ inputs.AWS_ROLE_ARN }}
id: aws-cred
if: ${{ env.role_arn != 0 }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.AWS_ROLE_ARN }}
aws-region: ${{ inputs.AWS_REGION }}
output-credentials: true
- name: Checkout
if: inputs.CHECKOUT_BRANCH != 'false'
uses: actions/checkout@v4
- name: "Setup jq"
shell: bash
run: |
if ! [ -x "$(command -v jq)" ]; then
sudo apt install jq -y
fi
- name: Define Domains
id: stackspot-url
run: |
if [ "${{ inputs.BETA_CLI_ENVIRONMENT }}" == "default" ]; then
STACKSPOT_IAM_URL="https://auth.stackspot.com"
STACKSPOT_RUNTIME_MANAGER_URL="https://runtime-manager.v1.stackspot.com"
elif [ "${{ inputs.BETA_CLI_ENVIRONMENT }}" == "stg" ]; then
STACKSPOT_IAM_URL="https://iam-auth-ssr.stg.stackspot.com"
STACKSPOT_RUNTIME_MANAGER_URL="https://runtime-manager.stg.stackspot.com"
elif [ "${{ inputs.BETA_CLI_ENVIRONMENT }}" == "dev" ]; then
STACKSPOT_IAM_URL="https://iam-auth-ssr.dev.stackspot.com"
STACKSPOT_RUNTIME_MANAGER_URL="https://runtime-manager.dev.stackspot.com"
else
echo "Invalid environment: ${{ inputs.BETA_CLI_ENVIRONMENT }}"
exit 1
fi
echo "iam=$STACKSPOT_IAM_URL" >> "$GITHUB_OUTPUT"
echo "runtime_manager=$STACKSPOT_RUNTIME_MANAGER_URL" >> "$GITHUB_OUTPUT"
shell: bash
- name: "Run all tasks"
shell: bash
run: |
task_list=$(echo "${{ inputs.TASK_LIST }}" | tr "'" '"')
echo "$task_list"
for row in $(echo "$task_list" | jq -e -r '.[] | @base64'); do
task_id=$(echo "${row}" | base64 --decode | jq -e -r '.runTaskId')
task_type=$(echo "${row}" | base64 --decode | jq -e -r '.taskType')
plugin_alias=$(echo "${row}" | base64 --decode | jq -e -r '.pluginAppliedAlias')
if [ "$task_type" == "IAC_SELF_HOSTED" ]; then
FLAGS=$(echo "-v ${{ inputs.PATH_TO_MOUNT }}:/app-volume \
-e FEATURES_LEVEL_LOG=${{ inputs.FEATURES_LEVEL_LOG }} \
-e AUTHENTICATE_CLIENT_ID=${{ inputs.CLIENT_ID }} \
-e AUTHENTICATE_CLIENT_SECRET=${{ inputs.CLIENT_KEY }} \
-e AUTHENTICATE_CLIENT_REALMS=${{ inputs.CLIENT_REALM }} \
-e AUTHENTICATE_URL="${{ steps.stackspot-url.outputs.iam }}" \
-e FEATURES_API_MANAGER="${{ steps.stackspot-url.outputs.runtime_manager }}" \
-e REPOSITORY_NAME=${{ inputs.REPOSITORY_NAME }} \
-e CHECKOUT_BRANCH="${{ inputs.CHECKOUT_BRANCH }}" \
-e AWS_REGION=${{ inputs.AWS_REGION }}")
if [ -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ inputs.AWS_ACCESS_KEY_ID }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ inputs.AWS_SECRET_ACCESS_KEY }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ inputs.AWS_SESSION_TOKEN }}")
fi
if [ ! -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ steps.aws-cred.outputs.aws-access-key-id }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ steps.aws-cred.outputs.aws-secret-access-key }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ steps.aws-cred.outputs.aws-session-token }}")
fi
docker run --rm \
$FLAGS \
--entrypoint=/app/stackspot-runtime-job-iac \
${{ inputs.CONTAINER_URL_IAC }} start --run-task-id="${task_id}" --base-path-output="${{ inputs.BASE_PATH_OUTPUT }}"
fi
if [ "$task_type" == "DEPLOY_SELF_HOSTED" ]; then
FLAGS=$(echo "-v ${{ inputs.PATH_TO_MOUNT }}:/app-volume \
-e FEATURES_LEVEL_LOG=${{ inputs.FEATURES_LEVEL_LOG }} \
-e AUTHENTICATE_CLIENT_ID=${{ inputs.CLIENT_ID }} \
-e AUTHENTICATE_CLIENT_SECRET=${{ inputs.CLIENT_KEY }} \
-e AUTHENTICATE_CLIENT_REALMS=${{ inputs.CLIENT_REALM }} \
-e REPOSITORY_NAME=${{ inputs.REPOSITORY_NAME }} \
-e AUTHENTICATE_URL="${{ steps.stackspot-url.outputs.iam }}" \
-e FEATURES_API_MANAGER="${{ steps.stackspot-url.outputs.runtime_manager }}" \
-e FEATURES_BASEPATH_TMP=/tmp/runtime/deploys \
-e FEATURES_BASEPATH_EBS=/opt/runtime \
-e FEATURES_TEMPLATES_FILEPATH=/app/ \
-e FEATURES_BASEPATH_TERRAFORM=/root/.asdf/shims/terraform \
-e AWS_REGION=${{ inputs.AWS_REGION }} \
-e FEATURES_RELEASE_LOCALEXEC=${{ inputs.LOCALEXEC_ENABLED }}")
if [ -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ inputs.AWS_ACCESS_KEY_ID }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ inputs.AWS_SECRET_ACCESS_KEY }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ inputs.AWS_SESSION_TOKEN }}")
fi
if [ ! -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ steps.aws-cred.outputs.aws-access-key-id }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ steps.aws-cred.outputs.aws-secret-access-key }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ steps.aws-cred.outputs.aws-session-token }}")
fi
if [ ! -z "${{ inputs.TF_LOG_PROVIDER }}" ]; then
FLAGS=$(echo "$FLAGS -e FEATURES_TERRAFORM_LOGPROVIDER=${{ inputs.TF_LOG_PROVIDER }}")
fi
docker run --rm \
$FLAGS \
-e FEATURES_TERRAFORM_MODULES='${{ inputs.FEATURES_TERRAFORM_MODULES }}' \
--entrypoint=/app/stackspot-runtime-job-deploy \
${{ inputs.CONTAINER_URL_DEPLOY }} start --run-task-id="${task_id}" --output-file="${plugin_alias}${{ inputs.OUTPUT_FILE }}"
fi
if [ "$task_type" == "DESTROY_SELF_HOSTED" ]; then
FLAGS=$(echo "-v ${{ inputs.PATH_TO_MOUNT }}:/app-volume \
-e FEATURES_LEVEL_LOG=${{ inputs.FEATURES_LEVEL_LOG }} \
-e AUTHENTICATE_CLIENT_ID=${{ inputs.CLIENT_ID }} \
-e AUTHENTICATE_CLIENT_SECRET=${{ inputs.CLIENT_KEY }} \
-e AUTHENTICATE_CLIENT_REALMS=${{ inputs.CLIENT_REALM }} \
-e REPOSITORY_NAME=${{ inputs.REPOSITORY_NAME }} \
-e AUTHENTICATE_URL="${{ steps.stackspot-url.outputs.iam }}" \
-e FEATURES_API_MANAGER="${{ steps.stackspot-url.outputs.runtime_manager }}" \
-e FEATURES_BASEPATH_TMP=/tmp/runtime/deploys \
-e FEATURES_BASEPATH_EBS=/opt/runtime \
-e FEATURES_TEMPLATES_FILEPATH=/app/ \
-e FEATURES_BASEPATH_TERRAFORM=/root/.asdf/shims/terraform \
-e AWS_REGION=${{ inputs.AWS_REGION }} \
-e FEATURES_RELEASE_LOCALEXEC=${{ inputs.LOCALEXEC_ENABLED }}")
if [ -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ inputs.AWS_ACCESS_KEY_ID }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ inputs.AWS_SECRET_ACCESS_KEY }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ inputs.AWS_SESSION_TOKEN }}")
fi
if [ ! -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ steps.aws-cred.outputs.aws-access-key-id }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ steps.aws-cred.outputs.aws-secret-access-key }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ steps.aws-cred.outputs.aws-session-token }}")
fi
if [ ! -z "${{ inputs.TF_LOG_PROVIDER }}" ]; then
FLAGS=$(echo "$FLAGS -e FEATURES_TERRAFORM_LOGPROVIDER=${{ inputs.TF_LOG_PROVIDER }}")
fi
docker run --rm \
$FLAGS \
-e FEATURES_TERRAFORM_MODULES='${{ inputs.FEATURES_TERRAFORM_MODULES }}' \
--entrypoint=/app/stackspot-runtime-job-destroy \
${{ inputs.CONTAINER_URL_DESTROY }} start --run-task-id="${task_id}"
fi
if [ "$task_type" == "UNIFIED_IAC" ] || [ "$task_type" == "UNIFIED_DEPLOY" ] || [ "$task_type" == "UNIFIED_DESTROY" ]; then
FLAGS=$(echo "-v ${{ inputs.PATH_TO_MOUNT }}:/app-volume \
-e FEATURES_LEVEL_LOG=${{ inputs.FEATURES_LEVEL_LOG }} \
-e AUTHENTICATE_CLIENT_ID=${{ inputs.CLIENT_ID }} \
-e AUTHENTICATE_CLIENT_SECRET=${{ inputs.CLIENT_KEY }} \
-e AUTHENTICATE_CLIENT_REALMS=${{ inputs.CLIENT_REALM }} \
-e REPOSITORY_NAME=${{ inputs.REPOSITORY_NAME }} \
-e AUTHENTICATE_URL="${{ steps.stackspot-url.outputs.iam }}" \
-e FEATURES_API_MANAGER="${{ steps.stackspot-url.outputs.runtime_manager }}" \
-e FEATURES_BASEPATH_TMP=/tmp/runtime/deploys \
-e FEATURES_BASEPATH_EBS=/opt/runtime \
-e FEATURES_TEMPLATES_FILEPATH=/app/ \
-e FEATURES_BASEPATH_TERRAFORM=/root/.asdf/shims/terraform \
-e AWS_REGION=${{ inputs.AWS_REGION }} \
-e CHECKOUT_BRANCH="${{ inputs.CHECKOUT_BRANCH }}" \
-e TF_CLI_ARGS_apply="-parallelism=${{ inputs.TF_PARALLELISM }}" \
-e TF_CLI_ARGS_plan="-parallelism=${{ inputs.TF_PARALLELISM }}" \
-e TF_CLI_ARGS_destroy="-parallelism=${{ inputs.TF_PARALLELISM }}" \
-e FEATURES_RELEASE_LOCALEXEC=${{ inputs.LOCALEXEC_ENABLED }}")
if [ -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ inputs.AWS_ACCESS_KEY_ID }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ inputs.AWS_SECRET_ACCESS_KEY }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ inputs.AWS_SESSION_TOKEN }}")
fi
if [ ! -z "${{ inputs.AWS_ROLE_ARN }}" ]; then
FLAGS=$(echo "$FLAGS -e AWS_ACCESS_KEY_ID=${{ steps.aws-cred.outputs.aws-access-key-id }}")
FLAGS=$(echo "$FLAGS -e AWS_SECRET_ACCESS_KEY=${{ steps.aws-cred.outputs.aws-secret-access-key }}")
FLAGS=$(echo "$FLAGS -e AWS_SESSION_TOKEN=${{ steps.aws-cred.outputs.aws-session-token }}")
fi
if [ ! -z "${{ inputs.TF_LOG_PROVIDER }}" ]; then
FLAGS=$(echo "$FLAGS -e FEATURES_TERRAFORM_LOGPROVIDER=${{ inputs.TF_LOG_PROVIDER }}")
fi
docker run --rm \
$FLAGS \
-e FEATURES_TERRAFORM_MODULES='${{ inputs.FEATURES_TERRAFORM_MODULES }}' \
--entrypoint=/app/stackspot-runtime-job \
${{ inputs.CONTAINER_URL_UNIFIED }} start --run-id="${{ inputs.RUN_ID }}" --base-path-output="${{ inputs.BASE_PATH_OUTPUT }}"
fi
done