Skip to content

Commit 76addbe

Browse files
authored
CCM-11938: Move Proxygen Deploy to Internal (#177)
* CCM-11938: Setting calls for proxygen workflow in internal * CCM-11938: Fix sonar issues * CCM-11938: Fix apim env var export * CCM-11938: Fix apim env var export * CCM-11938: Push to main default * CCM-11938: Push to main default
1 parent 05606d5 commit 76addbe

File tree

5 files changed

+229
-159
lines changed

5 files changed

+229
-159
lines changed

.github/actions/build-proxies/action.yml

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@ description: "Build Proxies"
44
inputs:
55
version:
66
description: "Version number"
7+
required: false
8+
releaseVersion:
9+
description: "Release, tag, branch, or commit ID to be used for deployment"
710
required: true
11+
environment:
12+
description: "Deployment environment"
13+
required: true
14+
apimEnv:
15+
description: "APIM environment"
16+
required: true
17+
runId:
18+
description: "GitHub Actions run ID to fetch the OAS artifact from"
19+
required: true
20+
buildSandbox:
21+
description: "Whether to build the sandbox OAS spec"
22+
required: false
23+
default: false
24+
targetComponent:
25+
description: "Name of the Component to deploy"
26+
required: true
27+
default: 'api'
828

929
runs:
1030
using: composite
@@ -25,46 +45,71 @@ runs:
2545
shell: bash
2646
run: |
2747
48+
ENV="${{ inputs.apimEnv }}"
49+
if [[ "$ENV" == "internal-dev" || "$ENV" == *pr ]]; then
50+
echo "TARGET_DOMAIN=suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
51+
elif [[ "$ENV" == "int" ]]; then
52+
echo "TARGET_DOMAIN=suppliers.nonprod.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
53+
elif [[ "$ENV" == "prod" ]]; then
54+
echo "TARGET_DOMAIN=suppliers.prod.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
55+
else
56+
echo "TARGET_DOMAIN=suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
57+
fi
58+
2859
if [ -z $PR_NUMBER ]
2960
then
3061
echo "INSTANCE=$PROXYGEN_API_NAME" >> $GITHUB_ENV
31-
echo "TARGET=https://main.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
62+
echo "TARGET=https://main.$TARGET_DOMAIN" >> $GITHUB_ENV
3263
echo "SANDBOX_TAG=latest" >> $GITHUB_ENV
3364
echo "MTLS_NAME=notify-supplier-mtls" >> $GITHUB_ENV
3465
else
35-
echo "TARGET=https://pr$PR_NUMBER.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
66+
echo "TARGET=https://pr$PR_NUMBER.$TARGET_DOMAIN" >> $GITHUB_ENV
3667
echo "INSTANCE=$PROXYGEN_API_NAME-PR-$PR_NUMBER" >> $GITHUB_ENV
3768
echo "SANDBOX_TAG=pr$PR_NUMBER" >> $GITHUB_ENV
3869
echo "MTLS_NAME=notify-supplier-mtls-pr$PR_NUMBER" >> $GITHUB_ENV
3970
fi
4071
41-
- name: Install Proxygen client
42-
shell: bash
43-
run: |
44-
# Install proxygen cli
45-
pip install pipx
46-
pipx install proxygen-cli
47-
48-
# Setup proxygen auth and settings
49-
mkdir -p ${HOME}/.proxygen
50-
echo -n $PROXYGEN_PRIVATE_KEY | base64 --decode > ${HOME}/.proxygen/key
51-
envsubst < ./.github/proxygen-credentials-template.yaml > ${HOME}/.proxygen/credentials.yaml
52-
envsubst < ./.github/proxygen-credentials-template.yaml | cat
53-
envsubst < ./.github/proxygen-settings.yaml > ${HOME}/.proxygen/settings.yaml
54-
envsubst < ./.github/proxygen-settings.yaml | cat
55-
56-
- name: Build sandbox oas
72+
- name: Build ${{ inputs.apimEnv }} oas
5773
working-directory: .
74+
env:
75+
APIM_ENV: ${{ inputs.apimEnv }}
5876
shell: bash
5977
run: |
60-
make build-json-oas-spec APIM_ENV=sandbox
78+
if [ ${{ env.APIM_ENV }} == "internal-dev-sandbox" ] && [ ${{ inputs.buildSandbox }} == true ]
79+
then
80+
echo "Building sandbox OAS spec"
81+
make build-json-oas-spec APIM_ENV=sandbox
82+
else
83+
echo "Building env specific OAS spec"
84+
make build-json-oas-spec APIM_ENV=${{ env.APIM_ENV }}
85+
fi
6186
62-
- name: Set docker tag
63-
shell: bash
64-
run: |
65-
jq --arg newtag "$SANDBOX_TAG" '.["x-nhsd-apim"].target.containers[0].image.tag = $newtag' build/notify-supplier.json > build/notify-supplier_target.json && mv build/notify-supplier_target.json build/notify-supplier.json
87+
if [[ $APIM_ENV == *-pr ]]; then
88+
echo "Removing pr suffix from APIM_ENV after building OAS and calling proxygen"
89+
APIM_ENV=$(echo "$APIM_ENV" | sed 's/-pr$//')
90+
fi
91+
echo "APIM_ENV=$APIM_ENV" >> $GITHUB_ENV
92+
93+
- name: Upload OAS Spec
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: ${{ env.APIM_ENV }}-build-output
97+
path: ./build
6698

67-
- name: Deploy to Internal Dev Sandbox
99+
- name: Trigger deploy proxy
100+
env:
101+
PR_TRIGGER_PAT: ${{ env.PR_TRIGGER_PAT }}
68102
shell: bash
69103
run: |
70-
proxygen instance deploy internal-dev-sandbox $INSTANCE build/notify-supplier.json --no-confirm
104+
.github/scripts/dispatch_internal_repo_workflow.sh \
105+
--infraRepoName "nhs-notify-supplier-api" \
106+
--releaseVersion "${{ inputs.releaseVersion }}" \
107+
--targetComponent "${{ inputs.targetComponent }}" \
108+
--targetWorkflow "proxy-deploy.yaml" \
109+
--targetEnvironment "${{ inputs.environment }}" \
110+
--runId "${{ inputs.runId }}" \
111+
--buildSandbox ${{ inputs.buildSandbox }} \
112+
--apimEnvironment "${{ env.APIM_ENV }}" \
113+
--boundedContext "notify-supplier" \
114+
--targetDomain "$TARGET_DOMAIN" \
115+
--version "${{ inputs.version }}"

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ while [[ $# -gt 0 ]]; do
6868
internalRef="$2"
6969
shift 2
7070
;;
71+
--runId) # Github Run ID (optional)
72+
runId="$2"
73+
shift 2
74+
;;
7175
--overrides) # Terraform overrides for passing in extra variables (optional)
7276
overrides="$2"
7377
shift 2
@@ -80,6 +84,26 @@ while [[ $# -gt 0 ]]; do
8084
overrideRoleName="$2"
8185
shift 2
8286
;;
87+
--buildSandbox) # Build sandbox flag (optional)
88+
buildSandbox="$2"
89+
shift 2
90+
;;
91+
--apimEnvironment) # APIM environment (optional)
92+
apimEnvironment="$2"
93+
shift 2
94+
;;
95+
--boundedContext) # Bounded context (optional)
96+
boundedContext="$2"
97+
shift 2
98+
;;
99+
--targetDomain) # Target domain (optional)
100+
targetDomain="$2"
101+
shift 2
102+
;;
103+
--version) # Version (optional)
104+
version="$2"
105+
shift 2
106+
;;
83107
*)
84108
echo "[ERROR] Unknown argument: $1"
85109
exit 1
@@ -101,6 +125,30 @@ if [[ -z "$internalRef" ]]; then
101125
internalRef="main"
102126
fi
103127

