Skip to content

Commit e9f9d5c

Browse files
committed
[NRL-762] Add specific rollback pipeline. Add general activate-stack pipeline. Fix env config scripts to return non-zero on errors
1 parent c0a21c6 commit e9f9d5c

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-2
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Switch Active Stack
2+
run-name: Switch active stack to ${{ inputs.stack_name }} in ${{ inputs.environment }} by ${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
environment:
8+
description: "Environment to activate the stack in"
9+
required: true
10+
default: "dev"
11+
type: environment
12+
13+
stack_name:
14+
description: Name of stack to activate
15+
required: true
16+
type: string
17+
18+
permissions:
19+
id-token: write
20+
contents: read
21+
actions: write
22+
23+
jobs:
24+
activate-stack:
25+
name: Activate ${{ inputs.stack_name }} for ${{ inputs.environment }}
26+
runs-on: [self-hosted, ci]
27+
environment: ${{ inputs.environment }}
28+
29+
steps:
30+
- name: Git clone - ${{ github.ref }}
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.ref }}
34+
35+
- name: Setup asdf cache
36+
uses: actions/cache@v4
37+
with:
38+
path: ~/.asdf
39+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
40+
restore-keys: |
41+
${{ runner.os }}-asdf-
42+
43+
- name: Install asdf
44+
uses: asdf-vm/actions/[email protected]
45+
46+
- name: Configure Management Credentials
47+
uses: aws-actions/configure-aws-credentials@v4
48+
with:
49+
aws-region: eu-west-2
50+
role-to-assume: ${{ secrets.MGMT_ROLE_ARN }}
51+
role-session-name: github-actions-ci-${{ inputs.environment }}-${{ github.run_id}}
52+
53+
- name: Install zip
54+
run: sudo apt-get install zip
55+
56+
- name: Setup Python environment
57+
run: |
58+
poetry install --no-root
59+
source $(poetry env info --path)/bin/activate
60+
61+
- name: Get current environment config
62+
run: |
63+
poetry run python ./scripts/get_env_config.py all ${{ inputs.environment }}
64+
65+
- name: Activate Stack
66+
run: |
67+
poetry run python ./scripts/activate-stack.py ${{ inputs.stack_name }} ${{ inputs.environment }}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Rollback Stack
2+
run-name: Rollback to inactive stack in ${{ inputs.environment }} by ${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
environment:
8+
description: "Environment to rollback the stack in"
9+
required: true
10+
default: "dev"
11+
type: environment
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
actions: write
17+
18+
jobs:
19+
rollback-stack:
20+
name: Rollback to inactive stack for ${{ inputs.environment }}
21+
runs-on: [self-hosted, ci]
22+
environment: ${{ inputs.environment }}
23+
24+
steps:
25+
- name: Git clone - ${{ github.ref }}
26+
uses: actions/checkout@v4
27+
with:
28+
ref: ${{ github.ref }}
29+
30+
- name: Setup asdf cache
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.asdf
34+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
35+
restore-keys: |
36+
${{ runner.os }}-asdf-
37+
38+
- name: Install asdf
39+
uses: asdf-vm/actions/[email protected]
40+
41+
- name: Configure Management Credentials
42+
uses: aws-actions/configure-aws-credentials@v4
43+
with:
44+
aws-region: eu-west-2
45+
role-to-assume: ${{ secrets.MGMT_ROLE_ARN }}
46+
role-session-name: github-actions-ci-${{ inputs.environment }}-${{ github.run_id}}
47+
48+
- name: Install zip
49+
run: sudo apt-get install zip
50+
51+
- name: Setup Python environment
52+
run: |
53+
poetry install --no-root
54+
source $(poetry env info --path)/bin/activate
55+
56+
- name: Get current environment config
57+
run: |
58+
poetry run python ./scripts/get_env_config.py all ${{ inputs.environment }}
59+
60+
- name: Rollback
61+
run: |
62+
inactive_stack_name=$(poetry run python ./scripts/get_env_config.py inactive-stack ${{ inputs.environment }})
63+
poetry run python ./scripts/activate-stack.py ${inactive_stack_name} ${{ inputs.environment }}
64+
65+
- name: "Smoke Test"
66+
run: |
67+
make ENV=${{ inputs.environment }} test-smoke-external

scripts/activate_stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def activate_stack(stack_name: str, env: str, session: any):
131131
)
132132
print(f"Failed to activate stack: {err}", file=sys.stderr)
133133
print(f"Stack trace: {traceback.format_exc()}", file=sys.stderr)
134-
return
134+
sys.exit(1)
135135

136136
print("Updating environment config and unlocking....")
137137
environment_config[CONFIG_INACTIVE_STACK] = current_active_stack

scripts/get_env_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ def main(parameter_name: str, env: str):
1414
response = sm.get_secret_value(SecretId=secret_key)
1515
parameters = json.loads(response["SecretString"])
1616

17-
if parameter_name in parameters:
17+
if parameter_name == "all":
18+
print(parameters)
19+
elif parameter_name in parameters:
1820
print(parameters[parameter_name])
1921
else:
2022
print(
2123
f"Parameter {parameter_name} not found in environment config",
2224
file=sys.stderr,
2325
)
26+
sys.exit(1)
2427

2528

2629
if __name__ == "__main__":

0 commit comments

Comments
 (0)