Skip to content

Commit 38d9249

Browse files
authored
Merge pull request #2 from stack-spot/fix/0410-2024
Improvments to actions and add gitlab workflow example
2 parents 4129abb + 72a5592 commit 38d9249

File tree

38 files changed

+681
-1158
lines changed

38 files changed

+681
-1158
lines changed

action.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
schema-version: v3
2+
kind: action
3+
metadata:
4+
name: workflow-main-action
5+
display-name: Workflows main action
6+
description: Responsible to define which workflow will be executed based on type.
7+
version: 1.0.0
8+
spec:
9+
type: python
10+
docs:
11+
en-us: docs/en-us/docs.md
12+
repository: https://github.com/stack-spot/workflow-stackspot-actions-runtime-selfhosted.git
13+
inputs:
14+
- label: Workflow type
15+
name: workflow_type
16+
type: text
17+
required: true
18+
python:
19+
workdir: .
20+
script: script.py

docs/en-us/docs.md

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
image: ubuntu:latest
2+
3+
# Define global variables
4+
variables:
5+
ENVIRONMENT: "staging"
6+
WORKFLOW_REPO_URL: "https://$GITHUB_PAT@github.com/stack-spot/workflow-stackspot-actions-runtime-selfhosted.git"
7+
8+
stages:
9+
- run_stackspot
10+
11+
# Common setup steps for all jobs
12+
before_script:
13+
# Install necessary dependencies
14+
- apt-get -qq update
15+
- apt-get install -y curl git
16+
17+
# Download and install STK CLI
18+
- curl -s -O "https://stk.stackspot.com/installer/linux/stk"
19+
- chmod +x stk
20+
- ./stk init
21+
22+
- export STK=~/.stk/bin/stk
23+
24+
# Verify STK CLI installation
25+
- $STK --version
26+
27+
stk:
28+
stage: run_stackspot
29+
script:
30+
# Export environment variables for StackSpot
31+
- export INPUTS_CLIENT_ID=$STK_CLIENT_ID
32+
- export INPUTS_CLIENT_KEY=$STK_CLIENT_SECRET
33+
- export INPUTS_CLIENT_REALM=$STK_REALM
34+
- export INPUTS_TF_STATE_REGION=$AWS_REGION
35+
- export INPUTS_IAC_REGION=$AWS_REGION
36+
- export INPUTS_AWS_REGION=$AWS_REGION
37+
- export INPUTS_IAC_BUCKET_NAME=$IAC_BUCKET_NAME
38+
- export INPUTS_TF_STATE_BUCKET_NAME=$TF_STATE_BUCKET_NAME
39+
- export INPUTS_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
40+
- export INPUTS_AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
41+
- export INPUTS_AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
42+
- export INPUTS_ENVIRONMENT=$ENVIRONMENT
43+
44+
# Authenticate with StackSpot
45+
- $STK login --client-id $INPUTS_CLIENT_ID --client-key $INPUTS_CLIENT_KEY --realm $INPUTS_CLIENT_REALM
46+
47+
# Use the specified workspace
48+
- $STK use workspace $STK_WORKSPACE
49+
50+
# Clone the workflow repository
51+
- git clone $WORKFLOW_REPO_URL
52+
- cd workflow-stackspot-actions-runtime-selfhosted
53+
- run_action_path=$(pwd)
54+
- cd ..
55+
56+
# Run the StackSpot action
57+
- $STK run action $run_action_path --workflow_type deploy --version_tag $CI_JOB_ID --repository_name $CI_PROJECT_NAME --non-interactive

runtime-cancel-run-action/.stkignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

runtime-cancel-run-action/action.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ metadata:
44
name: runtime-cancel-run-action
55
display-name: runtime-cancel-run-action
66
description: runtime-cancel-run-action
7-
version: 0.0.1
7+
version: 1.0.0
88
spec:
99
type: python
1010
docs:
11-
pt-br: docs/pt-br/docs.md
1211
en-us: docs/en-us/docs.md
1312
repository: https://github.com/stack-spot/workflow-stackspot-actions-runtime-selfhosted.git
1413
inputs:
1514
- label: Run id
1615
name: run_id
1716
type: text
18-
required: false
19-
help: 'Inform execution Id'
17+
pattern: "^[0-9A-HJ-NP-Z]{26}$"
18+
required: true
2019
python:
2120
workdir: .
2221
script: script.py
Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,18 @@
1-
<!--
2-
******************************************
1+
## runtime-cancel-run-action
32