128+
if [[ -z "$runId" ]]; then
129+
runId=""
130+
fi
131+
132+
if [[ -z "$buildSandbox" ]]; then
133+
buildSandbox=""
134+
fi
135+
136+
if [[ -z "$apimEnvironment" ]]; then
137+
apimEnvironment=""
138+
fi
139+
140+
if [[ -z "$boundedContext" ]]; then
141+
boundedContext=""
142+
fi
143+
144+
if [[ -z "$targetDomain" ]]; then
145+
targetDomain=""
146+
fi
147+
148+
if [[ -z "$version" ]]; then
149+
version=""
150+
fi
151+
104152
echo "==================== Workflow Dispatch Parameters ===================="
105153
echo " infraRepoName: $infraRepoName"
106154
echo " releaseVersion: $releaseVersion"
@@ -114,6 +162,12 @@ echo " overrides: $overrides"
114162
echo " overrideProjectName: $overrideProjectName"
115163
echo " overrideRoleName: $overrideRoleName"
116164
echo " targetProject: $targetProject"
165+
echo " runId: $runId"
166+
echo " buildSandbox: $buildSandbox"
167+
echo " apimEnvironment: $apimEnvironment"
168+
echo " boundedContext: $boundedContext"
169+
echo " targetDomain: $targetDomain"
170+
echo " version: $version"
117171

