Skip to content

Commit d928c41

Browse files
committed
new action run-all
1 parent 409feec commit d928c41

File tree

8 files changed

+228
-32
lines changed

8 files changed

+228
-32
lines changed

runtime-deploy-all/action.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

runtime-deploy-all/script.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

runtime-manager-action/script.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def safe_load(content: str) -> dict:
1919
return yml.load(StringIO(content))
2020

2121

22-
def save_output(name: str, value: str):
23-
with open("manager-output.log", 'a') as output_file:
24-
print(f'{name}={value}', file=output_file)
22+
def save_output(value: str):
23+
with open("manager-output.log", 'w') as output_file:
24+
print(value, file=output_file)
2525

2626
def run(metadata):
2727

@@ -155,8 +155,7 @@ def run(metadata):
155155
runType = d2["runType"]
156156
tasks = d2["tasks"]
157157

158-
save_output('tasks', tasks)
159-
save_output('run_id', runId)
158+
save_output(d2)
160159

161160
print(f"- RUN {runType} successfully started with ID: {runId}")
162161
print(f"- RUN TASKS LIST: {tasks}")

runtime-run-all/action.yaml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
schema-version: v3
2+
kind: action
3+
metadata:
4+
name: runtime-run-all
5+
display-name: runtime-run-all
6+
description: Descreva sua action explicando o propósito.
7+
version: 0.0.1
8+
spec:
9+
type: python
10+
docs:
11+
pt-br: docs/pt-br/docs.md
12+
en-us: docs/en-us/docs.md
13+
repository: https://github.com/stack-spot/workflow-stackspot-actions-runtime-selfhosted.git
14+
inputs:
15+
- label: base path actions
16+
name: base_path_actions
17+
type: text
18+
required: true
19+
help: 'Inform base path actions'
20+
21+
- label: Environment used to deploy
22+
name: environment
23+
type: text
24+
required: true
25+
help: 'Inform environment used to deploy'
26+
27+
- label: Workspace used to deploy
28+
name: workspace
29+
type: text
30+
required: true
31+
help: 'Inform workspace used to deploy'
32+
33+
- label: Deploy version tag
34+
name: version_tag
35+
type: text
36+
required: true
37+
help: 'Inform deploy version tag'
38+
39+
- label: Branch to perform checkout in Runtime
40+
name: branch
41+
type: text
42+
required: false
43+
help: 'Inform branch to perform checkout in Runtime'
44+
45+
- label: Path to API file to publish on StackSpot Catalog API
46+
name: open_api_path
47+
type: text
48+
required: false
49+
help: 'Inform path to API file to publish on StackSpot Catalog API'
50+
51+
- label: Dynamic Inputs
52+
name: dynamic_inputs
53+
type: text
54+
required: false
55+
help: '--key1 value1 --key2 value2'
56+
57+
- label: Bucket to save generated tfstate files
58+
name: tf_state_bucket_name
59+
type: text
60+
required: true
61+
help: 'Inform bucket to save generated tfstate files'
62+
63+
- label: Region configuration for tfstate
64+
name: tf_state_region
65+
type: text
66+
required: true
67+
help: 'Inform region configuration for tfstate'
68+
69+
- label: Bucket to save generated iac files
70+
name: iac_bucket_name
71+
type: text
72+
required: true
73+
help: 'Inform bucket to save generated iac files'
74+
75+
- label: Region configuration for iac
76+
name: iac_region
77+
type: text
78+
required: true
79+
help: 'Inform region configuration for iac'
80+
81+
- label: Path to the directory where the .stk is located.
82+
name: workdir
83+
type: text
84+
required: false
85+
help: 'Inform path to the directory where the .stk is located.'
86+
87+
- label: "Features Log Level"
88+
name: features_level_log
89+
type: text
90+
required: true
91+
- label: "CLIENT ID"
92+
name: client_id
93+
type: text
94+
required: true
95+
- label: "CLIENT KEY"
96+
name: client_key
97+
type: text
98+
required: true
99+
- label: "CLIENT REALM"
100+
name: client_realm
101+
type: text
102+
required: true
103+
- label: "Git Repository Name"
104+
name: repository_name
105+
type: text
106+
required: true
107+
- label: "AWS ACCESS KEY ID from console"
108+
name: aws_access_key_id
109+
type: text
110+
required: true
111+
- label: "AWS SECRET ACCESS KEY from console"
112+
name: aws_secret_access_key
113+
type: text
114+
required: true
115+
- label: "AWS SESSION TOKEN from console"
116+
name: aws_session_token
117+
type: text
118+
required: true
119+
- label: "AWS REGION"
120+
name: aws_region
121+
type: text
122+
required: true
123+
- label: "AWS ROLE ARN"
124+
name: aws_role_arn
125+
type: text
126+
required: false
127+
128+
- label: "Path to mount inside the docker"
129+
name: path_to_mount
130+
type: text
131+
default: "."
132+
required: true
133+
134+
- label: "Base Path Output"
135+
name: base_path_output
136+
type: text
137+
default: "."
138+
required: false
139+
140+
- label: "Features Terraform Modules"
141+
name: features_terraform_modules
142+
type: text
143+
required: false
144+
145+
- label: "If Runtimes will allow execution of the local-exec command within terraform"
146+
name: localexec_enabled
147+
type: bool
148+
default: false
149+
required: false
150+
151+
- label: "Level tf log provider - info, debug, warn or trace"
152+
name: tf_log_provider
153+
type: text
154+
required: false
155+
156+
- label: Verbose configuration
157+
name: verbose
158+
type: bool
159+
required: false
160+
default: true
161+
help: 'verbose configuration'
162+
163+
- label: stk
164+
name: stk
165+
type: text
166+
required: false
167+
default: stk
168+
help: 'stk'
169+
python:
170+
workdir: .
171+
script: script.py
File renamed without changes.
File renamed without changes.

