Skip to content

Commit f78ffe9

Browse files
committed
...
1 parent aed885e commit f78ffe9

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

runtime-create-manifest-action/script.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,50 @@
66
# Configure logging
77
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
88

9-
def check(result: subprocess.CompletedProcess) -> None:
9+
10+
def check(result: subprocess.Popen) -> None:
1011
"""
1112
Checks the result of a subprocess execution. If the return code is non-zero,
1213
it logs an error message and exits the program.
1314
1415
Args:
15-
result (subprocess.CompletedProcess): The result of the subprocess execution.
16+
result (subprocess.Popen): The result of the subprocess execution.
1617
"""
18+
result.wait() # Wait for the process to complete
1719
if result.returncode != 0:
1820
logging.error(f"Failed to execute: {result.args}")
19-
logging.error(f"Error output: {result.stderr}")
21+
logging.error(f"Error output: {result.stderr.read()}")
2022
sys.exit(1)
2123

22-
def run_command(command: List[str]) -> subprocess.CompletedProcess:
24+
25+
def run_command(command: List[str]) -> subprocess.Popen:
2326
"""
24-
Runs a command using subprocess and returns the result.
27+
Runs a command using subprocess.Popen and returns the result.
2528
2629
Args:
2730
command (List[str]): The command to be executed as a list of strings.
2831
2932
Returns:
30-
subprocess.CompletedProcess: The result of the command execution.
33+
subprocess.Popen: The result of the command execution.
3134
"""
3235
try:
3336
logging.info(f"Running command: {' '.join(command)}")
34-
result = subprocess.run(command, capture_output=True, text=True)
35-
check(result)
36-
return result
37+
# Start the process
38+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
39+
40+
# Read and print output in real-time
41+
for line in process.stdout:
42+
print(line, end="") # Print each line as it is produced
43+
44+
# Check the result after the process completes
45+
check(process)
46+
return process
3747
except Exception as e:
3848
logging.error(f"Exception occurred while running command: {command}")
3949
logging.error(str(e))
4050
sys.exit(1)
4151

