Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/lint-quality-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Quality Check
on:
workflow_call:
secrets:
git-org-token:
required: true
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
static_tests:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install linters
run: |
pip install black

- name: Perform lint
run: |
black . --check
88 changes: 88 additions & 0 deletions .github/workflows/stk-quality-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: STK actions quality-check

on:
pull_request:

jobs:
validate-actions:
name: StackSpot Runtime (v2)
runs-on: ubuntu-latest
env:
LANG: C.UTF-8
LANGUAGE: C.UTF-8
LC_ALL: C.UTF-8
PYTHONIOENCODING: utf-8
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- run: sudo apt update && sudo apt install -y curl unzip git jq
name: install dependencies

- name: Setup STK CLI
run: |
curl \
--fail \
--http2-prior-knowledge \
--location \
--output /tmp/stk.deb \
--silent \
--show-error \
--tlsv1.3 \
https://stk.stackspot.com/installer/linux/stk.deb
sudo dpkg --install /tmp/stk.deb || echo installed
rm --force /tmp/stk.deb

- name: Show STK CLI version
run: $HOME/.stk/bin/stk --version

- name: Login StackSpot
run: |
$HOME/.stk/bin/stk login -id ${{ secrets.STK_CLIENT_ID }} -key ${{ secrets.STK_CLIENT_SECRET }} -r ${{ secrets.STK_REALM }}

- name: Validate main action
run: |
$HOME/.stk/bin/stk validate action

- name: Validate runtime-cancel-run-action action
run: |
cd runtime-cancel-run-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-create-manifest-action action
run: |
cd runtime-create-manifest-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-deploy-action action
run: |
cd runtime-deploy-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-destroy-action action
run: |
cd runtime-destroy-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-iac-action action
run: |
cd runtime-iac-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-manager-action action
run: |
cd runtime-manager-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-rollback-action action
run: |
cd runtime-rollback-action
$HOME/.stk/bin/stk validate action

- name: Validate runtime-matrix action
run: |
cd runtime-matrix
$HOME/.stk/bin/stk validate action


45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# workflow-stackspot-actions-runtime-selfhosted
workflow-stackspot-actions-runtime-selfhosted
# StackSpot actions runtimes repository

This repository contains various StackSpot Actions that can be used to automate processes in CI/CD pipelines. Additionally, there is a main action that orchestrates the execution of the other actions, simplifying the integration and management of multiple tasks in a single workflow.

## Repository Structure


## Requirements

Before using the actions in this repository, ensure that you have the following requirements:

* StackSpot CLI installed and configured.

## How to Use

### Deploy

```bash
stk run action <path-where-u-cloned-the-repository> \
--workflow_type deploy \
--environment "<environment>" \
--version_tag "<version-tag>" \
--repository_name "<repository-name>" \
--client_id "<stackspot-client-id>" \
--client_key "<stackspot-client-key>" \
--client_realm "<stackspot-client-realm>" \
--aws_access_key_id "<aws-access-key-id>" \
--aws_secret_access_key "<aws-secret-access-key>" \
--aws_session_token "<aws-session-token>" \
--tf_state_bucket_name "<tf_state_bucket>" \
--iac_bucket_name "<iac_bucket_name>" \
--tf_state_region "<aws-region>" \
--iac_region "<aws-region>" \
--aws_region "<aws-region>"
```

### Cancel

```bash
stk run action <path-where-u-cloned-the-repository> \
--workflow_type cancel \
--run_id "<run_id>"
```
5 changes: 4 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ spec:
inputs:
- label: Workflow type
name: workflow_type
type: text
type: select
items:
- deploy
- cancel
required: true
python:
workdir: .
Expand Down
1 change: 1 addition & 0 deletions docs/en-us/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
18 changes: 10 additions & 8 deletions runtime-cancel-run-action/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from oscli.core.http import post_with_authorization


STK_RUNTIME_MANAGER_DOMAIN = os.getenv("STK_RUNTIME_MANAGER_DOMAIN", "https://runtime-manager.v1.stackspot.com")
STK_RUNTIME_MANAGER_DOMAIN = os.getenv(
"STK_RUNTIME_MANAGER_DOMAIN", "https://runtime-manager.v1.stackspot.com"
)


def run(metadata):
Expand Down Expand Up @@ -40,17 +42,17 @@ def run(metadata):
print the error details and exit the program.

"""

# Extract the RUN_ID from the metadata inputs
RUN_ID = metadata.inputs['run_id']
RUN_ID = metadata.inputs["run_id"]
print(f"> Requesting Run {RUN_ID} to be cancelled")

# Send a POST request to cancel the run
cancel_request = post_with_authorization(
url=f"{STK_RUNTIME_MANAGER_DOMAIN}/v1/run/cancel/{RUN_ID}?force=true",
headers={'Content-Type': 'application/json'},
url=f"{STK_RUNTIME_MANAGER_DOMAIN}/v1/run/cancel/{RUN_ID}?force=true",
headers={"Content-Type": "application/json"},
body=None,
timeout=20
timeout=20,
)

# Handle the response based on the status code
Expand All @@ -66,4 +68,4 @@ def run(metadata):
print("- Status:", cancel_request.status_code)
print("- Error:", cancel_request.reason)
print("- Response:", cancel_request.text)
exit(1)
exit(1)
36 changes: 24 additions & 12 deletions runtime-create-manifest-action/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from typing import List, Optional

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)


def check(result: subprocess.Popen) -> None:
"""
Checks the result of a subprocess execution. If the return code is non-zero,
Checks the result of a subprocess execution. If the return code is non-zero,
it logs an error message and exits the program.

Args:
Expand All @@ -35,12 +37,14 @@ def run_command(command: List[str]) -> subprocess.Popen:
try:
logging.info(f"Running command: {' '.join(command)}")
# Start the process
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

process = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

# Read and print output in real-time
for line in process.stdout:
print(line, end="") # Print each line as it is produced

# Check the result after the process completes
check(process)
return process
Expand All @@ -49,7 +53,7 @@ def run_command(command: List[str]) -> subprocess.Popen:
logging.error(str(e))
sys.exit(1)


def run(metadata) -> None:
"""
Executes a cmd of StackSpot CLI to deploy a plan.
Expand All @@ -58,10 +62,10 @@ def run(metadata) -> None:
metadata (object): An object containing the inputs required for the execution.
"""
stk = sys.argv[0]
environment = metadata.inputs['environment']
version_tag = metadata.inputs['version_tag']
open_api_path: Optional[str] = metadata.inputs.get('open_api_path')
dynamic_inputs: Optional[str] = metadata.inputs.get('dynamic_inputs')
environment = metadata.inputs["environment"]
version_tag = metadata.inputs["version_tag"]
open_api_path: Optional[str] = metadata.inputs.get("open_api_path")
dynamic_inputs: Optional[str] = metadata.inputs.get("dynamic_inputs")

# Prepare optional parameters for the deploy command
optional_params = []
Expand All @@ -71,7 +75,15 @@ def run(metadata) -> None:
optional_params += dynamic_inputs.split()

# Prepare the StackSpot CLI commands
stk_deploy_plan = [stk, "deploy", "plan", "--env", environment, "--version", version_tag] + optional_params
stk_deploy_plan = [
stk,
"deploy",
"plan",
"--env",
environment,
"--version",
version_tag,
] + optional_params

# Execute the commands
run_command(stk_deploy_plan)
run_command(stk_deploy_plan)
1 change: 1 addition & 0 deletions runtime-deploy-action/docs/en-us/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
Loading
Loading