4-
- THIS IS AN EXAMPLE OF HOW TO FILL OUT YOUR DOCUMENTATION OF CONTENT.
3+
Cancel Running Process
54

6-
- FILL OUT THE TEMPLATE BELOW WITH YOUR INFORMATION SO OTHER PEOPLE CAN USE IT. THIS DOCUMENTATION WILL APPEAR ON THE SECTION OF THE STACKSPOT PORTAL.
7-
8-
******************************************
9-
-->
10-
## Action name
11-
12-
<!-- Write concisely describing your Action. -->
5+
This action cancels a running process identified by a `RUN_ID` by sending a cancellation request to the StackSpot Runtime Manager API.
136

147
## Requirements
158

16-
<!--
17-
[This is a guideline; delete this content and write your information outside this markup. <!-- ]
18-
19-
- Describe the requirements that the user needs to know before using the Action.
20-
-->
9+
- The user must have access to the StackSpot Runtime Manager API.
10+
- The `run_id` of the process to be cancelled must be provided.
2111

2212
## Usage
2313

24-
<!--
25-
[This is a guideline; delete this content and write your information outside this markup. <!-- ]
26-
27-
Add the steps for the user to use your Action:
28-
29-
- What are the inputs?
30-
- Which methods should we know?
31-
- What are the resources?
32-
- Add the Action dependencies, if necessary.
33-
34-
Example:
35-
On your application’s folder, run the **action-doc-template** action and follow the instructions:
36-
1. Execute the command:
37-
`
38-
stk run action /Users/Home/action-doc-template
39-
`
40-
-->
41-
42-
## Release Notes
43-
44-
<!--
45-
[This is a guideline; delete this content and write your information outside this markup. <!-- ]
46-
47-
This section is only necessary if you publish a new Action version. Add what was changed, fixed, and the new features.
48-
49-
Example:
50-
### action-doc-template v1.0.0
51-
52-
#### Features
53-
Added new templates
54-
-->
14+
1. Input:
15+
- `run_id`: The ULID of the process to be cancelled.
16+
17+
2. Example usage:
18+
stk run action . --run_id 01J9EKHN5V2R75MGGT8KMEAGH1

runtime-cancel-run-action/docs/pt-br/docs.md

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,69 @@
1+
import os
12
from oscli.core.http import post_with_authorization
23

4+
5+
STK_RUNTIME_MANAGER_DOMAIN = os.getenv("STK_RUNTIME_MANAGER_DOMAIN", "https://runtime-manager.v1.stackspot.com")
6+
7+
38
def run(metadata):
9+
"""
10+
Cancels a running process identified by the provided RUN_ID.
411
5-
RUN_ID = metadata.inputs.get('run_id')
12+
This function sends a cancellation request to the StackSpot Runtime Manager API
13+
to cancel a running process. The cancellation is forced by appending `?force=true`
14+
to the request URL.
615
7-
if RUN_ID == "":
8-
print("- RUN_ID was not provided.")
9-
print(" No need to cancel it.")
10-
exit(0)
16+
Parameters:
17+
-----------
18+
metadata : object
19+
An object containing the inputs for the function. It must include a 'run_id' key
20+
in the `inputs` dictionary, which holds the ULID of the run to be cancelled.
1121
12-
# Calling Cancel Action
13-
print("Cancelling Run...")
22+
Example:
23+
--------
24+
metadata = {
25+
'inputs': {
26+
'run_id': '01F8MECHZX3TBDSZ7XRADM79XE'
27+
}
28+
}
29+
run(metadata)
1430
15-
print(f"Requesting Run {RUN_ID} to be cancelled")
31+
The function will print the status of the cancellation request based on the response
32+
from the API.
1633
17-
cancel_request = post_with_authorization(url=f"https://runtime-manager.v1.stackspot.com/v1/run/cancel/{RUN_ID}?force=true",
18-
headers={'Content-Type': 'application/json' },
19-
body=None,
20-
timeout=20)
21-
22-
if cancel_request.status_code == 202:
23-
print(f"- RUN {RUN_ID} cancelled successfully!")
34+
API Response Status Codes:
35+
--------------------------
36+
- 202: The run was successfully cancelled.
37+
- 404: The run was not found.
38+
- 422: The run is not currently running, so it cannot be aborted.
39+
- Other: Any other status code will be treated as an error, and the function will
40+
print the error details and exit the program.
2441
25-
elif cancel_request.status_code == 404:
26-
print(f"- RUN {RUN_ID} not found.")
42+
"""
43+
44+
# Extract the RUN_ID from the metadata inputs
45+
RUN_ID = metadata.inputs['run_id']
46+
print(f"> Requesting Run {RUN_ID} to be cancelled")
47+
48+
# Send a POST request to cancel the run
49+
cancel_request = post_with_authorization(
50+
url=f"{STK_RUNTIME_MANAGER_DOMAIN}/v1/run/cancel/{RUN_ID}?force=true",
51+
headers={'Content-Type': 'application/json'},
52+
body=None,
53+
timeout=20
54+
)
2755

