forked from hmcts/cnp-node-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-build.sh
executable file
·75 lines (59 loc) · 1.51 KB
/
test-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
#
# Run a test build for a given image.
#
# Sample usage:
#
# $ ./test-build.sh <image tag> <image version>
#
set -euo pipefail
info() {
printf "%s\\n" "$@"
}
fatal() {
printf "/!\ Fatal Error: %s\\n" "$@"
exit 1
}
removeTrailingspaces () {
sed -e 's/[[:space:]]*$//' "$@"
}
tag=${1}
version=${2-latest}
info "Testing ${tag}:${version}"
testUser() {
local hmctsUser
local whoami
hmctsUser="hmcts"
expectedId="uid=1000(hmcts) gid=1000(hmcts) groups=1000(hmcts)"
whoami=$(echo `docker run --rm ${tag}:${version} id` | removeTrailingspaces)
if [[ "$whoami" == *"$expectedId"* ]]; then
info "OK User $hmctsUser as expected"
else
fatal "User $hmctsUser not as expected: $whoami | should be $expectedId"
fi
}
testWorkdir() {
local defaultWorkdir
local workDir
defaultWorkdir="/opt/app"
workDir=$(echo `docker run --rm ${tag}:${version} pwd` | removeTrailingspaces)
if [[ "$workDir" != "$defaultWorkdir" ]]; then
fatal "Workdir is not $defaultWorkdir. Workdir found: $workDir"
else
info "OK Workdir is $defaultWorkdir"
fi
}
testDefaultCmd() {
local defaultCmd
local cmd
defaultCmd="[\"yarn\",\"start\"]"
cmd=$(echo `docker inspect --format='{{json .Config.Cmd}}' ${tag}:${version}`)
if [[ "$cmd" != "$defaultCmd" ]]; then
fatal "Default CMD is not $defaultCmd. Default CMD found: $cmd"
else
info "OK Default CMD is $defaultCmd"
fi
}
testUser
testWorkdir
testDefaultCmd