runtime-run-all/script.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from pathlib import Path
2+
import subprocess
3+
import json
4+
from sys import exit
5+
6+
def check(result):
7+
if (result.returncode == 1):
8+
print(f"Fail to execute {result.args[:100]}...")
9+
exit(1)
10+
11+
12+
def run(metadata):
13+
14+
manifest_action = f'{metadata.inputs.get("base_path_actions")}/runtime-create-manifest-action'
15+
manager_action = f'{metadata.inputs.get("base_path_actions")}/runtime-manager-action'
16+
iac_action = f'{metadata.inputs.get("base_path_actions")}/runtime-iac-action'
17+
container_url_iac = 'stackspot/runtime-job-iac:rc-2.19.0'
18+
deploy_action = f'{metadata.inputs.get("base_path_actions")}/runtime-deploy-action'
19+
container_url_deploy = 'stackspot/runtime-job-deploy:rc-2.36.0'
20+
21+
print(f"-----> Run runtime-create-manifest-action!")
22+
23+
result = subprocess.run([metadata.inputs.get('stk'), 'run', 'action', manifest_action, '--environment', metadata.inputs.get('environment'), '--workspace', metadata.inputs.get('workspace'), '--version_tag', metadata.inputs.get('version_tag'), '--branch', metadata.inputs.get('branch'), '--dynamic_inputs', metadata.inputs.get('dynamic_inputs'), '--verbose', f"{metadata.inputs.get('verbose')}", '--stk', metadata.inputs.get('stk'), '--non-interactive'])
24+
25+
check(result)
26+
27+
print(f"-----> Run runtime-manager-action!")
28+
29+
result = subprocess.run([metadata.inputs.get('stk'), 'run', 'action', manager_action , '--tf_state_bucket_name', metadata.inputs.get('tf_state_bucket_name'), '--tf_state_region', metadata.inputs.get('tf_state_region'), '--iac_bucket_name', metadata.inputs.get('iac_bucket_name'), '--iac_region', metadata.inputs.get('iac_region') , '--verbose', f"{metadata.inputs.get('verbose')}", '--workdir', metadata.inputs.get('workdir'), '--non-interactive'])
30+
31+
check(result)
32+
33+
with open('manager-output.log', 'r') as file:
34+
data = json.loads(file.read().replace("\'", "\""))
35+
36+
for t in data['tasks']:
37+
if t["taskType"] == "IAC_SELF_HOSTED":
38+
39+
print(f"-----> Run runtime-iac-action!")
40+
41+
result = subprocess.run([metadata.inputs.get('stk'), 'run', 'action', iac_action, '--features_level_log', metadata.inputs.get('features_level_log'), '--client_id', metadata.inputs.get('client_id'), '--client_key', metadata.inputs.get('client_key'), '--client_realm', metadata.inputs.get('client_realm'), '--repository_name', metadata.inputs.get('repository_name'), '--aws_access_key_id', metadata.inputs.get('aws_access_key_id'), '--aws_secret_access_key', metadata.inputs.get('aws_secret_access_key'), '--aws_session_token', metadata.inputs.get('aws_session_token'), '--aws_region', metadata.inputs.get('aws_region'), '--run_task_id', t["runTaskId"], '--path_to_mount', metadata.inputs.get('path_to_mount'), '--base_path_output', metadata.inputs.get('base_path_output'), '--container_url', container_url_iac, '--non-interactive'])
42+
43+
check(result)
44+
45+
46+
elif t["taskType"] == "DEPLOY_SELF_HOSTED":
47+
print(f"-----> Run runtime-deploy-action!")
48+
49+
result = subprocess.run([metadata.inputs.get('stk'), 'run', 'action', deploy_action, '--features_level_log', metadata.inputs.get('features_level_log'), '--client_id', metadata.inputs.get('client_id'), '--client_key', metadata.inputs.get('client_key'), '--client_realm', metadata.inputs.get('client_realm'), '--repository_name', metadata.inputs.get('repository_name'), '--aws_access_key_id', metadata.inputs.get('aws_access_key_id'), '--aws_secret_access_key', metadata.inputs.get('aws_secret_access_key'), '--aws_session_token', metadata.inputs.get('aws_session_token'), '--aws_region', metadata.inputs.get('aws_region'), '--run_task_id', t['runTaskId'], '--container_url', container_url_deploy, '--features_terraform_modules', metadata.inputs.get('features_terraform_modules'), '--path_to_mount', metadata.inputs.get('path_to_mount'), '--output_file', 'deploy-output.json', '--localexec_enabled', f"{metadata.inputs.get('localexec_enabled')}", '--tf_log_provider', metadata.inputs.get('tf_log_provider'), '--non-interactive'])
50+
51+
check(result)
52+
else:
53+
print(f"-----> Unsupported task type {t['taskType']}")

0 commit comments

Comments
 (0)