52+
4253
def run(metadata) -> None:
4354
"""
4455
Executes a series of StackSpot CLI commands to set the workspace and deploy a plan.

runtime-deploy-action/script.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import subprocess
44
import logging
5+
from typing import List
56

67
# Configure logging
78
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -84,7 +85,7 @@ def run(metadata):
8485
cmd = [
8586
"docker",
8687
"run", "--rm",
87-
"--entrypoint=/app/stackspot-runtime-job-deploy"
88+
"--entrypoint=/app/stackspot-runtime-job-deploy",
8889
container_url,
8990
"start",
9091
f"--run-task-id={run_task_id}",

runtime-iac-action/script.py

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import subprocess
44
import logging
5+
from typing import List
56

67
# Configure logging
78
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -11,75 +12,88 @@
1112
STK_RUNTIME_MANAGER_DOMAIN = os.getenv("STK_RUNTIME_MANAGER_DOMAIN", "https://runtime-manager.v1.stackspot.com")
1213

1314

14-
def check(result: subprocess.CompletedProcess) -> None:
15+
def check(result: subprocess.Popen) -> None:
1516
"""
1617
Checks the result of a subprocess execution. If the return code is non-zero,
1718
it logs an error message and exits the program.
1819
1920
Args:
20-
result (subprocess.CompletedProcess): The result of the subprocess execution.
21+
result (subprocess.Popen): The result of the subprocess execution.
2122
"""
23+
result.wait() # Wait for the process to complete
2224
if result.returncode != 0:
2325
logging.error(f"Failed to execute: {result.args}")
24-
logging.error(f"Error output: {result.stderr}")
26+
logging.error(f"Error output: {result.stderr.read()}")
2527
sys.exit(1)
2628

27-
def run_command(command: List[str]) -> subprocess.CompletedProcess:
29+
30+
def run_command(command: List[str]) -> subprocess.Popen:
2831
"""
29-
Runs a command using subprocess and returns the result.
32+
Runs a command using subprocess.Popen and returns the result.
3033
3134
Args:
3235
command (List[str]): The command to be executed as a list of strings.
3336
3437
Returns:
35-
subprocess.CompletedProcess: The result of the command execution.
38+
subprocess.Popen: The result of the command execution.
3639
"""
3740
try:
3841
logging.info(f"Running command: {' '.join(command)}")
39-
result = subprocess.run(command, capture_output=True, text=True)
40-
check(result)
41-
return result
42+
# Start the process
43+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
44+
45+
# Read and print output in real-time
46+
for line in process.stdout:
47+
print(line, end="") # Print each line as it is produced
48+
49+
# Check the result after the process completes
50+
check(process)
51+
return process
4252
except Exception as e:
4353
logging.error(f"Exception occurred while running command: {command}")
4454
logging.error(str(e))
4555
sys.exit(1)
4656

4757

48-
49-
def run(metadata):
50-
inputs: dict = metadata.inputs
51-
container_url: str = 'stackspot/runtime-job-iac:latest'
52-
run_task_id: str = inputs["run_task_id"]
53-
base_path_output: str = inputs.get("base_path_output") or "."
54-
path_to_mount: str = inputs.get("path_to_mount") or "."
55-
path_to_mount = f"{path_to_mount}:/app-volume"
56-
58+
def build_flags(inputs: dict) -> list:
5759
docker_flags: dict = dict(
5860
FEATURES_LEVEL_LOG=inputs.get("features_level_log") or "info",
5961

62+
REPOSITORY_NAME=inputs["repository_name"],
6063
AUTHENTICATE_CLIENT_ID=inputs["client_id"],
6164
AUTHENTICATE_CLIENT_SECRET=inputs["client_key"],
6265
AUTHENTICATE_CLIENT_REALMS=inputs["client_realm"],
63-
REPOSITORY_NAME=inputs["repository_name"],
66+
AWS_ACCESS_KEY_ID=inputs['aws_access_key_id'],
67+
AWS_SECRET_ACCESS_KEY=inputs['aws_secret_access_key'],
68+
AWS_SESSION_TOKEN=inputs['aws_session_token'],
6469
AWS_REGION=inputs["aws_region"],
6570

6671
AUTHENTICATE_URL=STK_IAM_DOMAIN,
6772
FEATURES_API_MANAGER=STK_RUNTIME_MANAGER_DOMAIN,
6873
)
74+
flags = []
75+
for k, v in docker_flags.items():
76+
flags += ["-e", f"{k}={v}"]
77+
78+
return flags
79+
80+
81+
def run(metadata):
82+
inputs: dict = metadata.inputs
83+
container_url: str = 'stackspot/runtime-job-iac:latest'
84+
run_task_id: str = inputs["run_task_id"]
85+
base_path_output: str = inputs.get("base_path_output") or "."
86+
path_to_mount: str = inputs.get("path_to_mount") or "."
87+
path_to_mount = f"{path_to_mount}:/app-volume"
6988

70-
cmd = [
71-
"docker",
72-
"run", "--rm",
89+
flags = build_flags(inputs)
90+
cmd = ["docker", "run", "--rm", "-v", path_to_mount] + flags + [
7391
"--entrypoint=/app/stackspot-runtime-job-iac",
7492
container_url,
7593
"start",
7694
f"--run-task-id={run_task_id}",
7795
f"--base-path-output={base_path_output}",
78-
"-v", path_to_mount
7996
]
80-
flags = []
81-
for k, v in docker_flags.items():
82-
flags += ["-e", f"{k}={v}"]
83-
docker_run = cmd + flags
97+
docker_run = cmd
8498

8599
run_command(docker_run)

runtime-run-all/script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ def run(metadata):
3333
DEPLOY_SELF_HOSTED=lambda **i: run_action("runtime-deploy-action", **i),
3434
)
3535
for t in data['tasks']:
36-
runner = task_runners.get(t["taskType"])
37-
runner(run_task_id=t["runTaskId"])
36+
runner = task_runners.get(t["taskType"])
37+
runner and runner(run_task_id=t["runTaskId"])

0 commit comments

Comments
 (0)