Skip to content

Commit f50ab7c

Browse files
committed
feat: use the same acr with a prefix in image tag for devtest
1 parent 7ffa544 commit f50ab7c

3 files changed

Lines changed: 171 additions & 53 deletions

File tree

.github/workflows/cicd-1-pull-request-devtest.yaml

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,41 +123,43 @@ jobs:
123123
secrets:
124124
client_id: ${{ secrets.AZURE_CLIENT_ID }}
125125
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
126-
#subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
127-
subscription_id_dev: ${{ secrets.AZURE_SUBSCRIPTION_ID_DEV }}
128-
acr_devtest_name: ${{ secrets.ACR_DEVTEST_NAME }}
126+
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
127+
acr_name: ${{ secrets.ACR_NAME }}
129128
with:
130129
docker_compose_file: application/CohortManager/compose.yaml
131130
excluded_containers_csv_list: azurite,azurite-setup,sql-server
132131
environment_tag: ${{ needs.metadata.outputs.environment_tag }}
133132
function_app_source_code_path: application/CohortManager/src
134133
project_name: cohort-manager
135134
build_all_images: true
136-
# deploy-stage:
137-
# if: contains(github.event.pull_request.labels.*.name, 'deploy')
138-
# name: Deploy review app pr-${{ github.event.pull_request.number }}
139-
# needs: [build-image-stage]
140-
# permissions:
141-
# id-token: write
142-
# contents: read
143-
# uses: ./.github/workflows/stage-4-deploy.yaml
144-
# with:
145-
# environments: '["review"]'
146-
# commit_sha: ${{ github.event.pull_request.head.sha }}
147-
# pr_number: ${{ github.event.pull_request.number }}
148-
# secrets: inherit
149-
# post-url:
150-
# if: contains(github.event.pull_request.labels.*.name, 'deploy')
151-
# name: Post URL pr-${{ github.event.pull_request.number }} to PR comments
152-
# runs-on: ubuntu-latest
153-
# needs: [deploy-stage]
154-
# permissions:
155-
# pull-requests: write
156-
# steps:
157-
# - name: Post URL to PR comments
158-
# uses: marocchino/sticky-pull-request-comment@5060d4700a91de252c87eeddd2da026382d9298a
159-
# with:
160-
# message: |
161-
# The review app is available at this URL:
162-
# https://pr-${{ github.event.pull_request.number }}.manage-breast-screening.non-live.screening.nhs.uk
163-
# You must authenticate with HTTP basic authentication. Ask the team for credentials.
135+
deploy-stage:
136+
if: github.event_name == 'push'
137+
name: Deploy DevTest environment for commit ${{ github.sha }}
138+
needs: [metadata, build-image-stage]
139+
permissions:
140+
id-token: write
141+
contents: read
142+
uses: ./.github/workflows/stage-4-deploy-devtest.yaml
143+
secrets:
144+
client_id: ${{ secrets.AZURE_CLIENT_ID }}
145+
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
146+
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
147+
with:
148+
environments: "[\"development\"]"
149+
commit_sha: ${{ github.sha }}
150+
validate-title-stage:
151+
name: Validate PR title
152+
runs-on: ubuntu-latest
153+
permissions:
154+
pull-requests: write
155+
env:
156+
GITHUB_TOKEN: ${{ github.token }}
157+
if: github.event_name == 'push'
158+
steps:
159+
- uses: amannn/action-semantic-pull-request@v5
160+
id: validate
161+
- uses: thollander/actions-comment-pull-request@v2
162+
if: ${{ failure() && steps.validate.conclusion == 'failure' }}
163+
with:
164+
message: |
165+
Your Pull Request title must meet the conventional commit standards, please see the following documentation - https://www.conventionalcommits.org/en/v1.0.0/#specification

.github/workflows/stage-3-build-images-devtest.yaml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ on:
3737
tenant_id:
3838
description: 'The Azure Tenant ID.'
3939
required: true
40-
# subscription_id:
41-
# description: 'The Azure Subscription ID.'
42-
# required: true
43-
subscription_id_dev:
44-
description: 'The Azure Development Subscription ID.'
40+
subscription_id:
41+
description: 'The Azure Subscription ID.'
4542
required: true
46-
acr_devtest_name:
43+
acr_name:
4744
description: 'The name of the Azure Container Registry.'
4845
required: true
4946

