1212 description : The environment to build the base image against
1313 type : string
1414 required : false
15- default : " origin/ next"
15+ default : " next"
1616 secrets :
1717 HTTP_AUTH_TOKEN_FOR_TESTS :
1818 description : HTTP Basic Auth token for the environment under test
3030 description : The environment to build the base image against
3131 type : string
3232 required : false
33- default : " origin/ next"
33+ default : " next"
3434
3535permissions : { }
3636
4242 steps :
4343 - uses : actions/checkout@v6
4444 with :
45- ref : ${{ inputs.git_reference_for_application_image || github.event.pull_request.head.sha || github .sha }}
45+ ref : ${{ github.event.pull_request.head.sha }}
4646 repository : nhsuk/manage-vaccinations-in-schools
4747 - name : Check if end-to-end tests need to run
4848 id : check
@@ -56,16 +56,24 @@ jobs:
5656 id-token : write
5757 outputs :
5858 build-needed : ${{ steps.check-image.outputs.build-needed }}
59+ application-image-git-ref : ${{ steps.check-image.outputs.GIT_REF_SHA }}
5960 steps :
6061 - name : Configure AWS Credentials
6162 uses : aws-actions/configure-aws-credentials@v5
6263 with :
6364 role-to-assume : arn:aws:iam::393416225559:role/GitHubAssuranceTestRole
6465 aws-region : eu-west-2
66+ - uses : actions/checkout@v6
67+ with :
68+ fetch-depth : 0
6569 - name : Check if image exists
6670 id : check-image
71+ env :
72+ GIT_REF : ${{ (inputs.git_reference_for_application_image == 'next' && 'origin/next') || github.event.pull_request.head.sha || github.sha }}
6773 run : |
68- if aws ecr describe-images --repository-name mavis/development --image-ids imageTag=${{ inputs.git_reference_for_application_image || github.event.pull_request.head.sha || github.sha }} > /dev/null 2>&1; then
74+ GIT_REF_SHA=$(git rev-parse $GIT_REF)
75+ echo "GIT_REF_SHA=$GIT_REF_SHA" >> $GITHUB_OUTPUT
76+ if aws ecr describe-images --repository-name mavis/development --image-ids imageTag=$GIT_REF_SHA > /dev/null 2>&1; then
6977 echo "Docker image with given tag already exists"
7078 echo "build-needed=false" >> $GITHUB_OUTPUT
7179 else
8290 - name : Checkout code
8391 uses : actions/checkout@v6
8492 with :
85- ref : ${{ inputs.git_reference_for_application_image || github.event.pull_request.head.sha || github.sha }}
93+ ref : ${{ needs.check-development-image-presence.outputs.application-image-git-ref }}
8694 repository : nhsuk/manage-vaccinations-in-schools
8795 - name : Configure AWS Credentials
8896 uses : aws-actions/configure-aws-credentials@v5
@@ -97,16 +105,17 @@ jobs:
97105 docker build \
98106 --build-arg BUNDLE_WITHOUT=test \
99107 --build-arg RAILS_ENV=development \
100- -t "393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ github.sha }}" \
108+ -t "393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ needs.check-development-image-presence.outputs.application-image-git-ref }}" \
101109 .
102- docker push "393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ github.sha }}"
110+ docker push "393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ needs.check-development-image-presence.outputs.application-image-git-ref }}"
103111 check-database-image-presence :
104112 name : Check if database docker image already exists
105113 runs-on : ubuntu-latest
106114 permissions :
107115 id-token : write
108116 outputs :
109117 build-needed : ${{ steps.check-image.outputs.build-needed }}
118+ db_git_ref_sha : ${{ steps.check-image.outputs.GIT_REF_SHA }}
110119 steps :
111120 - name : Configure AWS Credentials
112121 uses : aws-actions/configure-aws-credentials@v5
@@ -119,9 +128,11 @@ jobs:
119128 - name : Check if image exists
120129 id : check-image
121130 env :
122- GIT_REF : ${{ inputs.git_reference_for_database_image || (github.event_name == 'pull_request ' && github.event.pull_request.base.sha) || github.sha }}
131+ GIT_REF : ${{ ( inputs.git_reference_for_database_image == 'next ' && 'origin/next' ) || github.event.pull_request.base.sha || github.sha }}
123132 run : |
124- if aws ecr describe-images --repository-name mavis/development --image-ids imageTag=$GIT_REF > /dev/null 2>&1; then
133+ GIT_REF_SHA=$(git rev-parse $GIT_REF)
134+ echo "GIT_REF_SHA=$GIT_REF_SHA" >> $GITHUB_OUTPUT
135+ if aws ecr describe-images --repository-name mavis/development --image-ids imageTag=$GIT_REF_SHA > /dev/null 2>&1; then
125136 echo "Docker image with given tag already exists"
126137 echo "build-needed=false" >> $GITHUB_OUTPUT
127138 else
@@ -136,7 +147,7 @@ jobs:
136147 contents : read
137148 uses : ./.github/workflows/create_dockerized_db.yml
138149 with :
139- github_ref : ${{ inputs.git_reference_for_database_image }}
150+ github_ref : ${{ needs.check-database-image-presence.outputs.db_git_ref_sha }}
140151 launch-dockerized-devimage :
141152 needs : [ check-development-image-presence,
142153 build-and-push-development-image,
@@ -166,28 +177,27 @@ jobs:
166177 with :
167178 task-definition-family : " assurance-testing-mavis-development-task-definition-template"
168179 container-name : " mavis-development-web"
169- image : " 393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ github.sha }}"
180+ image : " 393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ needs.check-development-image-presence.outputs.application-image-git-ref }}"
170181 - name : Render task definition database
171182 id : render-task-definition-database
172183 uses : aws-actions/amazon-ecs-render-task-definition@v1
173184 with :
174185 task-definition : ${{ steps.render-task-definition-web.outputs.task-definition }}
175186 container-name : " mavis-development-db"
176- image : " 393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development/postgres_db:${{ github.event.pull_request.base.ref }}"
187+ image : " 393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development/postgres_db:${{ needs.check-database-image-presence.outputs.db_git_ref_sha }}"
177188 - name : Render task definition sidekiq
178189 id : render-task-definition-sidekiq
179190 uses : aws-actions/amazon-ecs-render-task-definition@v1
180191 with :
181192 task-definition : ${{ steps.render-task-definition-database.outputs.task-definition }}
182193 container-name : " mavis-development-sidekiq"
183- image : " 393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ github.sha }}"
194+ image : " 393416225559.dkr.ecr.eu-west-2.amazonaws.com/mavis/development:${{ needs.check-development-image-presence.outputs.application-image-git-ref }}"
184195 - name : Prepare deployment
185196 id : prepare-deployment
186197 run : |
187198 file_path="assurance-testing-mavis-development-task-definition.json"
188199 family_name="assurance-testing-mavis-development-task-definition"
189200 echo "$(jq --arg f "$family_name" '.family = $f' "${{ steps.render-task-definition-sidekiq.outputs.task-definition }}")" > "$file_path"
190- cat "$file_path" #TODO: Debugging, remove later
191201
192202 subnet_id=$(aws ec2 describe-subnets --filters Name=tag:Name,Values=assurance-testing-subnet --query 'Subnets[0].SubnetId' --output text)
193203 security_group_id=$(aws ec2 describe-security-groups --filters Name=group-name,Values=assurance-testing-mavis-development-sg --query 'SecurityGroups[0].GroupId' --output text)
0 commit comments