Skip to content

Commit 07df94a

Browse files
committed
feat: test devtest with new base images
1 parent 150a8d0 commit 07df94a

2 files changed

Lines changed: 115 additions & 34 deletions

File tree

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,40 +86,44 @@ jobs:
8686
python_version: "${{ needs.metadata.outputs.python_version }}"
8787
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
8888
version: "${{ needs.metadata.outputs.version }}"
89-
test-stage: # Recommended maximum execution time is 5 minutes
90-
name: 'Test stage'
91-
needs: [metadata]
92-
uses: ./.github/workflows/stage-2-test.yaml
93-
with:
94-
unit_test_dir: tests/UnitTests
95-
app_dir: application/CohortManager
96-
build_datetime: '${{ needs.metadata.outputs.build_datetime }}'
97-
build_timestamp: '${{ needs.metadata.outputs.build_timestamp }}'
98-
build_epoch: '${{ needs.metadata.outputs.build_epoch }}'
99-
nodejs_version: '${{ needs.metadata.outputs.nodejs_version }}'
100-
python_version: '${{ needs.metadata.outputs.python_version }}'
101-
terraform_version: '${{ needs.metadata.outputs.terraform_version }}'
102-
version: '${{ needs.metadata.outputs.version }}'
103-
secrets: inherit
104-
analysis-stage: # Recommended maximum execution time is 5 minutes
105-
name: "Analysis stage"
106-
needs: [metadata, commit-stage, test-stage]
107-
uses: ./.github/workflows/stage-2-analyse.yaml
108-
secrets:
109-
sonar_token: ${{ secrets.SONAR_TOKEN }}
110-
with:
111-
unit_test_dir: tests/UnitTests
112-
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
113-
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
114-
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
115-
nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}"
116-
python_version: "${{ needs.metadata.outputs.python_version }}"
117-
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
118-
version: "${{ needs.metadata.outputs.version }}"
89+
# test-stage: # Recommended maximum execution time is 5 minutes
90+
# name: "Test stage"
91+
# needs: [metadata, commit-stage]
92+
# uses: ./.github/workflows/stage-2-test.yaml
93+
# with:
94+
# unit_test_dir: tests/UnitTests
95+
# app_dir: application/CohortManager
96+
# build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
97+
# build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
98+
# build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
99+
# nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}"
100+
# python_version: "${{ needs.metadata.outputs.python_version }}"
101+
# terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
102+
# version: "${{ needs.metadata.outputs.version }}"
103+
# analysis-stage: # Recommended maximum execution time is 5 minutes
104+
# name: "Analysis stage"
105+
# needs: [metadata, commit-stage, test-stage]
106+
# uses: ./.github/workflows/stage-2-analyse.yaml
107+
# secrets:
108+
# sonar_token: ${{ secrets.SONAR_TOKEN }}
109+
# with:
110+
# unit_test_dir: tests/UnitTests
111+
# build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
112+
# build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
113+
# build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
114+
# nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}"
115+
# python_version: "${{ needs.metadata.outputs.python_version }}"
116+
# terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
117+
# version: "${{ needs.metadata.outputs.version }}"
119118
build-image-stage: # Recommended maximum execution time is 3 minutes
120119
name: "Image build stage"
121-
needs: [metadata, commit-stage, test-stage, analysis-stage]
120+
needs: [metadata, commit-stage] #[metadata, commit-stage, test-stage, analysis-stage]
122121
uses: ./.github/workflows/stage-3-build-images-devtest.yaml
122+
permissions:
123+
contents: read
124+
id-token: write
125+
pull-requests: write
126+
packages: write
123127
secrets:
124128
client_id: ${{ secrets.AZURE_CLIENT_ID }}
125129
tenant_id: ${{ secrets.AZURE_TENANT_ID }}

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

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,88 @@ jobs:
7777
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7878
run: bash scripts/deployment/get-docker-names.sh
7979

