From 84c40b13ec230f4b13d23f0a798c1597f520ffb9 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Mon, 14 Oct 2024 13:44:12 -0300 Subject: [PATCH 01/34] first commit --- .gitignore | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 202 +++++++++++++++++++++++++++++++++++++++++ action.yaml | 70 +++++++++++++++ deployment.py | 175 ++++++++++++++++++++++++++++++++++++ 4 files changed, 692 insertions(+) create mode 100755 .gitignore create mode 100644 LICENSE create mode 100644 action.yaml create mode 100644 deployment.py diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..dddb152 --- /dev/null +++ b/.gitignore @@ -0,0 +1,245 @@ +# Created by https://www.gitignore.io + +### Go ### +# Binaries for programs and plugins +*.dll +*.so +*.dylib + +/dist/ +**/dist/* +/test/tests.* +/test/coverage.* + +# Test binary, built with " go test -c " +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +# Persistent undo +[._]*.un~ + +### VisualStudioCode ### +.vscode/* + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# End of https://www.gitignore.io/api/macos + +# End of https://www.gitignore.io/api/macos +# Intellij project files +*.iml +*.ipr +*.iws +.idea/ + +# Created by https://www.toptal.com/developers/gitignore/api/maven +# Edit at https://www.toptal.com/developers/gitignore?templates=maven + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# End of https://www.toptal.com/developers/gitignore/api/maven + + +# Created by https://www.toptal.com/developers/gitignore/api/java +# Edit at https://www.toptal.com/developers/gitignore?templates=java + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# End of https://www.toptal.com/developers/gitignore/api/java + +# Created by https://www.toptal.com/developers/gitignore/api/node +# Edit at https://www.toptal.com/developers/gitignore?templates=node + +### Node ### +# Logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# End of https://www.toptal.com/developers/gitignore/api/node + +package-lock.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bd4a22a --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 StackSpot + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..eeec095 --- /dev/null +++ b/action.yaml @@ -0,0 +1,70 @@ +name: 'Runtime Manager Action' + +description: 'Runtime Manager Action' + +inputs: + CLIENT_ID: + description: Account client id + required: true + CLIENT_KEY: + description: Account client secret key + required: true + CLIENT_REALM: + description: Account client realm + required: true + IAC_REGION: + description: Region configuration for iac + required: true + VERBOSE: + description: Verbose configuration + required: false + APPLICATION_FILE: + description: Verbose configuration + required: true + +outputs: + deployment_id: + description: "DEPLOYMENT ID" + value: ${{ steps.deployment.outputs.deployment_id }} + +runs: + using: "composite" + steps: + - name: Check Runner + run: echo 🤖 OS runner is $(uname) + shell: bash + + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4.7.1 + with: + python-version: '3.10' + + - name: Install python libraries + run: pip install requests ruamel-yaml==0.17.33 + shell: bash + + - name: Start StackSpot Cloud Deploy + id: deployment + env: + CLIENT_ID: ${{ inputs.CLIENT_ID }} + CLIENT_KEY: ${{ inputs.CLIENT_KEY }} + CLIENT_REALM: ${{ inputs.CLIENT_REALM }} + VERBOSE: ${{ inputs.VERBOSE }} + APPLICATION_FILE: ${{ inputs.APPLICATION_FILE }} + run: | + if [ ${{runner.os}} != 'Windows' ]; then + python3 ${{ github.action_path }}/deployment.py + elif [ ${{runner.os}} == 'Windows' ]; then + python ${{ github.action_path }}\deployment.py + else + echo "${{runner.os}} not supported" + exit 1 + fi + shell: bash + +branding: + icon: 'terminal' + color: 'gray-dark' \ No newline at end of file diff --git a/deployment.py b/deployment.py new file mode 100644 index 0000000..62fd1e3 --- /dev/null +++ b/deployment.py @@ -0,0 +1,175 @@ +import os +import requests +import json +from ruamel.yaml import YAML +from io import StringIO + + +def yaml() -> YAML: + yml = YAML() + yml.indent(mapping=2, sequence=4, offset=2) + yml.allow_unicode = True + yml.default_flow_style = False + yml.preserve_quotes = True + return yml + + +def safe_load(content: str) -> dict: + yml = yaml() + return yml.load(StringIO(content)) + + +def save_output(name: str, value: str): + with open(os.environ['GITHUB_OUTPUT'], 'a') as output_file: + print(f'{name}={value}', file=output_file) + + +def build_pipeline_url() -> str: + GITHUB_SERVER_URL = os.getenv("GITHUB_SERVER_URL") + GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY") + GITHUB_RUN_ID = os.getenv("GITHUB_RUN_ID") + if None in [GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_RUN_ID]: + print("- Some mandatory GitHub Action environment variable is empty.") + exit(1) + url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/actions/runs/{GITHUB_RUN_ID}" + return url + +CLIENT_ID = os.getenv("CLIENT_ID") +CLIENT_KEY = os.getenv("CLIENT_KEY") +CLIENT_REALM = os.getenv("CLIENT_REALM") +VERBOSE = os.getenv("VERBOSE") +APPLICATION_FILE = os.getenv("APPLICATION_FILE") + +inputs_list = [CLIENT_ID, CLIENT_KEY, CLIENT_REALM] + +if None in inputs_list: + print("- Some mandatory input is empty. Please, check the input list.") + exit(1) + +# Load the YAML content +yaml_data = yaml.safe_load(APPLICATION_FILE) + +# Extract and check values from the YAML structure +application_name = yaml_data['metadata']['name'] +runtime_name = yaml_data['spec']['runtime']['name'] + +application_id = yaml_data['metadata']['id'] +if application_id is None: + print("- Application ID not informed or couldn't be extracted.") + exit(1) +runtime_id = yaml_data['spec']['runtime']['id'] +if runtime_id is None: + print("- Runtime ID not informed or couldn't be extracted.") + exit(1) +image_url = yaml_data['spec']['container']['imageUrl'] +if image_url is None: + print("- Image URL not informed or couldn't be extracted.") + exit(1) +tag = yaml_data['spec']['container']['tag'] +if tag is None: + print("- TAG not informed or couldn't be extracted.") + exit(1) +container_port = yaml_data['spec']['container']['port'] +if container_port is None: + print("- Container Port not informed or couldn't be extracted.") + exit(1) +health_check_path = yaml_data['spec']['container']['healthCheckPath'] +if health_check_path is None: + print("- Health Check Path not informed or couldn't be extracted.") + exit(1) +env_vars = yaml_data['spec']['container']['envVars'] +mem = yaml_data['spec']['runtime']['memory'] +if mem is None: + print("- Memory not informed or couldn't be extracted.") + exit(1) +cpu = yaml_data['spec']['runtime']['cpu'] +if cpu is None: + print("- CPU not informed or couldn't be extracted.") + exit(1) +replica_min = yaml_data['spec']['runtime']['replicaNum']['min'] +if replica_min is None: + print("- Replica MIN config not informed or couldn't be extracted.") + exit(1) +replica_max = yaml_data['spec']['runtime']['replicaNum']['max'] +if replica_min is None: + print("- Replica MAX config not informed or couldn't be extracted.") + exit(1) +replica_cpu = yaml_data['spec']['runtime']['replicaNum']['cpu'] +if replica_min is None: + print("- Replica CPU config not informed or couldn't be extracted.") + exit(1) + +if VERBOSE is not None: + print("- APPLICATION FILE:", yaml_data) + +# Gather authentication data +iam_url_stg = [ f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token"] +iam_headers = {'Content-Type': 'application/x-www-form-urlencoded'} +iam_data = {"client_id": f"{CLIENT_ID}", "grant_type": "client_credentials", "client_secret": f"{CLIENT_KEY}"} + +print("Authenticating...") +r1 = requests.post( + url=iam_url_stg, + headers=iam_headers, + data=iam_data + ) + +if r1.status_code == 200: + d1 = r1.json() + access_token = d1["access_token"] + print("Successfully authenticated!") + + # Create the DEPLOYMENT JSON structure + data = { + "applicationId": application_id, + "action": "DEPLOY", + "containerPort": container_port, + "healthCheckPath": health_check_path, + "envVars": env_vars, + "imageUrl": image_url, + "tag": tag, + "runtimeId": runtime_id, + "mem": mem, + "cpu": cpu, + "replicaNum": { + "min": replica_min, + "max": replica_max, + "cpu": replica_cpu + } + } + + # Convert the dictionary to a JSON string + json_data = json.dumps(data, indent=4) + + if VERBOSE is not None: + print("- DEPLOYMENT REQUEST DATA:", json_data) + + deploy_headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"} + + print(f"Deploying application {application_name} in runtime: {runtime_name}.") + stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" + r2 = requests.post( + url=stackspot_cloud_deployments_url_stg, + headers=deploy_headers, + data=json_data + ) + + if r2.status_code == 201: + d2 = r2.json() + deploymentId = d2["deploymentId"] + save_output('deployment_id', deploymentId) + print(f"- DEPLOYMENT successfully started with ID: {deploymentId}") + + else: + print("- Error starting cloud deployment") + print("- Status:", r2.status_code) + print("- Error:", r2.reason) + print("- Response:", r2.text) + exit(1) + +else: + print("- Error during IAM authentication") + print("- Status:", r1.status_code) + print("- Error:", r1.reason) + print("- Response:", r1.text) + exit(1) \ No newline at end of file From caece2b46878fa87d3c2aa887dc302f8e5185a40 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Mon, 14 Oct 2024 17:04:07 -0300 Subject: [PATCH 02/34] refactor repo --- .github/workflows/deploy.yaml | 24 +++++ README.md | 46 ++++++++- action.yaml | 12 +-- deployment.py | 171 +++++++++++++++++++++------------- 4 files changed, 175 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..a8a7dfc --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,24 @@ +name: Cloud Deploy Action Test STG + +on: + push: + branches: + - feat/1/action-stg + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@feat/1/action-stg + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM }} + CLIENT_ID: ${{ secrets.CLIENT_ID }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY }} + APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml + VERBOSE: true + \ No newline at end of file diff --git a/README.md b/README.md index 5d93fca..f47f773 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,46 @@ # cloud-deploy-action -StackSpot Cloud Github Actions to deploy applications + +GitHub action to authenticate and consume StackSpot Cloud API. + +_**Note**: This action is supported on all runners operating systems (`ubuntu`, `macos`, `windows`)_ + +## 📚 Usage + +### Requirements + +To get the account keys (`CLIENT_ID`, `CLIENT_KEY` and `CLIENT_REALM`), please login using a **ADMIN** user on the [StackSpot Portal](https://stackspot.com), and generate new keys at [https://stackspot.com/en/settings/access-token](https://stackspot.com/en/settings/access-token). + +### Use Case + +```yaml + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@main + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM }} + CLIENT_ID: ${{ secrets.CLIENT_ID }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY }} + APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml + VERBOSE: true +``` + +* * * + +## ▶️ Action Inputs + +Field | Mandatory | Default Value | Observation +------------ | ------------ | ------------- | ------------- +**CLIENT_ID** | YES | N/A | [StackSpot](https://stackspot.com/en/settings/access-token) Client ID. +**CLIENT_KEY** | YES | N/A |[StackSpot](https://stackspot.com/en/settings/access-token) Client KEY. +**CLIENT_REALM** | YES | N/A |[StackSpot](https://stackspot.com/en/settings/access-token) Client Realm. +**APPLICATION_FILE** | YES | N/A | StackSpot application config file (generally in .stk folder) +**VERBOSE** | NO | `false` | Whether to show extra logs during execution. (e.g: `true`). + +* * * + +## License + +[Apache License 2.0](https://github.com/stack-spot/cloud-deploy-action/blob/main/LICENSE) diff --git a/action.yaml b/action.yaml index eeec095..e8908f9 100644 --- a/action.yaml +++ b/action.yaml @@ -1,6 +1,6 @@ -name: 'Runtime Manager Action' +name: 'Cloud Deploy Action' -description: 'Runtime Manager Action' +description: 'Cloud Deploy Action' inputs: CLIENT_ID: @@ -12,9 +12,6 @@ inputs: CLIENT_REALM: description: Account client realm required: true - IAC_REGION: - description: Region configuration for iac - required: true VERBOSE: description: Verbose configuration required: false @@ -22,11 +19,6 @@ inputs: description: Verbose configuration required: true -outputs: - deployment_id: - description: "DEPLOYMENT ID" - value: ${{ steps.deployment.outputs.deployment_id }} - runs: using: "composite" steps: diff --git a/deployment.py b/deployment.py index 62fd1e3..d014a66 100644 --- a/deployment.py +++ b/deployment.py @@ -1,6 +1,7 @@ import os import requests import json +import time from ruamel.yaml import YAML from io import StringIO @@ -19,11 +20,68 @@ def safe_load(content: str) -> dict: return yml.load(StringIO(content)) -def save_output(name: str, value: str): - with open(os.environ['GITHUB_OUTPUT'], 'a') as output_file: - print(f'{name}={value}', file=output_file) +def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): + # Gather authentication data + iam_url_stg = [ f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token"] + iam_headers = {'Content-Type': 'application/x-www-form-urlencoded'} + iam_data = {"client_id": f"{CLIENT_ID}", "grant_type": "client_credentials", "client_secret": f"{CLIENT_KEY}"} + + print("Authenticating...") + r1 = requests.post( + url=iam_url_stg, + headers=iam_headers, + data=iam_data + ) + + if r1.status_code == 200: + d1 = r1.json() + access_token = d1["access_token"] + print("Successfully authenticated!") + return access_token # Return the access token + else: + print("- Error during IAM authentication") + print("- Status:", r1.status_code) + print("- Error:", r1.reason) + print("- Response:", r1.text) + exit(1) +def check_deployment_status(application_name, runtime_name, deployment_id, application_id, deploy_headers): + stackspot_cloud_deployments_details_url_stg = f"https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments/details/{deployment_id}" + application_portal_url_stg = "https://cloud.stg.stackspot.com/applications" + + while True: + print(f"Checking application {application_name} deployment status in runtime: {runtime_name}.") + + # Make the request to check the deployment status + r3 = requests.get( + url=stackspot_cloud_deployments_details_url_stg, + headers=deploy_headers + ) + + if r3.status_code == 200: + d3 = r3.json() + deployment_status = d3.get("deploymentStatus") + + # Check if the deployment status is "UP" + if deployment_status == "UP": + print(f"Deployment concluded for application {application_name} in runtime: {runtime_name}.") + print(f"Check the application status on {application_portal_url_stg}/{application_id}") + break # Exit the loop once the status is "UP" + else: + print(f"Current deployment status: {deployment_status}. Retrying in 5 seconds...") + else: + print("- Error getting deployment details") + print("- Status:", r3.status_code) + print("- Error:", r3.reason) + print("- Response:", r3.text) + exit(1) + + # Wait for 5 seconds before the next polling attempt + time.sleep(5) + + +# To use later to extract github url for logs def build_pipeline_url() -> str: GITHUB_SERVER_URL = os.getenv("GITHUB_SERVER_URL") GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY") @@ -34,6 +92,7 @@ def build_pipeline_url() -> str: url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/actions/runs/{GITHUB_RUN_ID}" return url + CLIENT_ID = os.getenv("CLIENT_ID") CLIENT_KEY = os.getenv("CLIENT_KEY") CLIENT_REALM = os.getenv("CLIENT_REALM") @@ -102,74 +161,52 @@ def build_pipeline_url() -> str: if VERBOSE is not None: print("- APPLICATION FILE:", yaml_data) -# Gather authentication data -iam_url_stg = [ f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token"] -iam_headers = {'Content-Type': 'application/x-www-form-urlencoded'} -iam_data = {"client_id": f"{CLIENT_ID}", "grant_type": "client_credentials", "client_secret": f"{CLIENT_KEY}"} +# Create the DEPLOYMENT JSON structure +data = { + "applicationId": application_id, + "action": "DEPLOY", + "containerPort": container_port, + "healthCheckPath": health_check_path, + "envVars": env_vars, + "imageUrl": image_url, + "tag": tag, + "runtimeId": runtime_id, + "mem": mem, + "cpu": cpu, + "replicaNum": { + "min": replica_min, + "max": replica_max, + "cpu": replica_cpu + } +} -print("Authenticating...") -r1 = requests.post( - url=iam_url_stg, - headers=iam_headers, - data=iam_data - ) +# Convert the dictionary to a JSON string +json_data = json.dumps(data, indent=4) -if r1.status_code == 200: - d1 = r1.json() - access_token = d1["access_token"] - print("Successfully authenticated!") - - # Create the DEPLOYMENT JSON structure - data = { - "applicationId": application_id, - "action": "DEPLOY", - "containerPort": container_port, - "healthCheckPath": health_check_path, - "envVars": env_vars, - "imageUrl": image_url, - "tag": tag, - "runtimeId": runtime_id, - "mem": mem, - "cpu": cpu, - "replicaNum": { - "min": replica_min, - "max": replica_max, - "cpu": replica_cpu - } - } +if VERBOSE is not None: + print("- DEPLOYMENT REQUEST DATA:", json_data) - # Convert the dictionary to a JSON string - json_data = json.dumps(data, indent=4) +access_token = authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY) +deploy_headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"} - if VERBOSE is not None: - print("- DEPLOYMENT REQUEST DATA:", json_data) - - deploy_headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"} - - print(f"Deploying application {application_name} in runtime: {runtime_name}.") - stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" - r2 = requests.post( - url=stackspot_cloud_deployments_url_stg, - headers=deploy_headers, - data=json_data - ) +print(f"Deploying application {application_name} in runtime: {runtime_name}.") +stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" +r2 = requests.post( + url=stackspot_cloud_deployments_url_stg, + headers=deploy_headers, + data=json_data + ) - if r2.status_code == 201: - d2 = r2.json() - deploymentId = d2["deploymentId"] - save_output('deployment_id', deploymentId) - print(f"- DEPLOYMENT successfully started with ID: {deploymentId}") - - else: - print("- Error starting cloud deployment") - print("- Status:", r2.status_code) - print("- Error:", r2.reason) - print("- Response:", r2.text) - exit(1) +if r2.status_code == 201: + d2 = r2.json() + deployment_id = d2["deploymentId"] + print(f"- DEPLOYMENT successfully started with ID: {deployment_id}") else: - print("- Error during IAM authentication") - print("- Status:", r1.status_code) - print("- Error:", r1.reason) - print("- Response:", r1.text) - exit(1) \ No newline at end of file + print("- Error starting cloud deployment") + print("- Status:", r2.status_code) + print("- Error:", r2.reason) + print("- Response:", r2.text) + exit(1) + +check_deployment_status(application_name, runtime_name, deployment_id, application_id, deploy_headers) \ No newline at end of file From e89a888eeccebc9d82636059b6643d65481dd76f Mon Sep 17 00:00:00 2001 From: Guillaume Falourd Date: Mon, 14 Oct 2024 17:08:42 -0300 Subject: [PATCH 03/34] Create application.yaml --- .stk/application.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .stk/application.yaml diff --git a/.stk/application.yaml b/.stk/application.yaml new file mode 100644 index 0000000..b040183 --- /dev/null +++ b/.stk/application.yaml @@ -0,0 +1,24 @@ +apiVersion: v1 +kind: Application +metadata: + id: 01J9YNDVH34W2Y4Y924T5CFVD7 + name: My demo app +spec: + runtime: + id: 01J9C694269APB2TCNAG9CJYVC + name: Runtime 1 + memory: 8 + cpu: 8 + replicaNum: + min: 2 + max: 10 + cpu: 8 + container: + imageUrl: cloud-apps-demo + tag: latest + port: 5000 + healthCheckPath: / + envVars: + - additionalProp1: string + - additionalProp2: string + - additionalProp3: string From 51a25db83906248d5970c13e969a3ad843d19fe1 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 08:31:54 -0300 Subject: [PATCH 04/34] update github workflow secrets --- .github/workflows/deploy.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index a8a7dfc..d19e9ee 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -16,9 +16,9 @@ jobs: uses: stack-spot/cloud-deploy-action@feat/1/action-stg id: deploy with: - CLIENT_REALM: ${{ secrets.CLIENT_REALM }} - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY }} + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml VERBOSE: true \ No newline at end of file From cfa6b094ef74da1c57a4a0ce18d467553c9f7011 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 08:54:59 -0300 Subject: [PATCH 05/34] update application.yaml --- .stk/application.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stk/application.yaml b/.stk/application.yaml index b040183..b7d831e 100644 --- a/.stk/application.yaml +++ b/.stk/application.yaml @@ -14,7 +14,7 @@ spec: max: 10 cpu: 8 container: - imageUrl: cloud-apps-demo + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo tag: latest port: 5000 healthCheckPath: / From 565c38c2939052011838983c15cd3aba3f87b260 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 08:57:33 -0300 Subject: [PATCH 06/34] update safe_load function --- deployment.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deployment.py b/deployment.py index d014a66..c7eb61b 100644 --- a/deployment.py +++ b/deployment.py @@ -3,6 +3,7 @@ import json import time from ruamel.yaml import YAML +from pathlib import Path from io import StringIO @@ -106,7 +107,10 @@ def build_pipeline_url() -> str: exit(1) # Load the YAML content -yaml_data = yaml.safe_load(APPLICATION_FILE) +with open(Path(APPLICATION_FILE), 'r') as file: + yaml_data = file.read() + +yaml_data = safe_load(yaml_data) # Extract and check values from the YAML structure application_name = yaml_data['metadata']['name'] From d996ea76f65a6a4de60595aafecea093827d3f14 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 09:15:35 -0300 Subject: [PATCH 07/34] update python script --- deployment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment.py b/deployment.py index c7eb61b..1e922ac 100644 --- a/deployment.py +++ b/deployment.py @@ -23,7 +23,7 @@ def safe_load(content: str) -> dict: def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): # Gather authentication data - iam_url_stg = [ f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token"] + iam_url_stg = f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token" iam_headers = {'Content-Type': 'application/x-www-form-urlencoded'} iam_data = {"client_id": f"{CLIENT_ID}", "grant_type": "client_credentials", "client_secret": f"{CLIENT_KEY}"} @@ -201,7 +201,7 @@ def build_pipeline_url() -> str: data=json_data ) -if r2.status_code == 201: +if r2.status_code == 200: d2 = r2.json() deployment_id = d2["deploymentId"] print(f"- DEPLOYMENT successfully started with ID: {deployment_id}") From 0ce97c3b9c1a766aced32f2badd171e7868f8888 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 09:27:57 -0300 Subject: [PATCH 08/34] update runner --- .github/workflows/deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index d19e9ee..7daaba4 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -8,7 +8,7 @@ on: jobs: deploy: - runs-on: ubuntu-latest + runs-on: engineering-runners-stg steps: - name: Checkout repo uses: actions/checkout@v4 From 69d3814ee5e1a68e412f397b7a4b2cd49e314949 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 10:39:19 -0300 Subject: [PATCH 09/34] update action logs --- deployment.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/deployment.py b/deployment.py index 1e922ac..970c4c8 100644 --- a/deployment.py +++ b/deployment.py @@ -27,7 +27,7 @@ def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): iam_headers = {'Content-Type': 'application/x-www-form-urlencoded'} iam_data = {"client_id": f"{CLIENT_ID}", "grant_type": "client_credentials", "client_secret": f"{CLIENT_KEY}"} - print("Authenticating...") + print("⚙️ Authenticating...") r1 = requests.post( url=iam_url_stg, headers=iam_headers, @@ -37,10 +37,10 @@ def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): if r1.status_code == 200: d1 = r1.json() access_token = d1["access_token"] - print("Successfully authenticated!") + print("✅ Successfully authenticated!") return access_token # Return the access token else: - print("- Error during IAM authentication") + print("❌ Error during IAM authentication") print("- Status:", r1.status_code) print("- Error:", r1.reason) print("- Response:", r1.text) @@ -52,7 +52,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli application_portal_url_stg = "https://cloud.stg.stackspot.com/applications" while True: - print(f"Checking application {application_name} deployment status in runtime: {runtime_name}.") + print(f'⚙️ Checking application "{application_name}" deployment status in runtime: "{runtime_name}".') # Make the request to check the deployment status r3 = requests.get( @@ -66,11 +66,11 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli # Check if the deployment status is "UP" if deployment_status == "UP": - print(f"Deployment concluded for application {application_name} in runtime: {runtime_name}.") - print(f"Check the application status on {application_portal_url_stg}/{application_id}") + print(f"✅ Deployment concluded for application {application_name} in runtime: {runtime_name}.") + print(f"📊 Check the application status on {application_portal_url_stg}/{application_id}") break # Exit the loop once the status is "UP" else: - print(f"Current deployment status: {deployment_status}. Retrying in 5 seconds...") + print(f"⚙️ Current deployment status: {deployment_status}. Retrying in 5 seconds...") else: print("- Error getting deployment details") print("- Status:", r3.status_code) @@ -103,7 +103,7 @@ def build_pipeline_url() -> str: inputs_list = [CLIENT_ID, CLIENT_KEY, CLIENT_REALM] if None in inputs_list: - print("- Some mandatory input is empty. Please, check the input list.") + print("❌ Some credential is missing!") exit(1) # Load the YAML content @@ -118,52 +118,52 @@ def build_pipeline_url() -> str: application_id = yaml_data['metadata']['id'] if application_id is None: - print("- Application ID not informed or couldn't be extracted.") + print("❌ Application ID not informed or couldn't be extracted.") exit(1) runtime_id = yaml_data['spec']['runtime']['id'] if runtime_id is None: - print("- Runtime ID not informed or couldn't be extracted.") + print("❌ Runtime ID not informed or couldn't be extracted.") exit(1) image_url = yaml_data['spec']['container']['imageUrl'] if image_url is None: - print("- Image URL not informed or couldn't be extracted.") + print("❌ Image URL not informed or couldn't be extracted.") exit(1) tag = yaml_data['spec']['container']['tag'] if tag is None: - print("- TAG not informed or couldn't be extracted.") + print("❌ TAG not informed or couldn't be extracted.") exit(1) container_port = yaml_data['spec']['container']['port'] if container_port is None: - print("- Container Port not informed or couldn't be extracted.") + print("❌ Container Port not informed or couldn't be extracted.") exit(1) health_check_path = yaml_data['spec']['container']['healthCheckPath'] if health_check_path is None: - print("- Health Check Path not informed or couldn't be extracted.") + print("❌ Health Check Path not informed or couldn't be extracted.") exit(1) env_vars = yaml_data['spec']['container']['envVars'] mem = yaml_data['spec']['runtime']['memory'] if mem is None: - print("- Memory not informed or couldn't be extracted.") + print("❌ Memory not informed or couldn't be extracted.") exit(1) cpu = yaml_data['spec']['runtime']['cpu'] if cpu is None: - print("- CPU not informed or couldn't be extracted.") + print("❌ CPU not informed or couldn't be extracted.") exit(1) replica_min = yaml_data['spec']['runtime']['replicaNum']['min'] if replica_min is None: - print("- Replica MIN config not informed or couldn't be extracted.") + print("❌ Replica MIN config not informed or couldn't be extracted.") exit(1) replica_max = yaml_data['spec']['runtime']['replicaNum']['max'] if replica_min is None: - print("- Replica MAX config not informed or couldn't be extracted.") + print("❌ Replica MAX config not informed or couldn't be extracted.") exit(1) replica_cpu = yaml_data['spec']['runtime']['replicaNum']['cpu'] if replica_min is None: - print("- Replica CPU config not informed or couldn't be extracted.") + print("❌ Replica CPU config not informed or couldn't be extracted.") exit(1) if VERBOSE is not None: - print("- APPLICATION FILE:", yaml_data) + print("🕵️ APPLICATION FILE:", yaml_data) # Create the DEPLOYMENT JSON structure data = { @@ -188,12 +188,12 @@ def build_pipeline_url() -> str: json_data = json.dumps(data, indent=4) if VERBOSE is not None: - print("- DEPLOYMENT REQUEST DATA:", json_data) + print("🕵️ DEPLOYMENT REQUEST DATA:", json_data) access_token = authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY) deploy_headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"} -print(f"Deploying application {application_name} in runtime: {runtime_name}.") +print(f'⚙️ Deploying application "{application_name}" in runtime: "{runtime_name}".') stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" r2 = requests.post( url=stackspot_cloud_deployments_url_stg, @@ -204,10 +204,10 @@ def build_pipeline_url() -> str: if r2.status_code == 200: d2 = r2.json() deployment_id = d2["deploymentId"] - print(f"- DEPLOYMENT successfully started with ID: {deployment_id}") + print(f"✅ DEPLOYMENT successfully started with ID: {deployment_id}") else: - print("- Error starting cloud deployment") + print("❌ Error starting cloud deployment") print("- Status:", r2.status_code) print("- Error:", r2.reason) print("- Response:", r2.text) From 2f2462d2bcc60b50838c4bdd02c559d8f9395730 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Tue, 15 Oct 2024 11:41:56 -0300 Subject: [PATCH 10/34] refactor python code --- deployment.py | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/deployment.py b/deployment.py index 970c4c8..7c52f99 100644 --- a/deployment.py +++ b/deployment.py @@ -38,7 +38,7 @@ def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): d1 = r1.json() access_token = d1["access_token"] print("✅ Successfully authenticated!") - return access_token # Return the access token + return access_token else: print("❌ Error during IAM authentication") print("- Status:", r1.status_code) @@ -47,6 +47,29 @@ def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): exit(1) +def deployment(application_name, runtime_name, deploy_headers): + print(f'⚙️ Deploying application "{application_name}" in runtime: "{runtime_name}".') + stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" + r2 = requests.post( + url=stackspot_cloud_deployments_url_stg, + headers=deploy_headers, + data=json_data + ) + + if r2.status_code == 200: + d2 = r2.json() + deployment_id = d2["deploymentId"] + print(f"✅ DEPLOYMENT successfully started with ID: {deployment_id}") + return deployment_id + + else: + print("❌ Error starting cloud deployment") + print("- Status:", r2.status_code) + print("- Error:", r2.reason) + print("- Response:", r2.text) + exit(1) + + def check_deployment_status(application_name, runtime_name, deployment_id, application_id, deploy_headers): stackspot_cloud_deployments_details_url_stg = f"https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments/details/{deployment_id}" application_portal_url_stg = "https://cloud.stg.stackspot.com/applications" @@ -66,7 +89,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli # Check if the deployment status is "UP" if deployment_status == "UP": - print(f"✅ Deployment concluded for application {application_name} in runtime: {runtime_name}.") + print(f'✅ Deployment concluded for application "{application_name}" in runtime: "{runtime_name}".') print(f"📊 Check the application status on {application_portal_url_stg}/{application_id}") break # Exit the loop once the status is "UP" else: @@ -93,6 +116,7 @@ def build_pipeline_url() -> str: url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/actions/runs/{GITHUB_RUN_ID}" return url +# MAIN EXECUTION CLIENT_ID = os.getenv("CLIENT_ID") CLIENT_KEY = os.getenv("CLIENT_KEY") @@ -192,25 +216,5 @@ def build_pipeline_url() -> str: access_token = authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY) deploy_headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"} - -print(f'⚙️ Deploying application "{application_name}" in runtime: "{runtime_name}".') -stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" -r2 = requests.post( - url=stackspot_cloud_deployments_url_stg, - headers=deploy_headers, - data=json_data - ) - -if r2.status_code == 200: - d2 = r2.json() - deployment_id = d2["deploymentId"] - print(f"✅ DEPLOYMENT successfully started with ID: {deployment_id}") - -else: - print("❌ Error starting cloud deployment") - print("- Status:", r2.status_code) - print("- Error:", r2.reason) - print("- Response:", r2.text) - exit(1) - +deployment_id = deployment(application_name, runtime_name, deploy_headers) check_deployment_status(application_name, runtime_name, deployment_id, application_id, deploy_headers) \ No newline at end of file From cb29b079019d4d7d2d56962196c07617efc5e109 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 11:53:32 -0300 Subject: [PATCH 11/34] convert tag to action input --- .github/workflows/deploy.yaml | 1 + .stk/application.yaml | 1 - action.yaml | 6 +++++- deployment.py | 15 ++++++++------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 7daaba4..1215d94 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -20,5 +20,6 @@ jobs: CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml + IMAGE_TAG: demo1 VERBOSE: true \ No newline at end of file diff --git a/.stk/application.yaml b/.stk/application.yaml index b7d831e..9978446 100644 --- a/.stk/application.yaml +++ b/.stk/application.yaml @@ -15,7 +15,6 @@ spec: cpu: 8 container: imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo - tag: latest port: 5000 healthCheckPath: / envVars: diff --git a/action.yaml b/action.yaml index e8908f9..839dd8e 100644 --- a/action.yaml +++ b/action.yaml @@ -16,7 +16,10 @@ inputs: description: Verbose configuration required: false APPLICATION_FILE: - description: Verbose configuration + description: Application file path to use + required: true + IMAGE_TAG: + description: Image tag to use required: true runs: @@ -46,6 +49,7 @@ runs: CLIENT_REALM: ${{ inputs.CLIENT_REALM }} VERBOSE: ${{ inputs.VERBOSE }} APPLICATION_FILE: ${{ inputs.APPLICATION_FILE }} + IMAGE_TAG: ${{ inputs.IMAGE_TAG }} run: | if [ ${{runner.os}} != 'Windows' ]; then python3 ${{ github.action_path }}/deployment.py diff --git a/deployment.py b/deployment.py index 7c52f99..1ce4a47 100644 --- a/deployment.py +++ b/deployment.py @@ -21,6 +21,7 @@ def safe_load(content: str) -> dict: return yml.load(StringIO(content)) +# Call to the StackSpot IAM API endpoint to authenticate def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): # Gather authentication data iam_url_stg = f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token" @@ -47,6 +48,7 @@ def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): exit(1) +# Call to the Cloud Platform API endpoint to start deployment def deployment(application_name, runtime_name, deploy_headers): print(f'⚙️ Deploying application "{application_name}" in runtime: "{runtime_name}".') stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" @@ -70,6 +72,7 @@ def deployment(application_name, runtime_name, deploy_headers): exit(1) +# Call to the Cloud Platform API endpoint to check deployment status def check_deployment_status(application_name, runtime_name, deployment_id, application_id, deploy_headers): stackspot_cloud_deployments_details_url_stg = f"https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments/details/{deployment_id}" application_portal_url_stg = "https://cloud.stg.stackspot.com/applications" @@ -117,12 +120,12 @@ def build_pipeline_url() -> str: return url # MAIN EXECUTION - CLIENT_ID = os.getenv("CLIENT_ID") CLIENT_KEY = os.getenv("CLIENT_KEY") CLIENT_REALM = os.getenv("CLIENT_REALM") VERBOSE = os.getenv("VERBOSE") APPLICATION_FILE = os.getenv("APPLICATION_FILE") +IMAGE_TAG = os.getenv("IMAGE_TAG") inputs_list = [CLIENT_ID, CLIENT_KEY, CLIENT_REALM] @@ -139,7 +142,9 @@ def build_pipeline_url() -> str: # Extract and check values from the YAML structure application_name = yaml_data['metadata']['name'] runtime_name = yaml_data['spec']['runtime']['name'] - +if IMAGE_TAG is None: + print("❌ Image Tag to deploy not informed.") + exit(1) application_id = yaml_data['metadata']['id'] if application_id is None: print("❌ Application ID not informed or couldn't be extracted.") @@ -152,10 +157,6 @@ def build_pipeline_url() -> str: if image_url is None: print("❌ Image URL not informed or couldn't be extracted.") exit(1) -tag = yaml_data['spec']['container']['tag'] -if tag is None: - print("❌ TAG not informed or couldn't be extracted.") - exit(1) container_port = yaml_data['spec']['container']['port'] if container_port is None: print("❌ Container Port not informed or couldn't be extracted.") @@ -197,7 +198,7 @@ def build_pipeline_url() -> str: "healthCheckPath": health_check_path, "envVars": env_vars, "imageUrl": image_url, - "tag": tag, + "tag": IMAGE_TAG, "runtimeId": runtime_id, "mem": mem, "cpu": cpu, From 260fbfb3533ee2906b3a62a12667bb5688fc816c Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 11:57:00 -0300 Subject: [PATCH 12/34] update loop message --- deployment.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deployment.py b/deployment.py index 1ce4a47..bae479f 100644 --- a/deployment.py +++ b/deployment.py @@ -77,8 +77,9 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli stackspot_cloud_deployments_details_url_stg = f"https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments/details/{deployment_id}" application_portal_url_stg = "https://cloud.stg.stackspot.com/applications" + i = 0 while True: - print(f'⚙️ Checking application "{application_name}" deployment status in runtime: "{runtime_name}".') + print(f'⚙️ Checking application "{application_name}" deployment status in runtime: "{runtime_name}" ({i}).') # Make the request to check the deployment status r3 = requests.get( @@ -96,6 +97,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli print(f"📊 Check the application status on {application_portal_url_stg}/{application_id}") break # Exit the loop once the status is "UP" else: + i = i+1 print(f"⚙️ Current deployment status: {deployment_status}. Retrying in 5 seconds...") else: print("- Error getting deployment details") From 18b58bd01bdace9e4a07d835c07f9eab5a3d3c11 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 12:00:06 -0300 Subject: [PATCH 13/34] update cache and action versions --- action.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/action.yaml b/action.yaml index 839dd8e..ce71c71 100644 --- a/action.yaml +++ b/action.yaml @@ -30,15 +30,16 @@ runs: shell: bash - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v4.2.1 - name: Setup Python - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.2.0 with: - python-version: '3.10' + python-version: '3.12' + cache: 'pip' # caching pip dependencies - name: Install python libraries - run: pip install requests ruamel-yaml==0.17.33 + run: pip install requests ruamel-yaml==0.18.6 shell: bash - name: Start StackSpot Cloud Deploy From 460d99ea765c7a4f80a1d15a177369bd75c3c8b9 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 12:05:40 -0300 Subject: [PATCH 14/34] add requirements.txt file --- action.yaml | 10 +++++++++- requirements.txt | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/action.yaml b/action.yaml index ce71c71..f399362 100644 --- a/action.yaml +++ b/action.yaml @@ -39,7 +39,15 @@ runs: cache: 'pip' # caching pip dependencies - name: Install python libraries - run: pip install requests ruamel-yaml==0.18.6 + run: | + if [ ${{runner.os}} != 'Windows' ]; then + python3 ${{ github.action_path }}/requirements.txt + elif [ ${{runner.os}} == 'Windows' ]; then + python ${{ github.action_path }}\requirements.txt + else + echo "${{runner.os}} not supported" + exit 1 + fi shell: bash - name: Start StackSpot Cloud Deploy diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8126316 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +ruamel-yaml==0.18.6 \ No newline at end of file From d98b268479169b35619f7d3cb180318b5acd0a98 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 12:10:06 -0300 Subject: [PATCH 15/34] update requirements.txt usage --- action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index f399362..6c999ff 100644 --- a/action.yaml +++ b/action.yaml @@ -41,9 +41,9 @@ runs: - name: Install python libraries run: | if [ ${{runner.os}} != 'Windows' ]; then - python3 ${{ github.action_path }}/requirements.txt + pip install -r ${{ github.action_path }}/requirements.txt elif [ ${{runner.os}} == 'Windows' ]; then - python ${{ github.action_path }}\requirements.txt + pip install -r ${{ github.action_path }}\requirements.txt else echo "${{runner.os}} not supported" exit 1 From 094d611286302445d1756c0b9ddfa8517b659694 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 13:28:04 -0300 Subject: [PATCH 16/34] update github action workflow with build job --- .github/workflows/deploy.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 1215d94..96a72d1 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -7,11 +7,21 @@ on: workflow_dispatch: jobs: + build: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.imageTag}} + steps: + - name: Build process generating a tag + id: tag + run: echo "imageTag=demo1" >> $GITHUB_OUTPUT + deploy: runs-on: engineering-runners-stg + needs: [build] steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v4.2.1 - name: Deploy repo application uses: stack-spot/cloud-deploy-action@feat/1/action-stg id: deploy @@ -20,6 +30,6 @@ jobs: CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml - IMAGE_TAG: demo1 + IMAGE_TAG: ${{needs.build.outputs.tag}} VERBOSE: true \ No newline at end of file From 6aa0c23454f56513d0eeb255d19956f75c9b131d Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 13:34:18 -0300 Subject: [PATCH 17/34] update displayed message when deployment concluded --- .../{deploy.yaml => deploy-stg.yaml} | 2 +- .stk/application.yaml | 23 ------------------- deployment.py | 2 +- 3 files changed, 2 insertions(+), 25 deletions(-) rename .github/workflows/{deploy.yaml => deploy-stg.yaml} (98%) delete mode 100644 .stk/application.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy-stg.yaml similarity index 98% rename from .github/workflows/deploy.yaml rename to .github/workflows/deploy-stg.yaml index 96a72d1..111a6a6 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -29,7 +29,7 @@ jobs: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml + APPLICATION_FILE: ${{ github.workspace }}/.stk/application-stg.yaml IMAGE_TAG: ${{needs.build.outputs.tag}} VERBOSE: true \ No newline at end of file diff --git a/.stk/application.yaml b/.stk/application.yaml deleted file mode 100644 index 9978446..0000000 --- a/.stk/application.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: v1 -kind: Application -metadata: - id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: My demo app -spec: - runtime: - id: 01J9C694269APB2TCNAG9CJYVC - name: Runtime 1 - memory: 8 - cpu: 8 - replicaNum: - min: 2 - max: 10 - cpu: 8 - container: - imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo - port: 5000 - healthCheckPath: / - envVars: - - additionalProp1: string - - additionalProp2: string - - additionalProp3: string diff --git a/deployment.py b/deployment.py index bae479f..77eb3db 100644 --- a/deployment.py +++ b/deployment.py @@ -93,7 +93,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli # Check if the deployment status is "UP" if deployment_status == "UP": - print(f'✅ Deployment concluded for application "{application_name}" in runtime: "{runtime_name}".') + print(f'✅ Deployment concluded ({deployment_status}) for application "{application_name}" in runtime: "{runtime_name}".') print(f"📊 Check the application status on {application_portal_url_stg}/{application_id}") break # Exit the loop once the status is "UP" else: From 587027067948622da94ca5182efb7fbe752c9741 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 13:39:37 -0300 Subject: [PATCH 18/34] add stk folder --- .github/workflows/deploy-stg.yaml | 2 +- stk/application-stg.yaml | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 stk/application-stg.yaml diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 111a6a6..979fd19 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -29,7 +29,7 @@ jobs: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - APPLICATION_FILE: ${{ github.workspace }}/.stk/application-stg.yaml + APPLICATION_FILE: ${{ github.workspace }}/stk/application-stg.yaml IMAGE_TAG: ${{needs.build.outputs.tag}} VERBOSE: true \ No newline at end of file diff --git a/stk/application-stg.yaml b/stk/application-stg.yaml new file mode 100644 index 0000000..9978446 --- /dev/null +++ b/stk/application-stg.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Application +metadata: + id: 01J9YNDVH34W2Y4Y924T5CFVD7 + name: My demo app +spec: + runtime: + id: 01J9C694269APB2TCNAG9CJYVC + name: Runtime 1 + memory: 8 + cpu: 8 + replicaNum: + min: 2 + max: 10 + cpu: 8 + container: + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + port: 5000 + healthCheckPath: / + envVars: + - additionalProp1: string + - additionalProp2: string + - additionalProp3: string From a1081bb3853ef17d102d39d6c55cacd65c30db9d Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:01:28 -0300 Subject: [PATCH 19/34] update demo files --- README.md | 1 + stk/application-dev.yaml | 23 +++++++++++++++++++++++ stk/application-prd.yaml | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 stk/application-dev.yaml create mode 100644 stk/application-prd.yaml diff --git a/README.md b/README.md index f47f773..230d8cc 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Field | Mandatory | Default Value | Observation **CLIENT_KEY** | YES | N/A |[StackSpot](https://stackspot.com/en/settings/access-token) Client KEY. **CLIENT_REALM** | YES | N/A |[StackSpot](https://stackspot.com/en/settings/access-token) Client Realm. **APPLICATION_FILE** | YES | N/A | StackSpot application config file (generally in .stk folder) +**IMAGE_TAG** | YES | N/A | Image tag to use for deploy **VERBOSE** | NO | `false` | Whether to show extra logs during execution. (e.g: `true`). * * * diff --git a/stk/application-dev.yaml b/stk/application-dev.yaml new file mode 100644 index 0000000..9978446 --- /dev/null +++ b/stk/application-dev.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Application +metadata: + id: 01J9YNDVH34W2Y4Y924T5CFVD7 + name: My demo app +spec: + runtime: + id: 01J9C694269APB2TCNAG9CJYVC + name: Runtime 1 + memory: 8 + cpu: 8 + replicaNum: + min: 2 + max: 10 + cpu: 8 + container: + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + port: 5000 + healthCheckPath: / + envVars: + - additionalProp1: string + - additionalProp2: string + - additionalProp3: string diff --git a/stk/application-prd.yaml b/stk/application-prd.yaml new file mode 100644 index 0000000..9978446 --- /dev/null +++ b/stk/application-prd.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Application +metadata: + id: 01J9YNDVH34W2Y4Y924T5CFVD7 + name: My demo app +spec: + runtime: + id: 01J9C694269APB2TCNAG9CJYVC + name: Runtime 1 + memory: 8 + cpu: 8 + replicaNum: + min: 2 + max: 10 + cpu: 8 + container: + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + port: 5000 + healthCheckPath: / + envVars: + - additionalProp1: string + - additionalProp2: string + - additionalProp3: string From 236b126ba5844ac074cbe3e359c590c48cf41569 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:28:00 -0300 Subject: [PATCH 20/34] update envVars to attend new contract --- .github/workflows/deploy-stg.yaml | 2 +- README.md | 2 +- {stk => stackspot}/application-dev.yaml | 9 ++++++--- {stk => stackspot}/application-prd.yaml | 0 {stk => stackspot}/application-stg.yaml | 9 ++++++--- 5 files changed, 14 insertions(+), 8 deletions(-) rename {stk => stackspot}/application-dev.yaml (74%) rename {stk => stackspot}/application-prd.yaml (100%) rename {stk => stackspot}/application-stg.yaml (74%) diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 979fd19..45aaf7f 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -29,7 +29,7 @@ jobs: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - APPLICATION_FILE: ${{ github.workspace }}/stk/application-stg.yaml + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-stg.yaml IMAGE_TAG: ${{needs.build.outputs.tag}} VERBOSE: true \ No newline at end of file diff --git a/README.md b/README.md index 230d8cc..8eb7c02 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Field | Mandatory | Default Value | Observation **CLIENT_ID** | YES | N/A | [StackSpot](https://stackspot.com/en/settings/access-token) Client ID. **CLIENT_KEY** | YES | N/A |[StackSpot](https://stackspot.com/en/settings/access-token) Client KEY. **CLIENT_REALM** | YES | N/A |[StackSpot](https://stackspot.com/en/settings/access-token) Client Realm. -**APPLICATION_FILE** | YES | N/A | StackSpot application config file (generally in .stk folder) +**APPLICATION_FILE** | YES | N/A | StackSpot application config file (generally in `stackspot` folder) **IMAGE_TAG** | YES | N/A | Image tag to use for deploy **VERBOSE** | NO | `false` | Whether to show extra logs during execution. (e.g: `true`). diff --git a/stk/application-dev.yaml b/stackspot/application-dev.yaml similarity index 74% rename from stk/application-dev.yaml rename to stackspot/application-dev.yaml index 9978446..781caf4 100644 --- a/stk/application-dev.yaml +++ b/stackspot/application-dev.yaml @@ -18,6 +18,9 @@ spec: port: 5000 healthCheckPath: / envVars: - - additionalProp1: string - - additionalProp2: string - - additionalProp3: string + - key: ENV_VAR_1 + value: value1 + - key: ENV_VAR_2 + value: value2 + - key: ENV_VAR_3 + value: value3 diff --git a/stk/application-prd.yaml b/stackspot/application-prd.yaml similarity index 100% rename from stk/application-prd.yaml rename to stackspot/application-prd.yaml diff --git a/stk/application-stg.yaml b/stackspot/application-stg.yaml similarity index 74% rename from stk/application-stg.yaml rename to stackspot/application-stg.yaml index 9978446..781caf4 100644 --- a/stk/application-stg.yaml +++ b/stackspot/application-stg.yaml @@ -18,6 +18,9 @@ spec: port: 5000 healthCheckPath: / envVars: - - additionalProp1: string - - additionalProp2: string - - additionalProp3: string + - key: ENV_VAR_1 + value: value1 + - key: ENV_VAR_2 + value: value2 + - key: ENV_VAR_3 + value: value3 From 752b6c5d622ece080a9e4142c596d27e39acd1b7 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:34:09 -0300 Subject: [PATCH 21/34] update payload --- .github/workflows/deploy-stg.yaml | 4 ++++ deployment.py | 11 ++++++++--- stackspot/application-dev.yaml | 2 +- stackspot/application-prd.yaml | 11 +++++++---- stackspot/application-stg.yaml | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 45aaf7f..1f11fe1 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -6,6 +6,10 @@ on: - feat/1/action-stg workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: runs-on: ubuntu-latest diff --git a/deployment.py b/deployment.py index 77eb3db..7dba760 100644 --- a/deployment.py +++ b/deployment.py @@ -142,11 +142,14 @@ def build_pipeline_url() -> str: yaml_data = safe_load(yaml_data) # Extract and check values from the YAML structure -application_name = yaml_data['metadata']['name'] -runtime_name = yaml_data['spec']['runtime']['name'] + if IMAGE_TAG is None: print("❌ Image Tag to deploy not informed.") exit(1) +application_name = yaml_data['metadata']['name'] +if application_name is None: + print("❌ Application Name not informed or couldn't be extracted.") + exit(1) application_id = yaml_data['metadata']['id'] if application_id is None: print("❌ Application ID not informed or couldn't be extracted.") @@ -155,6 +158,7 @@ def build_pipeline_url() -> str: if runtime_id is None: print("❌ Runtime ID not informed or couldn't be extracted.") exit(1) +runtime_name = yaml_data['spec']['runtime']['name'] image_url = yaml_data['spec']['container']['imageUrl'] if image_url is None: print("❌ Image URL not informed or couldn't be extracted.") @@ -195,8 +199,9 @@ def build_pipeline_url() -> str: # Create the DEPLOYMENT JSON structure data = { "applicationId": application_id, + "applicationName": application_name, "action": "DEPLOY", - "containerPort": container_port, + "containerPort": "{container_port}", "healthCheckPath": health_check_path, "envVars": env_vars, "imageUrl": image_url, diff --git a/stackspot/application-dev.yaml b/stackspot/application-dev.yaml index 781caf4..02a1991 100644 --- a/stackspot/application-dev.yaml +++ b/stackspot/application-dev.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Application metadata: id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: My demo app + name: app spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC diff --git a/stackspot/application-prd.yaml b/stackspot/application-prd.yaml index 9978446..02a1991 100644 --- a/stackspot/application-prd.yaml +++ b/stackspot/application-prd.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Application metadata: id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: My demo app + name: app spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC @@ -18,6 +18,9 @@ spec: port: 5000 healthCheckPath: / envVars: - - additionalProp1: string - - additionalProp2: string - - additionalProp3: string + - key: ENV_VAR_1 + value: value1 + - key: ENV_VAR_2 + value: value2 + - key: ENV_VAR_3 + value: value3 diff --git a/stackspot/application-stg.yaml b/stackspot/application-stg.yaml index 781caf4..02a1991 100644 --- a/stackspot/application-stg.yaml +++ b/stackspot/application-stg.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Application metadata: id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: My demo app + name: app spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC From feff22614e9ea8fb738462d5a9f4ea08e69c3ed2 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:38:56 -0300 Subject: [PATCH 22/34] update app data --- .github/workflows/deploy-stg.yaml | 2 +- stackspot/application-dev.yaml | 6 +++--- stackspot/application-prd.yaml | 6 +++--- stackspot/application-stg.yaml | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 1f11fe1..ce1f871 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -18,7 +18,7 @@ jobs: steps: - name: Build process generating a tag id: tag - run: echo "imageTag=demo1" >> $GITHUB_OUTPUT + run: echo "imageTag=latest" >> $GITHUB_OUTPUT deploy: runs-on: engineering-runners-stg diff --git a/stackspot/application-dev.yaml b/stackspot/application-dev.yaml index 02a1991..583627c 100644 --- a/stackspot/application-dev.yaml +++ b/stackspot/application-dev.yaml @@ -1,8 +1,8 @@ apiVersion: v1 kind: Application metadata: - id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: app + id: 01JAB800C2S97BAZDF2PRDNQD2 + name: cloud-verde spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC @@ -14,7 +14,7 @@ spec: max: 10 cpu: 8 container: - imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-flask-demo port: 5000 healthCheckPath: / envVars: diff --git a/stackspot/application-prd.yaml b/stackspot/application-prd.yaml index 02a1991..583627c 100644 --- a/stackspot/application-prd.yaml +++ b/stackspot/application-prd.yaml @@ -1,8 +1,8 @@ apiVersion: v1 kind: Application metadata: - id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: app + id: 01JAB800C2S97BAZDF2PRDNQD2 + name: cloud-verde spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC @@ -14,7 +14,7 @@ spec: max: 10 cpu: 8 container: - imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-flask-demo port: 5000 healthCheckPath: / envVars: diff --git a/stackspot/application-stg.yaml b/stackspot/application-stg.yaml index 02a1991..583627c 100644 --- a/stackspot/application-stg.yaml +++ b/stackspot/application-stg.yaml @@ -1,8 +1,8 @@ apiVersion: v1 kind: Application metadata: - id: 01J9YNDVH34W2Y4Y924T5CFVD7 - name: app + id: 01JAB800C2S97BAZDF2PRDNQD2 + name: cloud-verde spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC @@ -14,7 +14,7 @@ spec: max: 10 cpu: 8 container: - imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-flask-demo port: 5000 healthCheckPath: / envVars: From 5795948553bb706a575882dd9089148759f10740 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:48:03 -0300 Subject: [PATCH 23/34] update workflows --- .github/workflows/deploy-dev.yaml | 29 +++++++++++++ .github/workflows/deploy-prd.yaml | 29 +++++++++++++ .github/workflows/deploy-stg.yaml | 59 ++++++++++++-------------- .github/workflows/reusable-deploy.yaml | 36 ++++++++++++++++ 4 files changed, 120 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/deploy-dev.yaml create mode 100644 .github/workflows/deploy-prd.yaml create mode 100644 .github/workflows/reusable-deploy.yaml diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml new file mode 100644 index 0000000..aaa868d --- /dev/null +++ b/.github/workflows/deploy-dev.yaml @@ -0,0 +1,29 @@ +name: Deploy DEV + +on: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.imageTag}} + steps: + - name: Build process generating a tag + id: tag + run: echo "imageTag=latest" >> $GITHUB_OUTPUT + + deploy: + needs: [build] + uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-workflow.yaml@feat/1/action-stg + secrets: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + with: + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-dev.yaml + IMAGE_TAG: ${{needs.build.outputs.tag}} \ No newline at end of file diff --git a/.github/workflows/deploy-prd.yaml b/.github/workflows/deploy-prd.yaml new file mode 100644 index 0000000..e75636d --- /dev/null +++ b/.github/workflows/deploy-prd.yaml @@ -0,0 +1,29 @@ +name: Deploy PRD + +on: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.imageTag}} + steps: + - name: Build process generating a tag + id: tag + run: echo "imageTag=latest" >> $GITHUB_OUTPUT + + deploy: + needs: [build] + uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-workflow.yaml@feat/1/action-stg + secrets: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + with: + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-prd.yaml + IMAGE_TAG: ${{needs.build.outputs.tag}} \ No newline at end of file diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index ce1f871..8b7d697 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -1,39 +1,32 @@ -name: Cloud Deploy Action Test STG +name: Deploy STG on: - push: - branches: - - feat/1/action-stg - workflow_dispatch: - + push: + branches: + - feat/1/action-stg + workflow_dispatch: + concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - build: - runs-on: ubuntu-latest - outputs: - tag: ${{ steps.tag.outputs.imageTag}} - steps: - - name: Build process generating a tag - id: tag - run: echo "imageTag=latest" >> $GITHUB_OUTPUT - - deploy: - runs-on: engineering-runners-stg - needs: [build] - steps: - - name: Checkout repo - uses: actions/checkout@v4.2.1 - - name: Deploy repo application - uses: stack-spot/cloud-deploy-action@feat/1/action-stg - id: deploy + build: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.imageTag}} + steps: + - name: Build process generating a tag + id: tag + run: echo "imageTag=latest" >> $GITHUB_OUTPUT + + deploy: + needs: [build] + uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-workflow.yaml@feat/1/action-stg + secrets: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} with: - CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} - CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-stg.yaml - IMAGE_TAG: ${{needs.build.outputs.tag}} - VERBOSE: true - \ No newline at end of file + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-stg.yaml + IMAGE_TAG: ${{needs.build.outputs.tag}} \ No newline at end of file diff --git a/.github/workflows/reusable-deploy.yaml b/.github/workflows/reusable-deploy.yaml new file mode 100644 index 0000000..8bdab3e --- /dev/null +++ b/.github/workflows/reusable-deploy.yaml @@ -0,0 +1,36 @@ +name: StackSpot Cloud Reusable + +on: + workflow_call: + inputs: + APPLICATION_FILE: + required: true + type: string + IMAGE_TAG: + required: true + type: string + secrets: + CLIENT_REALM: + required: true + CLIENT_ID: + required: true + CLIENT_KEY: + required: true + +jobs: + stk-cs-deploy: + runs-on: engineering-runners-stg + steps: + - name: Checkout repo + uses: actions/checkout@v4.2.1 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@feat/1/action-stg + id: deploy + with: + CLIENT_REALM: ${{ inputs.CLIENT_REALM }} + CLIENT_ID: ${{ inputs.CLIENT_ID }} + CLIENT_KEY: ${{ inputs.CLIENT_KEY }} + APPLICATION_FILE: ${{ inputs.APPLICATION_FILE }} + IMAGE_TAG: ${{ inputs.IMAGE_TAG }} + VERBOSE: true + \ No newline at end of file From 9e41a8909c669193163c74e27ef573ea8ed31dad Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:52:11 -0300 Subject: [PATCH 24/34] update README file --- .github/workflows/deploy-stg.yaml | 4 ++-- README.md | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 8b7d697..1133fb0 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -2,8 +2,8 @@ name: Deploy STG on: push: - branches: - - feat/1/action-stg + branches: + - feat/1/action-stg workflow_dispatch: concurrency: diff --git a/README.md b/README.md index 8eb7c02..aa89f6a 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ To get the account keys (`CLIENT_ID`, `CLIENT_KEY` and `CLIENT_REALM`), please l ```yaml steps: - - name: Checkout repo - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4.2.1 - name: Deploy repo application uses: stack-spot/cloud-deploy-action@main id: deploy @@ -23,7 +23,8 @@ To get the account keys (`CLIENT_ID`, `CLIENT_KEY` and `CLIENT_REALM`), please l CLIENT_REALM: ${{ secrets.CLIENT_REALM }} CLIENT_ID: ${{ secrets.CLIENT_ID }} CLIENT_KEY: ${{ secrets.CLIENT_KEY }} - APPLICATION_FILE: ${{ github.workspace }}/.stk/application.yaml + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application.yaml + IMAGE_TAG: latest VERBOSE: true ``` From 1b6afb688971bbad01fe5fba1925bf75dd869d90 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:54:05 -0300 Subject: [PATCH 25/34] update reusable name --- .github/workflows/deploy-stg.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 1133fb0..439f1b9 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -22,7 +22,7 @@ jobs: deploy: needs: [build] - uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-workflow.yaml@feat/1/action-stg + uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg secrets: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} From cf7d8d166b1dc0cd9d79fe0aa836b5e76228b76b Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:54:18 -0300 Subject: [PATCH 26/34] update reusable names --- .github/workflows/deploy-dev.yaml | 2 +- .github/workflows/deploy-prd.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml index aaa868d..bd97f05 100644 --- a/.github/workflows/deploy-dev.yaml +++ b/.github/workflows/deploy-dev.yaml @@ -19,7 +19,7 @@ jobs: deploy: needs: [build] - uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-workflow.yaml@feat/1/action-stg + uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg secrets: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} diff --git a/.github/workflows/deploy-prd.yaml b/.github/workflows/deploy-prd.yaml index e75636d..dc10340 100644 --- a/.github/workflows/deploy-prd.yaml +++ b/.github/workflows/deploy-prd.yaml @@ -19,7 +19,7 @@ jobs: deploy: needs: [build] - uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-workflow.yaml@feat/1/action-stg + uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg secrets: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} From 5b7f1303f59c39984dc81a856ba65351c11f2801 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 15:56:25 -0300 Subject: [PATCH 27/34] update reusable org --- .github/workflows/deploy-dev.yaml | 2 +- .github/workflows/deploy-prd.yaml | 2 +- .github/workflows/deploy-stg.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml index bd97f05..b2f4dd7 100644 --- a/.github/workflows/deploy-dev.yaml +++ b/.github/workflows/deploy-dev.yaml @@ -19,7 +19,7 @@ jobs: deploy: needs: [build] - uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg + uses: stack-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg secrets: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} diff --git a/.github/workflows/deploy-prd.yaml b/.github/workflows/deploy-prd.yaml index dc10340..9a3c7d7 100644 --- a/.github/workflows/deploy-prd.yaml +++ b/.github/workflows/deploy-prd.yaml @@ -19,7 +19,7 @@ jobs: deploy: needs: [build] - uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg + uses: stack-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg secrets: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 439f1b9..6ce43d9 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -22,7 +22,7 @@ jobs: deploy: needs: [build] - uses: stacks-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg + uses: stack-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg secrets: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} From 5bbf8ff88537d6fe44b060dbcef0adce311e6711 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 16:05:01 -0300 Subject: [PATCH 28/34] update workflows --- .github/workflows/deploy-dev.yaml | 22 ++++++++++------ .github/workflows/deploy-prd.yaml | 22 ++++++++++------ .github/workflows/deploy-stg.yaml | 22 ++++++++++------ .github/workflows/reusable-deploy.yaml | 36 -------------------------- 4 files changed, 42 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/reusable-deploy.yaml diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml index b2f4dd7..105d2ed 100644 --- a/.github/workflows/deploy-dev.yaml +++ b/.github/workflows/deploy-dev.yaml @@ -19,11 +19,17 @@ jobs: deploy: needs: [build] - uses: stack-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg - secrets: - CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} - CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - with: - APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-dev.yaml - IMAGE_TAG: ${{needs.build.outputs.tag}} \ No newline at end of file + runs-on: engineering-runners-stg + steps: + - name: Checkout repo + uses: actions/checkout@v4.2.1 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@feat/1/action-stg + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-dev.yaml + IMAGE_TAG: ${{needs.build.outputs.tag}} + VERBOSE: true \ No newline at end of file diff --git a/.github/workflows/deploy-prd.yaml b/.github/workflows/deploy-prd.yaml index 9a3c7d7..72e63d9 100644 --- a/.github/workflows/deploy-prd.yaml +++ b/.github/workflows/deploy-prd.yaml @@ -19,11 +19,17 @@ jobs: deploy: needs: [build] - uses: stack-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg - secrets: - CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} - CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - with: - APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-prd.yaml - IMAGE_TAG: ${{needs.build.outputs.tag}} \ No newline at end of file + runs-on: engineering-runners-stg + steps: + - name: Checkout repo + uses: actions/checkout@v4.2.1 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@feat/1/action-stg + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-prd.yaml + IMAGE_TAG: ${{needs.build.outputs.tag}} + VERBOSE: true \ No newline at end of file diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 6ce43d9..6f5a4ad 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -22,11 +22,17 @@ jobs: deploy: needs: [build] - uses: stack-spot/cloud-deploy-action/.github/workflows/reusable-deploy.yaml@feat/1/action-stg - secrets: - CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} - CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - with: - APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-stg.yaml - IMAGE_TAG: ${{needs.build.outputs.tag}} \ No newline at end of file + runs-on: engineering-runners-stg + steps: + - name: Checkout repo + uses: actions/checkout@v4.2.1 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@feat/1/action-stg + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-stg.yaml + IMAGE_TAG: ${{needs.build.outputs.tag}} + VERBOSE: true \ No newline at end of file diff --git a/.github/workflows/reusable-deploy.yaml b/.github/workflows/reusable-deploy.yaml deleted file mode 100644 index 8bdab3e..0000000 --- a/.github/workflows/reusable-deploy.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: StackSpot Cloud Reusable - -on: - workflow_call: - inputs: - APPLICATION_FILE: - required: true - type: string - IMAGE_TAG: - required: true - type: string - secrets: - CLIENT_REALM: - required: true - CLIENT_ID: - required: true - CLIENT_KEY: - required: true - -jobs: - stk-cs-deploy: - runs-on: engineering-runners-stg - steps: - - name: Checkout repo - uses: actions/checkout@v4.2.1 - - name: Deploy repo application - uses: stack-spot/cloud-deploy-action@feat/1/action-stg - id: deploy - with: - CLIENT_REALM: ${{ inputs.CLIENT_REALM }} - CLIENT_ID: ${{ inputs.CLIENT_ID }} - CLIENT_KEY: ${{ inputs.CLIENT_KEY }} - APPLICATION_FILE: ${{ inputs.APPLICATION_FILE }} - IMAGE_TAG: ${{ inputs.IMAGE_TAG }} - VERBOSE: true - \ No newline at end of file From 76f305f4405e244db2f45fecc45d5d10499f66ec Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Wed, 16 Oct 2024 16:14:47 -0300 Subject: [PATCH 29/34] update python script --- deployment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment.py b/deployment.py index 7dba760..02caf1d 100644 --- a/deployment.py +++ b/deployment.py @@ -201,7 +201,7 @@ def build_pipeline_url() -> str: "applicationId": application_id, "applicationName": application_name, "action": "DEPLOY", - "containerPort": "{container_port}", + "containerPort": f"{container_port}", "healthCheckPath": health_check_path, "envVars": env_vars, "imageUrl": image_url, From 714e644e8180f712cce19e4abdfb2587b1d065a3 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 17 Oct 2024 08:48:00 -0300 Subject: [PATCH 30/34] update action.yaml --- action.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/action.yaml b/action.yaml index 6c999ff..d422a46 100644 --- a/action.yaml +++ b/action.yaml @@ -29,25 +29,13 @@ runs: run: echo 🤖 OS runner is $(uname) shell: bash - - name: Checkout - uses: actions/checkout@v4.2.1 - - name: Setup Python uses: actions/setup-python@v5.2.0 with: python-version: '3.12' - cache: 'pip' # caching pip dependencies - name: Install python libraries - run: | - if [ ${{runner.os}} != 'Windows' ]; then - pip install -r ${{ github.action_path }}/requirements.txt - elif [ ${{runner.os}} == 'Windows' ]; then - pip install -r ${{ github.action_path }}\requirements.txt - else - echo "${{runner.os}} not supported" - exit 1 - fi + run: pip install requests ruamel-yaml==0.18.6 shell: bash - name: Start StackSpot Cloud Deploy From 8622a149f3cd9ee8bee8ffeef9a30d8c7bbc0fc0 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 17 Oct 2024 09:39:37 -0300 Subject: [PATCH 31/34] update branch ref --- .github/workflows/deploy-dev.yaml | 4 ++-- .github/workflows/deploy-prd.yaml | 4 ++-- .github/workflows/deploy-stg.yaml | 5 +---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml index 105d2ed..d7dd826 100644 --- a/.github/workflows/deploy-dev.yaml +++ b/.github/workflows/deploy-dev.yaml @@ -19,12 +19,12 @@ jobs: deploy: needs: [build] - runs-on: engineering-runners-stg + runs-on: engineering-runners-dev steps: - name: Checkout repo uses: actions/checkout@v4.2.1 - name: Deploy repo application - uses: stack-spot/cloud-deploy-action@feat/1/action-stg + uses: ./ id: deploy with: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} diff --git a/.github/workflows/deploy-prd.yaml b/.github/workflows/deploy-prd.yaml index 72e63d9..445e93c 100644 --- a/.github/workflows/deploy-prd.yaml +++ b/.github/workflows/deploy-prd.yaml @@ -19,12 +19,12 @@ jobs: deploy: needs: [build] - runs-on: engineering-runners-stg + runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4.2.1 - name: Deploy repo application - uses: stack-spot/cloud-deploy-action@feat/1/action-stg + uses: ./ id: deploy with: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 6f5a4ad..415a149 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -1,9 +1,6 @@ name: Deploy STG on: - push: - branches: - - feat/1/action-stg workflow_dispatch: concurrency: @@ -27,7 +24,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4.2.1 - name: Deploy repo application - uses: stack-spot/cloud-deploy-action@feat/1/action-stg + uses: ./ id: deploy with: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} From 75221ef9dbeb968a7796770b1465953fc247dc95 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 17 Oct 2024 09:44:25 -0300 Subject: [PATCH 32/34] update urls to PRD --- deployment.py | 16 ++++++++-------- requirements.txt | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 requirements.txt diff --git a/deployment.py b/deployment.py index 02caf1d..0484e73 100644 --- a/deployment.py +++ b/deployment.py @@ -24,13 +24,13 @@ def safe_load(content: str) -> dict: # Call to the StackSpot IAM API endpoint to authenticate def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): # Gather authentication data - iam_url_stg = f"https://iam-auth-ssr.stg.stackspot.com/{CLIENT_REALM}/oidc/oauth/token" + iam_url = f"https://idm.stackspot.com/{CLIENT_REALM}/oidc/oauth/token" iam_headers = {'Content-Type': 'application/x-www-form-urlencoded'} iam_data = {"client_id": f"{CLIENT_ID}", "grant_type": "client_credentials", "client_secret": f"{CLIENT_KEY}"} print("⚙️ Authenticating...") r1 = requests.post( - url=iam_url_stg, + url=iam_url, headers=iam_headers, data=iam_data ) @@ -51,9 +51,9 @@ def authentication(CLIENT_REALM, CLIENT_ID, CLIENT_KEY): # Call to the Cloud Platform API endpoint to start deployment def deployment(application_name, runtime_name, deploy_headers): print(f'⚙️ Deploying application "{application_name}" in runtime: "{runtime_name}".') - stackspot_cloud_deployments_url_stg = "https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments" + stackspot_cloud_deployments_url = "https://cloud-cloud-platform-api.prd.stackspot.com/v1/deployments" r2 = requests.post( - url=stackspot_cloud_deployments_url_stg, + url=stackspot_cloud_deployments_url, headers=deploy_headers, data=json_data ) @@ -74,8 +74,8 @@ def deployment(application_name, runtime_name, deploy_headers): # Call to the Cloud Platform API endpoint to check deployment status def check_deployment_status(application_name, runtime_name, deployment_id, application_id, deploy_headers): - stackspot_cloud_deployments_details_url_stg = f"https://cloud-cloud-platform-api.stg.stackspot.com/v1/deployments/details/{deployment_id}" - application_portal_url_stg = "https://cloud.stg.stackspot.com/applications" + stackspot_cloud_deployments_details_url = f"https://cloud-cloud-platform-api.prd.stackspot.com/v1/deployments/details/{deployment_id}" + application_portal_url = "https://cloud.prd.stackspot.com/applications" i = 0 while True: @@ -83,7 +83,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli # Make the request to check the deployment status r3 = requests.get( - url=stackspot_cloud_deployments_details_url_stg, + url=stackspot_cloud_deployments_details_url, headers=deploy_headers ) @@ -94,7 +94,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli # Check if the deployment status is "UP" if deployment_status == "UP": print(f'✅ Deployment concluded ({deployment_status}) for application "{application_name}" in runtime: "{runtime_name}".') - print(f"📊 Check the application status on {application_portal_url_stg}/{application_id}") + print(f"📊 Check the application status on {application_portal_url}/{application_id}") break # Exit the loop once the status is "UP" else: i = i+1 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8126316..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests -ruamel-yaml==0.18.6 \ No newline at end of file From b2481b5861491c8829d51c92ace8f567a698a498 Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Thu, 17 Oct 2024 09:46:39 -0300 Subject: [PATCH 33/34] update app url on portal --- deployment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment.py b/deployment.py index 0484e73..693301f 100644 --- a/deployment.py +++ b/deployment.py @@ -94,7 +94,7 @@ def check_deployment_status(application_name, runtime_name, deployment_id, appli # Check if the deployment status is "UP" if deployment_status == "UP": print(f'✅ Deployment concluded ({deployment_status}) for application "{application_name}" in runtime: "{runtime_name}".') - print(f"📊 Check the application status on {application_portal_url}/{application_id}") + print(f"📊 Check the application status on {application_portal_url}/{application_id}/?tabIndex=0") break # Exit the loop once the status is "UP" else: i = i+1 From 17f0af5a93f333f2bda87889c0e1108f8253abee Mon Sep 17 00:00:00 2001 From: GuillaumeFalourd Date: Mon, 21 Oct 2024 10:21:24 -0300 Subject: [PATCH 34/34] add other environment examples --- .github/workflows/deploy-dev.yaml | 35 --------------------------- .github/workflows/deploy-prd.yaml | 8 +++---- .github/workflows/deploy-stg.yaml | 2 +- README.md | 40 +++++++++++++++++++++++++++++++ stackspot/application-dev.yaml | 26 -------------------- stackspot/application-prd.yaml | 18 +++++++------- 6 files changed, 54 insertions(+), 75 deletions(-) delete mode 100644 .github/workflows/deploy-dev.yaml delete mode 100644 stackspot/application-dev.yaml diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml deleted file mode 100644 index d7dd826..0000000 --- a/.github/workflows/deploy-dev.yaml +++ /dev/null @@ -1,35 +0,0 @@ -name: Deploy DEV - -on: - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - outputs: - tag: ${{ steps.tag.outputs.imageTag}} - steps: - - name: Build process generating a tag - id: tag - run: echo "imageTag=latest" >> $GITHUB_OUTPUT - - deploy: - needs: [build] - runs-on: engineering-runners-dev - steps: - - name: Checkout repo - uses: actions/checkout@v4.2.1 - - name: Deploy repo application - uses: ./ - id: deploy - with: - CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} - CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} - APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-dev.yaml - IMAGE_TAG: ${{needs.build.outputs.tag}} - VERBOSE: true \ No newline at end of file diff --git a/.github/workflows/deploy-prd.yaml b/.github/workflows/deploy-prd.yaml index 445e93c..bf37ba8 100644 --- a/.github/workflows/deploy-prd.yaml +++ b/.github/workflows/deploy-prd.yaml @@ -24,12 +24,12 @@ jobs: - name: Checkout repo uses: actions/checkout@v4.2.1 - name: Deploy repo application - uses: ./ + uses: stack-spot/cloud-deploy-action@main id: deploy with: - CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} - CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} - CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + CLIENT_REALM: ${{ secrets.CLIENT_REALM_PRD }} + CLIENT_ID: ${{ secrets.CLIENT_ID_PRD }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_PRD }} APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-prd.yaml IMAGE_TAG: ${{needs.build.outputs.tag}} VERBOSE: true \ No newline at end of file diff --git a/.github/workflows/deploy-stg.yaml b/.github/workflows/deploy-stg.yaml index 415a149..6054046 100644 --- a/.github/workflows/deploy-stg.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -24,7 +24,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4.2.1 - name: Deploy repo application - uses: ./ + uses: stack-spot/cloud-deploy-action@stg id: deploy with: CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} diff --git a/README.md b/README.md index aa89f6a..c6a740e 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,43 @@ Field | Mandatory | Default Value | Observation ## License [Apache License 2.0](https://github.com/stack-spot/cloud-deploy-action/blob/main/LICENSE) + +* * * + +## Development + +### STG environment + +```yaml + steps: + - name: Checkout repository + uses: actions/checkout@v4.2.1 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@stg + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_STG }} + CLIENT_ID: ${{ secrets.CLIENT_ID_STG }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_STG }} + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-stg.yaml + IMAGE_TAG: latest + VERBOSE: true +``` + +### DEV environment + +```yaml + steps: + - name: Checkout repository + uses: actions/checkout@v4.2.1 + - name: Deploy repo application + uses: stack-spot/cloud-deploy-action@dev + id: deploy + with: + CLIENT_REALM: ${{ secrets.CLIENT_REALM_DEV }} + CLIENT_ID: ${{ secrets.CLIENT_ID_DEV }} + CLIENT_KEY: ${{ secrets.CLIENT_KEY_DEV }} + APPLICATION_FILE: ${{ github.workspace }}/stackspot/application-dev.yaml + IMAGE_TAG: latest + VERBOSE: true +``` \ No newline at end of file diff --git a/stackspot/application-dev.yaml b/stackspot/application-dev.yaml deleted file mode 100644 index 583627c..0000000 --- a/stackspot/application-dev.yaml +++ /dev/null @@ -1,26 +0,0 @@ -apiVersion: v1 -kind: Application -metadata: - id: 01JAB800C2S97BAZDF2PRDNQD2 - name: cloud-verde -spec: - runtime: - id: 01J9C694269APB2TCNAG9CJYVC - name: Runtime 1 - memory: 8 - cpu: 8 - replicaNum: - min: 2 - max: 10 - cpu: 8 - container: - imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-flask-demo - port: 5000 - healthCheckPath: / - envVars: - - key: ENV_VAR_1 - value: value1 - - key: ENV_VAR_2 - value: value2 - - key: ENV_VAR_3 - value: value3 diff --git a/stackspot/application-prd.yaml b/stackspot/application-prd.yaml index 583627c..58fb081 100644 --- a/stackspot/application-prd.yaml +++ b/stackspot/application-prd.yaml @@ -1,8 +1,8 @@ apiVersion: v1 kind: Application metadata: - id: 01JAB800C2S97BAZDF2PRDNQD2 - name: cloud-verde + id: 01JAFW10F5VD3JY0254HWP0M4T + name: cloud-apps-demo spec: runtime: id: 01J9C694269APB2TCNAG9CJYVC @@ -14,13 +14,13 @@ spec: max: 10 cpu: 8 container: - imageUrl: 300543077521.dkr.ecr.sa-east-1.amazonaws.com/cloud-flask-demo - port: 5000 - healthCheckPath: / + imageUrl: 742799255367.dkr.ecr.sa-east-1.amazonaws.com/cloud-apps-demo + port: 8080 + healthCheckPath: /healthz envVars: - - key: ENV_VAR_1 + - key: ENV_VAR_DEMO1 value: value1 - - key: ENV_VAR_2 + - key: ENV_VAR_DEMO2 value: value2 - - key: ENV_VAR_3 - value: value3 + - key: ENV_VAR_DEMO3 + value: value3 \ No newline at end of file