@@ -94,6 +91,7 @@ jobs:
9491
outputs:
9592
pr_num_tag: ${{ env.PR_NUM_TAG }}
9693
short_commit_hash: ${{ env.COMMIT_HASH_TAG }}
94+
devtest_commit_hash: ${{ env.DEVTEST_HASH_TAG }}
9795
steps:
9896
- uses: actions/checkout@v4
9997
with:
@@ -113,12 +111,12 @@ jobs:
113111
with:
114112
client-id: ${{ secrets.client_id }}
115113
tenant-id: ${{ secrets.tenant_id }}
116-
subscription-id: ${{ secrets.subscription_id_dev }}
114+
subscription-id: ${{ secrets.subscription_id }}
117115

118116
- name: Azure Container Registry login
119117
env:
120-
ACR_DEVTEST_NAME: ${{ secrets.acr_devtest_name }}
121-
run: az acr login --name ${ACR_DEVTEST_NAME}
118+
ACR_NAME: ${{ secrets.acr_name }}
119+
run: az acr login --name ${ACR_NAME}
122120

123121
- name: Create Tags
124122
env:
@@ -144,6 +142,10 @@ jobs:
144142
echo "Commit hash tag: ${SHORT_COMMIT_HASH}"
145143
echo "COMMIT_HASH_TAG=${SHORT_COMMIT_HASH}" >> ${GITHUB_ENV}
146144
145+
DEVTEST_COMMIT_HASH="devtest_${SHORT_COMMIT_HASH}"
146+
echo "Commit devtest hash tag: ${DEVTEST_COMMIT_HASH}"
147+
echo "DEVTEST_HASH_TAG=${DEVTEST_COMMIT_HASH}" >> ${GITHUB_ENV}
148+
147149
echo "ENVIRONMENT_TAG=${ENVIRONMENT_TAG}" >> ${GITHUB_ENV}
148150
149151
- name: Build and Push Image
@@ -152,7 +154,7 @@ jobs:
152154
env:
153155
COMPOSE_FILE: ${{ inputs.docker_compose_file }}
154156
PROJECT_NAME: ${{ inputs.project_name }}
155-
ACR_DEVTEST_NAME: ${{ secrets.acr_devtest_name }}
157+
ACR_NAME: ${{ secrets.acr_name }}
156158
run: |
157159
function=${{ matrix.function }}
158160
@@ -166,14 +168,14 @@ jobs:
166168
# Build the image
167169
docker compose -f ${COMPOSE_FILE//,/ -f } -p ${PROJECT_NAME} --profile "*" build --no-cache --pull ${function}
168170
169-
repo_name="${ACR_DEVTEST_NAME}.azurecr.io/${PROJECT_NAME}-${function}"
171+
repo_name="${ACR_NAME}.azurecr.io/${PROJECT_NAME}-${function}"
170172
echo $(repo_name)
171173
172174
# Tag the image
173175
echo "Tag the image:"
174-
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${COMMIT_HASH_TAG}"
175-
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${PR_NUM_TAG}"
176-
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${ENVIRONMENT_TAG}"
176+
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${DEVTEST_HASH_TAG}"
177+
# docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${PR_NUM_TAG}"
178+
# docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${ENVIRONMENT_TAG}"
177179
178180
# If this variable is set, the create-sbom-report.sh script will scan this docker image instead.
179181
export CHECK_DOCKER_IMAGE=${PROJECT_NAME}-${function}:latest
@@ -183,22 +185,18 @@ jobs:
183185
echo "PR_NUM_TAG=${PR_NUM_TAG}" >> ${GITHUB_ENV}
184186
185187
# Push the image to the repository
186-
docker push "${repo_name}:${COMMIT_HASH_TAG}"
187-
if [ "${PR_NUM_TAG}" != 'pr' ]; then
188-
docker push "${repo_name}:${PR_NUM_TAG}"
189-
fi
190-
docker push "${repo_name}:${ENVIRONMENT_TAG}"
188+
docker push "${repo_name}:${DEVTEST_HASH_TAG}"
191189
192190
- name: Cleanup the docker images
193191
env:
194192
PROJECT_NAME: ${{ inputs.project_name }}
195-
ACR_DEVTEST_NAME: ${{ secrets.acr_devtest_name }}
193+
ACR_NAME: ${{ secrets.acr_name }}
196194
run: |
197195
function=${{ matrix.function }}
198-
repo_name="${ACR_DEVTEST_NAME}.azurecr.io/${PROJECT_NAME}-${function}"
196+
repo_name="${ACR_NAME}.azurecr.io/${PROJECT_NAME}-${function}"
199197
200198
# Remove the images
201-
docker rmi "${repo_name}:${COMMIT_HASH_TAG}"
199+
docker rmi "${repo_name}:${DEVTEST_HASH_TAG}"
202200
docker rmi "${repo_name}:${PR_NUM_TAG}"
203201
docker rmi "${repo_name}:${ENVIRONMENT_TAG}"
204202
docker rmi ${PROJECT_NAME}-${function}:latest
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Deployment stage
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environments:
7+
description: List of environments to deploy to (String array)
8+
required: true
9+
type: string
10+
commit_sha:
11+
description: Commit SHA used to fetch ADO pipeline and docker image
12+
required: true
13+
type: string
14+
pr_number:
15+
description: Pull request number when used in a pull request
16+
required: false
17+
type: string
18+
19+
secrets:
20+
client_id:
21+
description: 'The Azure Client ID.'
22+
required: true
23+
tenant_id:
24+
description: 'The Azure Tenant ID.'
25+
required: true
26+
subscription_id:
27+
description: 'The Azure Subscription ID.'
28+
required: true
29+
30+
workflow_dispatch:
31+
inputs:
32+
environments:
33+
description: List of environments to deploy to (String array)
34+
required: true
35+
type: string
36+
commit_sha:
37+
description: Commit SHA used to fetch ADO pipeline and docker image
38+
required: true
39+
type: string
40+
pr_number:
41+
description: Pull request number when used in a pull request
42+
required: false
43+
type: string
44+
45+
secrets:
46+
client_id:
47+
description: 'The Azure Client ID.'
48+
required: true
49+
tenant_id:
50+
description: 'The Azure Tenant ID.'
51+
required: true
52+
subscription_id:
53+
description: 'The Azure Subscription ID.'
54+
required: true
55+
56+
jobs:
57+
deploy:
58+
name: Deploy
59+
runs-on: ubuntu-latest
60+
permissions:
61+
id-token: write
62+
contents: read
63+
strategy:
64+
matrix:
65+
environment: ${{ fromJson(inputs.environments) }}
66+
max-parallel: 1
67+
environment: ${{ matrix.environment }}
68+
concurrency: deploy-${{ matrix.environment }}-${{ github.ref }}
69+
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v5
73+
74+
- uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5
75+
with:
76+
client-id: ${{ secrets.client_id }}
77+
tenant-id: ${{ secrets.tenant_id }}
78+
subscription-id: ${{ secrets.subscription_id }}
79+
80+
- name: Make script executable
81+
run: chmod +x scripts/bash/wait_ado_pipeline.sh
82+
83+
- name: Call deployment pipeline
84+
shell: bash
85+
env:
86+
COMMIT_SHA: ${{ inputs.commit_sha }}
87+
ENVIRONMENT_NAME: ${{ matrix.environment }}
88+
run: |
89+
set -euo pipefail
90+
# Define common variables
91+
organisation='https://dev.azure.com/nhse-dtos'
92+
project_name='dtos-cohort-manager'
93+
94+
# Define which tests to run based on the environment
95+
declare -A test_types=(
96+
["development"]=""
97+
)
98+
99+
# Derive the short SHA from the provided commit
100+
git_short_sha=$(git rev-parse --short "$COMMIT_SHA")
101+
devtest_short_sha="devtest_${git_short_sha}"
102+
103+
# Prepare parameters as separate key=value tokens
104+
param_image="dockerImageTag=${devtest_short_sha}"
105+
param_tests="testTypes=[${test_types[$ENVIRONMENT_NAME]}]"
106+
107+
echo "Starting Azure devops pipeline \"Deploy to Azure - Core ${ENVIRONMENT_NAME}\"..."
108+
RUN_ID=$(az pipelines run \
109+
--commit-id "$COMMIT_SHA" \
110+
--name "Deploy to Azure - Core ${ENVIRONMENT_NAME}" \
111+
--org "${organisation}" \
112+
--project "${project_name}" \
113+
--parameters "$param_image" "$param_tests" \
114+
--output tsv --query id)
115+
116+
echo "Click here to view the ADO pipeline: ${organisation}/${project_name}/_build/results?buildId=${RUN_ID}"
117+
118+
scripts/bash/wait_ado_pipeline.sh "$RUN_ID" "${organisation}" "${project_name}" 1800

0 commit comments

Comments
 (0)