Skip to content

Commit b6141d7

Browse files
committed
Added undeploy-*.yml workflows for removing deployments
1 parent b232e8a commit b6141d7

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Undeployment Setup
2+
on:
3+
workflow_call:
4+
inputs:
5+
version:
6+
type: string
7+
required: true
8+
description: The version of the model being removed
9+
jobs:
10+
get-spack-env:
11+
name: Get Spack Environment
12+
runs-on: ubuntu-latest
13+
outputs:
14+
model: ${{ steps.get-model.outputs.model }}
15+
env-name: ${{ steps.get-env-name.outputs.env-name }}
16+
steps:
17+
- name: Get Model
18+
id: get-model
19+
# for the cases where the repo name is in uppercase but the package name is lowercase (eg. access-nri/MOM5)
20+
run: echo "model=$(echo ${{ github.event.repository.name }} | tr [:upper:] [:lower:])" >> $GITHUB_OUTPUT
21+
- name: Set Spack Env Name String
22+
id: get-env-name
23+
# replace occurences of '.' with '_' in environment name as spack doesn't support '.'. Ex: 'access-om2-v1.0.0' -> 'access-om2-v1_0_0'.
24+
run: echo "env-name=$(echo '${{ steps.get-model.outputs.model }}-${{ inputs.version }}' | tr '.' '_')" >> $GITHUB_OUTPUT
25+
26+
get-prerelease-deployment-env:
27+
name: Get Prerelease Deployment Environment
28+
runs-on: ubuntu-latest
29+
outputs:
30+
deployment-environments: ${{ steps.get-deployment-environment.outputs.deployment-environments }}
31+
steps:
32+
- name: Checkout Config
33+
uses: actions/checkout@v4
34+
with:
35+
repository: access-nri/build-cd
36+
37+
- name: Get Environments
38+
id: get-deployment-environment
39+
run: echo "deployment-environments=$(jq --compact-output '.prerelease-environments' ./config/deployment-environment.json)" >> $GITHUB_OUTPUT
40+
41+
42+
deployment:
43+
name: Deployment
44+
needs:
45+
- get-spack-env
46+
- get-prerelease-deployment-env
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
deployment-environment: ${{ fromJson(needs.setup-deployment-env.outputs.deployment-environments) }}
51+
uses: access-nri/build-cd/.github/workflows/undeploy-2-start.yml@main
52+
with:
53+
deployment-environment: ${{ matrix.deployment-environment }}
54+
env-name: ${{ needs.setup-spack-env.outputs.env-name }}
55+
secrets: inherit
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Undeployment Start
2+
on:
3+
workflow_call:
4+
inputs:
5+
env-name:
6+
type: string
7+
required: true
8+
description: The spack-env-compliant environment name for the model
9+
deployment-environment:
10+
type: string
11+
required: true
12+
description: The GitHub deployment environment name
13+
jobs:
14+
undeploy-from-environment:
15+
name: Undeploy ${{ inputs.env-name }} from ${{ inputs.deployment-environment }}
16+
runs-on: ubuntu-latest
17+
environment: ${{ inputs.deployment-environment }}
18+
steps:
19+
- name: Setup SSH
20+
id: ssh
21+
uses: access-nri/actions/.github/actions/setup-ssh@main
22+
with:
23+
private-key: ${{ secrets.SSH_KEY }}
24+
hosts: |
25+
${{ secrets.HOST }}
26+
${{ secrets.HOST_DATA }}
27+
28+
- name: Undeploy
29+
# ssh into deployment environment, create and activate the env, install the spack.yaml.
30+
id: undeploy
31+
run: |
32+
ssh ${{ secrets.USER}}@${{ secrets.HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
33+
34+
EOT
35+
36+
- name: Undeploy Status Notifier
37+
if: always()
38+
run: |
39+
if [[ "${{ steps.undeploy.outcome }}" == "success" ]]; then
40+
echo "::notice::Deployment ${{ inputs.env-name }} was successfully removed from ${{ inputs.deployment-environment }}"
41+
else
42+
echo "::error::Deployment ${{ inputs.env-name }} couldn't be removed from ${{ inputs.deployment-environment}}. Please check manually."
43+
fi

0 commit comments

Comments
 (0)