Skip to content

Commit 7e4b55b

Browse files
authored
Merge pull request #123 from NHSDigital/DTOSS-9416-postgres-2
[DTOSS-9416] Wait for db migrate to finish
2 parents 482b31c + 5571aac commit 7e4b55b

4 files changed

Lines changed: 46 additions & 5 deletions

File tree

.azuredevops/pipelines/deploy.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,4 @@ stages:
5555
scriptType: bash
5656
scriptLocation: inlineScript
5757
addSpnToEnvironment: true
58-
inlineScript: |
59-
az containerapp job start --name manage-breast-screening-dbm-${{ env }} --resource-group rg-manbrs-${{ env }}-uks
58+
inlineScript: ./scripts/bash/db_migrate.sh ${{ env }}

scripts/bash/db_migrate.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ENV=$1
6+
JOB_NAME=manage-breast-screening-dbm-${ENV}
7+
RG_NAME=rg-manbrs-${ENV}-uks
8+
TIMEOUT=300
9+
WAIT=5
10+
count=0
11+
12+
get_job_status() {
13+
az containerapp job execution show --job-execution-name "$execution_name" -n "$JOB_NAME" -g "$RG_NAME" | jq -r '.properties.status'
14+
}
15+
16+
echo Starting job "$JOB_NAME"...
17+
execution_name=$(az containerapp job start --name "$JOB_NAME" --resource-group "$RG_NAME" | jq -r '.id|split("/")[-1]')
18+
19+
while [[ $(get_job_status) = "Running" ]]; do
20+
echo The job "$execution_name" is still running...
21+
((count*WAIT > TIMEOUT)) && break
22+
((count+=1))
23+
sleep $WAIT
24+
done
25+
26+
if ((count*WAIT > TIMEOUT)); then
27+
echo "The job \"$execution_name\" timed out (${TIMEOUT}s)"
28+
exit 1
29+
fi
30+
31+
status=$(get_job_status)
32+
if [[ $status = "Succeeded" ]]; then
33+
echo The job "$execution_name" completed successfully
34+
else
35+
echo The job "$execution_name" has not completed successfully. Status: "$status"
36+
exit 2
37+
fi

scripts/docker/docker.lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function docker-build() {
4949

5050
# Tag the image with all the stated versions, see the documentation for more details
5151
for version in $(_get-all-effective-versions) latest; do
52-
if [ ! -z "$version" ]; then
52+
if [ -n "$version" ]; then
5353
docker tag "${tag}" "${DOCKER_IMAGE}:${version}"
5454
fi
5555
done
@@ -312,7 +312,7 @@ function _get-effective-tag() {
312312

313313
local tag=$DOCKER_IMAGE
314314
version=$(_get-effective-version)
315-
if [ ! -z "$version" ]; then
315+
if [ -n "$version" ]; then
316316
tag="${tag}:${version}"
317317
fi
318318
echo "$tag"

scripts/shared.mk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ HELP_SCRIPT = \
5959
} \
6060
}
6161

62+
shellscript-lint-all: # Lint all shell scripts in the scripts directory, do not fail on error, just print the error messages @Quality
63+
for file in $$(find scripts -type f -name "*.sh"); do \
64+
file=$${file} scripts/shellscript-linter.sh ||: ; \
65+
done
66+
6267
.PHONY: _install-tool _install-tools
6368
.ONESHELL:
6469
MAKEFLAGS := --no-print-directory
6570
SHELL := /bin/bash
66-
SHELLFLAGS := -cex
71+
SHELLFLAGS := -cex

0 commit comments

Comments
 (0)