Skip to content

Commit 13e895a

Browse files
committed
...
1 parent 964046d commit 13e895a

File tree

6 files changed

+39
-306
lines changed

6 files changed

+39
-306
lines changed
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +0,0 @@
1-
Fill out this template to help users use your content. The following information will appear on the Action sections of the StackSpot Portal.
2-
3-
4-
## Action name
5-
6-
Write concisely describing your Action content.
7-
8-
Example:
9-
> This Action shows you how to fill out information to use Actions on the StackSpot platform.
10-
11-
## Requirements
12-
13-
- Describe in a list all the items and necessary action before running this Action
14-
15-
Example:
16-
1. Install the dependencies
17-
2. Create the configuration file
18-
3. Create the **template** folder
19-
20-
## Usage
21-
22-
Add the steps for the user to use your Action:
23-
24-
- What are the inputs?
25-
- Which methods should we know?
26-
- What are the resources?
27-
- Add the Action dependencies, if necessary.
28-
29-
Example:
30-
On your application’s folder, run the **action-doc-template** action and follow the instructions:
31-
1. Execute the command:
32-
`
33-
stk run action /Users/Home/action-doc-template
34-
`
35-
36-
37-
## Release Notes
38-
39-
This section is only necessary if you publish a new Action version. Add what was changed, fixed, and the new features.
40-
41-
Example:
42-
### action-doc-template v1.0.0
43-
44-
#### Features
45-
Added new templates

runtime-deploy-action/script.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,52 @@
1616
FEATURES_TEMPLATES_FILEPATH = "/app/"
1717
FEATURES_BASEPATH_TERRAFORM = "/root/.asdf/shims/terraform"
1818

19-
def check(result: subprocess.CompletedProcess) -> None:
19+
20+
def check(result: subprocess.Popen) -> None:
2021
"""
2122
Checks the result of a subprocess execution. If the return code is non-zero,
2223
it logs an error message and exits the program.
2324
2425
Args:
25-
result (subprocess.CompletedProcess): The result of the subprocess execution.
26+
result (subprocess.Popen): The result of the subprocess execution.
2627
"""
28+
result.wait() # Wait for the process to complete
2729
if result.returncode != 0:
2830
logging.error(f"Failed to execute: {result.args}")
29-
logging.error(f"Error output: {result.stderr}")
31+
logging.error(f"Error output: {result.stderr.read()}")
3032
sys.exit(1)
3133

32-
def run_command(command: List[str]) -> subprocess.CompletedProcess:
34+
35+
def run_command(command: List[str]) -> subprocess.Popen:
3336
"""
34-
Runs a command using subprocess and returns the result.
37+
Runs a command using subprocess.Popen and returns the result.
3538
3639
Args:
3740
command (List[str]): The command to be executed as a list of strings.
3841
3942
Returns:
40-
subprocess.CompletedProcess: The result of the command execution.
43+
subprocess.Popen: The result of the command execution.
4144
"""
4245
try:
4346
logging.info(f"Running command: {' '.join(command)}")
44-
result = subprocess.run(command, capture_output=True, text=True)
45-
check(result)
46-
return result
47+
# Start the process
48+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
49+
50+
# Read and print output in real-time
51+
for line in process.stdout:
52+
print(line, end="") # Print each line as it is produced
53+
54+
# Check the result after the process completes
55+
check(process)
56+
return process
4757
except Exception as e:
4858
logging.error(f"Exception occurred while running command: {command}")
4959
logging.error(str(e))
5060
sys.exit(1)
5161

5262

53-
54-
def run(metadata):
55-
inputs: dict = metadata.inputs
56-
container_url: str = 'stackspot/runtime-job-deploy:latest'
57-
run_task_id: str = inputs["run_task_id"]
58-
output_file: str = inputs.get("output_file") or "deploy-output.json"
59-
path_to_mount: str = inputs.get("path_to_mount") or "."
60-
path_to_mount = f"{path_to_mount}:/app-volume"
61-
63+
def build_flags(inputs: dict) -> list:
64+
6265
docker_flags: dict = dict(
6366
FEATURES_LEVEL_LOG=inputs.get("features_level_log") or "info",
6467
FEATURES_TERRAFORM_LOGPROVIDER=inputs.get("tf_log_provider") or "info",
@@ -81,20 +84,28 @@ def run(metadata):
8184
FEATURES_TEMPLATES_FILEPATH=FEATURES_TEMPLATES_FILEPATH,
8285
FEATURES_BASEPATH_TERRAFORM=FEATURES_BASEPATH_TERRAFORM
8386
)
87+
flags = []
88+
for k, v in docker_flags.items():
89+
flags += ["-e", f"{k}={v}"]
90+
91+
return flags
92+
8493

85-
cmd = [
86-
"docker",
87-
"run", "--rm",
94+
def run(metadata):
95+
inputs: dict = metadata.inputs
96+
container_url: str = 'stackspot/runtime-job-deploy:latest'
97+
run_task_id: str = inputs["run_task_id"]
98+
output_file: str = inputs.get("output_file") or "deploy-output.json"
99+
path_to_mount: str = inputs.get("path_to_mount") or "."
100+
path_to_mount = f"{path_to_mount}:/app-volume"
101+
102+
flags = build_flags(inputs)
103+
cmd = ["docker", "run", "--rm", "-v", path_to_mount] + flags + [
88104
"--entrypoint=/app/stackspot-runtime-job-deploy",
89105
container_url,
90106
"start",
91107
f"--run-task-id={run_task_id}",
92108
f"--output-file={output_file}",
93-
"-v", path_to_mount
94109
]
95-
flags = []
96-
for k, v in docker_flags.items():
97-
flags += ["-e", f"{k}={v}"]
98-
docker_run = cmd + flags
99110

100-
run_command(docker_run)
111+
run_command(cmd)

runtime-deploy-action/templates/script.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +0,0 @@
1-
Fill out this template to help users use your content. The following information will appear on the Action sections of the StackSpot Portal.
2-
3-
4-
## Action name
5-
6-
Write concisely describing your Action content.
7-
8-
Example:
9-
> This Action shows you how to fill out information to use Actions on the StackSpot platform.
10-
11-
## Requirements
12-
13-
- Describe in a list all the items and necessary action before running this Action
14-
15-
Example:
16-
1. Install the dependencies
17-
2. Create the configuration file
18-
3. Create the **template** folder
19-
20-
## Usage
21-
22-
Add the steps for the user to use your Action:
23-
24-
- What are the inputs?
25-
- Which methods should we know?
26-
- What are the resources?
27-
- Add the Action dependencies, if necessary.
28-
29-
Example:
30-
On your application’s folder, run the **action-doc-template** action and follow the instructions:
31-
1. Execute the command:
32-
`
33-
stk run action /Users/Home/action-doc-template
34-
`
35-
36-
37-
## Release Notes
38-
39-
This section is only necessary if you publish a new Action version. Add what was changed, fixed, and the new features.
40-
41-
Example:
42-
### action-doc-template v1.0.0
43-
44-
#### Features
45-
Added new templates

runtime-iac-action/script.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ def run(metadata):
9494
f"--run-task-id={run_task_id}",
9595
f"--base-path-output={base_path_output}",
9696
]
97-
docker_run = cmd
9897

99-
run_command(docker_run)
98+
run_command(cmd)

0 commit comments

Comments
 (0)