Skip to content

Commit f58945c

Browse files
CCM-7035 Adding auto deploy on release
1 parent ec2fdee commit f58945c

File tree

6 files changed

+188
-74
lines changed

6 files changed

+188
-74
lines changed

.github/workflows/pr_create_dynamic_env.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
}
4141
}')
4242
43-
curl -L \
43+
curl --fail -L \
4444
-X POST \
4545
-H "Accept: application/vnd.github+json" \
4646
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \

.github/workflows/pr_merge.yaml

Lines changed: 22 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,34 @@
11
name: PR Merged
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
types: [closed]
7+
branches:
8+
- main
69

710
concurrency:
811
group: ${{ github.workflow }}-${{ github.ref }}
912
cancel-in-progress: false
1013

1114
jobs:
12-
destroy-dynamic-environment:
13-
name: Destroy Dynamic Environment
14-
runs-on: ubuntu-latest
15-
16-
steps:
17-
- name: Trigger nhs-notify-internal dynamic environment workflow
18-
shell: bash
19-
run: |
20-
set -x
21-
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
22-
23-
DISPATCH_EVENT=$(jq -ncM \
24-
--arg infraRepoName "${this_repo_name}" \
25-
--arg releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
26-
--arg targetEnvironment "pr${{ github.event.number }}" \
27-
--arg targetAccountGroup "nhs-notify-template-management-dev" \
28-
--arg targetComponent "branch" \
29-
--arg terraformAction "destroy" \
30-
--arg overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
31-
'{ "ref": "main",
32-
"inputs": {
33-
"infraRepoName": $infraRepoName,
34-
"releaseVersion", $releaseVersion,
35-
"targetEnvironment", $targetEnvironment,
36-
"targetAccountGroup", $targetAccountGroup,
37-
"targetComponent", $targetComponent,
38-
"terraformAction", $terraformAction,
39-
"overrides", $overrides,
40-
}
41-
}')
42-
43-
curl -L \
44-
-X POST \
45-
-H "Accept: application/vnd.github+json" \
46-
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
47-
-H "X-GitHub-Api-Version: 2022-11-28" \
48-
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
49-
-d "${DISPATCH_EVENT}"
50-
5115
deploy-main:
52-
name: Deploy changes to main
53-
runs-on: ubuntu-latest
54-
steps:
55-
- name: Trigger nhs-notify-internal static environment workflow deployment
56-
shell: bash
57-
run: |
58-
set -x
59-
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
60-
61-
DISPATCH_EVENT=$(jq -ncM \
62-
--arg infraRepoName "${this_repo_name}" \
63-
--arg releaseVersion "main" \
64-
--arg targetEnvironment "main" \
65-
--arg targetAccountGroup "nhs-notify-template-management-dev" \
66-
--arg targetComponent "app" \
67-
--arg terraformAction "apply" \
68-
'{ "ref": "main",
69-
"inputs": {
70-
"infraRepoName": $infraRepoName,
71-
"releaseVersion", $releaseVersion,
72-
"targetEnvironment", $targetEnvironment,
73-
"targetAccountGroup", $targetAccountGroup,
74-
"targetComponent", $targetComponent,
75-
"terraformAction", $terraformAction
76-
}
77-
}')
78-
79-
curl -L \
80-
-X POST \
81-
-H "Accept: application/vnd.github+json" \
82-
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
83-
-H "X-GitHub-Api-Version: 2022-11-28" \
84-
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-static-env.yaml/dispatches \
85-
-d "${DISPATCH_EVENT}"
16+
name: Deploy changes to main in dev AWS account
17+
18+
permissions:
19+
id-token: write
20+
contents: read
21+
22+
strategy:
23+
max-parallel: 1
24+
matrix:
25+
component: [dnsroot]
26+
27+
uses: ./.github/workflows/trigger_internal_repo_build.yaml
28+
secrets: inherit
29+
with:
30+
release_version: main
31+
tf_environment: "main"
32+
tf_group: "nhs-notify-template-management-dev"
33+
tf_component: ${{ matrix.component }}
34+
tf_action: "apply"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Github Release Created
2+
3+
on:
4+
release:
5+
types: ["published"] # Inherits all input defaults
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
deploy-main:
13+
name: Deploy changes to main in nonprod AWS Account
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
max-parallel: 1
18+
matrix:
19+
component: [dnsroot]
20+
21+
steps:
22+
- name: Trigger nhs-notify-internal static environment workflow deployments
23+
uses: ./.github/workflows/trigger_internal_repo_build.yaml
24+
with:
25+
secrets: inherit
26+
release_version: ${{ github.event.release.tag_name }}
27+
tf_environment: "main"
28+
tf_group: "nhs-notify-template-management-nonprod"
29+
tf_component: ${{ matrix.component }}
30+
tf_action: "apply"
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Trigger Notify Internal Infrastructure Deployment
2+
## Sub workflow which plans and deploys Notify components as part of the workflow.
3+
## Review Gates may be required to proceed on triggered builds.
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
release_version:
9+
type: string
10+
description: The Github release version, commit, or tag.
11+
default: main
12+
tf_environment:
13+
type: string
14+
description: The Terraform environment to deploy
15+
default: main
16+
tf_component:
17+
type: string
18+
description: The Terraform component to deploy
19+
required: true
20+
tf_group:
21+
type: string
22+
description: The Terraform group to deploy
23+
required: true
24+
tf_action:
25+
type: string
26+
description: The Terraform component to deploy
27+
default: plan
28+
29+
concurrency:
30+
group: ${{ inputs.tf_environment }}-${{ inputs.tf_group }}-${{ inputs.tf_component }}-${{ inputs.tf_action }}
31+
32+
jobs:
33+
trigger:
34+
runs-on: ubuntu-latest
35+
36+
permissions:
37+
id-token: write
38+
contents: read
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Trigger nhs-notify-internal static environment workflow deployment
44+
shell: bash
45+
run: |
46+
set -x
47+
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
48+
49+
DISPATCH_EVENT=$(jq -ncM \
50+
--arg infraRepoName "${this_repo_name}" \
51+
--arg releaseVersion ${{ inputs.release_version }} \
52+
--arg targetEnvironment ${{ inputs.tf_environment }} \
53+
--arg targetAccountGroup ${{ inputs.tf_group }} \
54+
--arg targetComponent ${{ inputs.tf_component }} \
55+
--arg terraformAction ${{ inputs.tf_action }} \
56+
'{ "ref": "main",
57+
"inputs": {
58+
"infraRepoName": $infraRepoName,
59+
"releaseVersion", $releaseVersion,
60+
"targetEnvironment", $targetEnvironment,
61+
"targetAccountGroup", $targetAccountGroup,
62+
"targetComponent", $targetComponent,
63+
"terraformAction", $terraformAction
64+
}
65+
}')
66+
67+
# Trigger The workflow
68+
curl -L \
69+
--fail \
70+
--silent \
71+
-X POST \
72+
-H "Accept: application/vnd.github+json" \
73+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
74+
-H "X-GitHub-Api-Version: 2022-11-28" \
75+
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-static-env.yaml/dispatches \
76+
-d "${DISPATCH_EVENT}"
77+
78+
echo "Workflow triggered successfully. HTTP response. Waiting for the workflow to complete.."
79+
80+
# Poll GitHub API to check the workflow status
81+
run_id=""
82+
for i in {1..12}; do
83+
run_id=$(curl -s \
84+
-H "Accept: application/vnd.github+json" \
85+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
86+
-H "X-GitHub-Api-Version: 2022-11-28" \
87+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \
88+
| jq -r '.workflow_runs[0].id')
89+
90+
if [[ -n "$run_id" && "$run_id" != null ]]; then
91+
echo "Found workflow run with ID: $run_id"
92+
break
93+
fi
94+
95+
echo "Waiting for workflow to start..."
96+
sleep 10
97+
done
98+
99+
if [[ -z "$run_id" || "$run_id" == null ]]; then
100+
echo "Failed to get the workflow run ID. Exiting."
101+
exit 1
102+
fi
103+
104+
# Wait for workflow completion
105+
while true; do
106+
sleep 10
107+
status=$(curl -s \
108+
-H "Accept: application/vnd.github+json" \
109+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
110+
-H "X-GitHub-Api-Version: 2022-11-28" \
111+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs/$run_id" \
112+
| jq -r '.status')
113+
114+
conclusion=$(curl -s \
115+
-H "Accept: application/vnd.github+json" \
116+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
117+
-H "X-GitHub-Api-Version: 2022-11-28" \
118+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs/$run_id" \
119+
| jq -r '.conclusion')
120+
121+
if [ "$status" == "completed" ]; then
122+
if [ "$conclusion" == "success" ]; then
123+
echo "Workflow completed successfully."
124+
exit 0
125+
else
126+
echo "Workflow failed with conclusion: $conclusion"
127+
exit 1
128+
fi
129+
fi
130+
131+
echo "Workflow still running..."
132+
sleep 20
133+
done

infrastructure/terraform/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Transient backends
44
components/**/backend_tfscaffold.tf
5+
bootstrap
56

67
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
78
# password, private keys, and other secrets. These should not be part of version

infrastructure/terraform/components/app/route53_record_root.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ resource "aws_route53_record" "root" {
55
type = "A"
66
ttl = 300
77
records = ["127.0.0.1"]
8+
89
lifecycle {
910
# Amplify is going to overwrite this record, but due to some provider wierdness this must exist initialy or cognito fails to deploy, even with depends_on configured.
1011
ignore_changes = [

0 commit comments

Comments
 (0)