56+
# Handle the response based on the status code
57+
if cancel_request.status_code == 202:
58+
print(f"> Cancelled successfully!")
59+
elif cancel_request.status_code == 404:
60+
print(f"> Not found.")
2861
elif cancel_request.status_code == 422:
29-
print(f"- RUN {RUN_ID} not currently running. Unable to Abort.")
30-
62+
print(f"> Not currently running. Unable to Abort.")
3163
else:
64+
# Handle any other error response
3265
print("- Error cancelling run")
3366
print("- Status:", cancel_request.status_code)
3467
print("- Error:", cancel_request.reason)
3568
print("- Response:", cancel_request.text)
36-
exit(1)
37-
69+
exit(1)

runtime-create-manifest-action/.stkignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

runtime-create-manifest-action/action.yaml

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ metadata:
66
description: runtime-create-manifest-action
77
version: 0.0.1
88
spec:
9-
type: shell
9+
type: python
1010
docs:
11-
pt-br: docs/pt-br/docs.md
1211
en-us: docs/en-us/docs.md
1312
repository: https://github.com/stack-spot/workflow-stackspot-actions-runtime-selfhosted.git
1413
inputs:
@@ -18,24 +17,12 @@ spec:
1817
required: true
1918
help: 'Inform environment used to deploy'
2019

21-
- label: Workspace used to deploy
22-
name: workspace
23-
type: text
24-
required: true
25-
help: 'Inform workspace used to deploy'
26-
2720
- label: Deploy version tag
2821
name: version_tag
2922
type: text
3023
required: true
3124
help: 'Inform deploy version tag'
3225

33-
- label: Branch to perform checkout in Runtime
34-
name: branch
35-
type: text
36-
required: false
37-
help: 'Inform branch to perform checkout in Runtime'
38-
3926
- label: Path to API file to publish on StackSpot Catalog API
4027
name: open_api_path
4128
type: text
@@ -48,32 +35,9 @@ spec:
4835
required: false
4936
help: '--key1 value1 --key2 value2'
5037

51-
- label: Verbose configuration
52-
name: verbose
53-
type: bool
54-
required: false
55-
default: true
56-
help: 'verbose configuration'
57-
58-
- label: stk
59-
name: stk
60-
type: text
61-
required: false
62-
default: stk
63-
help: 'stk'
64-
65-
66-
shell:
38+
python:
6739
workdir: .
40+
script: script.py
6841

69-
script:
70-
linux: |
71-
chmod +x {{component_path}}/script.sh
72-
sh {{component_path}}/script.sh
73-
mac: |
74-
chmod +x {{component_path}}/script.sh
75-
sh {{component_path}}/script.sh
76-
windows: |
77-
echo "Not supported"
7842

7943

0 commit comments

Comments
 (0)