118172
DISPATCH_EVENT=$(jq -ncM \
119173
--arg infraRepoName "$infraRepoName" \
@@ -127,6 +181,12 @@ DISPATCH_EVENT=$(jq -ncM \
127181
--arg overrideProjectName "$overrideProjectName" \
128182
--arg overrideRoleName "$overrideRoleName" \
129183
--arg targetProject "$targetProject" \
184+
--arg runId "$runId" \
185+
--arg buildSandbox "$buildSandbox" \
186+
--arg apimEnvironment "$apimEnvironment" \
187+
--arg boundedContext "$boundedContext" \
188+
--arg targetDomain "$targetDomain" \
189+
--arg version "$version" \
130190
'{
131191
"ref": "'"$internalRef"'",
132192
"inputs": (
@@ -135,18 +195,26 @@ DISPATCH_EVENT=$(jq -ncM \
135195
(if $overrideProjectName != "" then { "overrideProjectName": $overrideProjectName } else {} end) +
136196
(if $overrideRoleName != "" then { "overrideRoleName": $overrideRoleName } else {} end) +
137197
(if $targetProject != "" then { "targetProject": $targetProject } else {} end) +
198+
(if $overrides != "" then { "overrides": $overrides } else {} end) +
199+
(if $runId != "" then { "runId": $runId } else {} end) +
200+
(if $buildSandbox != "" then { "buildSandbox": $buildSandbox } else {} end) +
201+
(if $apimEnvironment != "" then { "apimEnvironment": $apimEnvironment } else {} end) +
202+
(if $boundedContext != "" then { "boundedContext": $boundedContext } else {} end) +
203+
(if $targetDomain != "" then { "targetDomain": $targetDomain } else {} end) +
204+
(if $version != "" then { "version": $version } else {} end) +
205+
(if $targetAccountGroup != "" then { "targetAccountGroup": $targetAccountGroup } else {} end) +
138206
{
139207
"releaseVersion": $releaseVersion,
140208
"targetEnvironment": $targetEnvironment,
141-
"targetAccountGroup": $targetAccountGroup,
142209
"targetComponent": $targetComponent,
143-
"overrides": $overrides,
144210
}
145211
)
146212
}')
147213

148214
echo "[INFO] Triggering workflow '$targetWorkflow' in nhs-notify-internal..."
149215

216+
echo "[DEBUG] Dispatch event payload: $DISPATCH_EVENT"
217+
150218
trigger_response=$(curl -s -L \
151219
--fail \
152220
-X POST \
@@ -185,16 +253,12 @@ for _ in {1..18}; do
185253
workflow_run_url=$(echo "$response" | jq -r \
186254
--arg targetWorkflow "$targetWorkflow" \
187255
--arg targetEnvironment "$targetEnvironment" \
188-
--arg targetAccountGroup "$targetAccountGroup" \
189256
--arg targetComponent "$targetComponent" \
190-
--arg terraformAction "$terraformAction" \
191257
'.workflow_runs[]
192258
| select(.path == ".github/workflows/" + $targetWorkflow)
193259
| select(.name
194260
| contains($targetEnvironment)
195-
and contains($targetAccountGroup)
196261
and contains($targetComponent)
197-
and contains($terraformAction)
198262
)
199263
| .url')
200264

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Deploy proxy to environment
2+
run-name: Proxygen Deployment for ${{ inputs.proxy_environment }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
proxy_environment:
8+
description: Name of the proxygen environment to deploy to
9+
required: true
10+
type: choice
11+
default: internal-dev
12+
options:
13+
- internal-dev
14+
- int
15+
- prod
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
deploy-environment:
22+
runs-on: ubuntu-latest
23+
name: Deploy to Environment
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: 24
31+
32+
- name: Npm install
33+
working-directory: .
34+
run: npm ci
35+
shell: bash
36+
37+
- name: "Check if pull request exists for this branch and set ENVIRONMENT/APIM_ENV"
38+
id: pr_exists
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
run: |
42+
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
43+
echo "Current branch is '$branch_name'"
44+
45+
if [ -z "${{ inputs.proxy_environment }}" ]; then
46+
ENVIRONMENT="internal-dev"
47+
else
48+
ENVIRONMENT="${{ inputs.proxy_environment }}"
49+
fi
50+
51+
pr_json=$(gh pr list --head "$branch_name" --state open --json number --limit 1)
52+
pr_number=$(echo "$pr_json" | jq -r '.[0].number // empty')
53+
54+
if [[ -n "$pr_number" ]]; then
55+
echo "Pull request exists: #$pr_number"
56+
echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT
57+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
58+
APIM_ENV="$ENVIRONMENT-pr"
59+
echo "changing environment variable so that PR number is used in proxy pipeline for setting env vars"
60+
ENVIRONMENT="pr$pr_number"
61+
else
62+
echo "Pull request doesn't exist, setting target env to main"
63+
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
64+
echo "pr_number=" >> $GITHUB_OUTPUT
65+
APIM_ENV="$ENVIRONMENT"
66+
$ENVIRONMENT='main'
67+
fi
68+
69+
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
70+
echo "APIM_ENV=$APIM_ENV" >> $GITHUB_ENV
71+
72+
- name: "Build proxies"
73+
env:
74+
PROXYGEN_API_NAME: nhs-notify-supplier
75+
PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }}
76+
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
77+
uses: ./.github/actions/build-proxies
78+
with:
79+
environment: "${{ env.ENVIRONMENT }}"
80+
apimEnv: "${{ env.APIM_ENV }}"
81+
runId: "${{ github.run_id }}"
82+
buildSandbox: false
83+
releaseVersion: ${{ github.ref_name }}

0 commit comments

Comments
 (0)