Skip to main content

Register Application Destruction

In this section, you will learn how to register the destruction of your Application in your pipeline and in StackSpot EDP using the STK CLI.


Overview

To destroy an Application version in StackSpot, you must use your own CI/CD pipeline. To track all Application Workflows in the StackSpot Platform, you need to register the destruction using the STK CLI (StackSpot Command-Line Interface).

To do this, run the command stk register app-destroy in one of the workflow steps that destroys the Application in a specific environment.

This way, you can:

  1. Monitor and track the execution of these Workflows directly in the Platform. Activities related to destruction will be displayed as Activities within the Application.

  2. See in the Application header which versions of Infrastructure and Application were destroyed in the Workspace in the StackSpot Portal.

  3. With the destruction of all Application versions registered in all environments, it is possible to delete your Application entirely from the StackSpot Platform.

Check out the complete destruction flow in the following diagram:

Application destroy flow diagram in StackSpot EDP.Application destroy flow diagram in StackSpot EDP.
warning

Because the deployment of your Application's infrastructure is done via Self-hosted Runtime:

  1. You need to destroy the infrastructure components in your pipeline;
  2. You must execute an empty deploy, that is, with the infrastructure components already destroyed.

With this, you upload an empty Infrastructure version to StackSpot EDP, and it becomes possible to delete your Application via the Portal.

danger

To view all Workflow logs from your Application repository in the Workspace, you need to configure a Webhook in GitHub.
To do this, follow the steps in the guide Configure Webhook to register repository activities on the Activities screen.

Check out the steps to integrate the commands into your pipeline:

Configure Integration in Your Pipeline

Run the command stk register app-destroy in one of the workflow steps that destroys the Application in an environment in your pipeline. See the following example:

stk register app-destroy --env dev --status success 

There are two ways to integrate the commands with your pipeline:

  1. Automated, through a GitHub Action (recommended);
  2. Manually.

See the steps for both ways below:

The Action is available in the StackSpot Marketplace and performs the following automations in your pipeline:

  • Installs the STK CLI in your pipeline (if not already installed);
  • Authenticates with Client_ID, Client_KEY, and REALM;
  • Integrates and runs the commands stk register app-deploy, stk register app-destroy, and stk delete app.

To use it, follow these steps:

Step 1. Configure the CI/CD authentication keys in the repository where your Application is located. To do this, follow the steps in the guide Authenticate via CI/CD.

Step 2. Add the Action to the deploy workflow of your Application. To do this, copy the code snippet below and paste it into your file:

  • Destruction with a success status:
- uses: stack-spot/cli-github-action-run-command@v1.0.0
id: stk-register-app-destroy-success
with:
client_id: ${{ secrets.CLIENT_ID }}
client_key: ${{ secrets.CLIENT_KEY }}
realm: ${{ secrets.REALM }}
command_stk: "register app-destroy --target my-app/ --env dev --status success"
  • Destruction with a failed status:
- uses: stack-spot/cli-github-action-run-command@v1.0.0
id: stk-register-app-destroy-failed
with:
client_id: ${{ secrets.CLIENT_ID }}
client_key: ${{ secrets.CLIENT_KEY }}
realm: ${{ secrets.REALM }}
command_stk: "register app-destroy --target my-app/ --env dev --status failed"

Step 3. Configure the flags of the stk register app-destroy command with the correct variables:

  • target: path to the Application directory;
  • version: version of the Application being destroyed;
  • env: deployment environment;
  • status: deployment status (failed, success).

For more information, visit the stk register app-destroy command page.

info

To register the destruction of the Application, you need to be inside a Workspace. To run commands that require an active Workspace, add the command command_stk with both operations in sequence, as in the example below:

- uses: stack-spot/cli-github-action-run-command@v1.0.0
id: stk-delete-app
with:
client_id: ${{ secrets.CLIENT_ID }}
client_key: ${{ secrets.CLIENT_KEY }}
realm: ${{ secrets.REALM }}
command_stk: "use workspace my-workspace-name && register app-deploy --target my-app/ --version 1.0.0 --env dev --status failed"

2. Integrate Commands in the Pipeline Manually

For your convenience, StackSpot recommends using the Action. But you can configure the steps manually in your pipeline.

Prerequisites

  • Register the Client_ID, Client_Key, and Realm data of your Access Token as GitHub secrets;
  • STK CLI installed in your pipeline;
  • Authenticate in the pipeline;
  • Have an active Workspace in your pipeline.

After following the previous steps, the pipeline file should look like the example below:

.github/workflows/run-cli-commands.yml
name: Run CLI Commands

on: [push]

jobs:
deploy:
runs-on: ubuntu-latest
env:
LANG: C.UTF-8
LANGUAGE: C.UTF-8
LC_ALL: C.UTF-8
PYTHONIOENCODING: utf-8

steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Download STK CLI
shell: bash
run: |
curl \
--fail \
--http2-prior-knowledge \
--location \
--output /tmp/stk.deb \
--silent \
--show-error \
--tlsv1.3 \
https://stk.stackspot.com/installer/linux/stk.deb

- name: Install STK CLI
shell: bash
run: |
sudo dpkg --install /tmp/stk.deb || echo "Installation failed with exit code: $?"

- name: Authenticate StackSpot
run: |
$HOME/.stk/bin/stk login --client-id ${{ secrets.CLIENT_ID }} --client-key ${{ secrets.CLIENT_KEY }} --realm ${{ secrets.CLIENT_REALM }}

- name: Use Workspace
run: |
$HOME/.stk/bin/stk use workspace <workspace>

After configuring all the steps, add the following command execution as the next step in the pipeline to register the destruction of your Application:

- name: Register App Destroy 
run: |
stk register app-destroy --target my-app/ --status success

Next Steps