80+
build-base-images:
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: read
84+
pull-requests: read
85+
id-token: write
86+
packages: write
87+
outputs:
88+
DOTNET_BASE_IMAGE: ${{ steps.set-image-tags.outputs.DOTNET_BASE_IMAGE }}
89+
FUNCTION_BASE_IMAGE: ${{ steps.set-image-tags.outputs.FUNCTION_BASE_IMAGE }}
90+
steps:
91+
- uses: actions/checkout@v4
92+
with:
93+
token: ${{ secrets.GITHUB_TOKEN }}
94+
fetch-depth: 1
95+
submodules: 'true'
96+
97+
- name: log in to GHCR
98+
uses: docker/login-action@v3
99+
continue-on-error: false
100+
with:
101+
registry: ghcr.io
102+
username: ${{ github.actor }}
103+
password: ${{ secrets.GITHUB_TOKEN }}
104+
105+
- name: Detect base image changes
106+
id: detect-base-image-changes
107+
continue-on-error: false
108+
run: bash scripts/deployment/check-base-image-changes.sh
109+
110+
- name: Build Base Images
111+
id: build-base-images
112+
working-directory: ./
113+
if: ${{ steps.detect-base-image-changes.outputs.BASE_IMAGE_CHANGE == 'true' || github.ref == 'refs/heads/main' }}
114+
continue-on-error: false
115+
run: |
116+
PR_NUM_TAG=$(echo "${GITHUB_REF}" | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
117+
SHORT_COMMIT_HASH=$(git rev-parse --short ${GITHUB_SHA})
118+
119+
docker build -f Dockerfile.dotnet.base -t cohort-manager-dotnet-base:latest .
120+
docker tag cohort-manager-dotnet-base:latest "ghcr.io/nhsdigital/cohort-manager-dotnet-base:${PR_NUM_TAG}"
121+
docker tag cohort-manager-dotnet-base:latest "ghcr.io/nhsdigital/cohort-manager-dotnet-base:${SHORT_COMMIT_HASH}"
122+
123+
docker build -f Dockerfile.function.base -t cohort-manager-function-base:latest .
124+
docker tag cohort-manager-function-base:latest "ghcr.io/nhsdigital/cohort-manager-function-base:${PR_NUM_TAG}"
125+
docker tag cohort-manager-function-base:latest "ghcr.io/nhsdigital/cohort-manager-function-base:${SHORT_COMMIT_HASH}"
126+
127+
docker push "ghcr.io/nhsdigital/cohort-manager-dotnet-base:${PR_NUM_TAG}"
128+
docker push "ghcr.io/nhsdigital/cohort-manager-dotnet-base:${SHORT_COMMIT_HASH}"
129+
docker push "ghcr.io/nhsdigital/cohort-manager-function-base:${PR_NUM_TAG}"
130+
docker push "ghcr.io/nhsdigital/cohort-manager-function-base:${SHORT_COMMIT_HASH}"
131+
if [ "${GITHUB_REF}" == 'refs/heads/main' ]; then
132+
docker push "ghcr.io/nhsdigital/cohort-manager-dotnet-base:latest"
133+
docker push "ghcr.io/nhsdigital/cohort-manager-function-base:latest"
134+
fi
135+
136+
- name: Set Image Tags
137+
id: set-image-tags
138+
run: |
139+
140+
PR_NUM_TAG=$(echo "${GITHUB_REF}" | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
141+
IMAGE_TAG="latest"
142+
143+
if [[ ${{steps.detect-base-image-changes.outputs.BASE_IMAGE_CHANGE}} == 'true' ]]; then
144+
IMAGE_TAG="${PR_NUM_TAG}"
145+
fi
146+
echo "Image Tag = ${IMAGE_TAG}"
147+
148+
echo "DOTNET_BASE_IMAGE=ghcr.io/nhsdigital/cohort-manager-dotnet-base:${IMAGE_TAG}" >> "${GITHUB_OUTPUT}"
149+
echo "FUNCTION_BASE_IMAGE=ghcr.io/nhsdigital/cohort-manager-function-base:${IMAGE_TAG}" >> "${GITHUB_OUTPUT}"
150+
151+
152+
153+
154+
80155
build-and-push:
81156
runs-on: ubuntu-latest
82157
permissions:
83158
id-token: write
84159
contents: read
85160
pull-requests: read
86-
needs: get-functions
161+
needs: [get-functions, build-base-images]
87162
strategy:
88163
matrix:
89164
function: ${{ fromJSON(needs.get-functions.outputs.FUNC_NAMES) }}
@@ -165,8 +240,10 @@ jobs:
165240
exit 0
166241
fi
167242
168-
# Build the image
169-
docker compose -f ${COMPOSE_FILE//,/ -f } -p ${PROJECT_NAME} --profile "*" build --no-cache --pull ${function}
243+
244+
docker compose -f ${COMPOSE_FILE//,/ -f } \
245+
-p ${PROJECT_NAME} \
246+
--profile "*" build --no-cache --pull ${function}
170247
171248
repo_name="${ACR_NAME}.azurecr.io/${PROJECT_NAME}-${function}"
172249
echo $(repo_name)

0 commit comments

Comments
 (0)