-
Notifications
You must be signed in to change notification settings - Fork 1
/
dockerbuild.sh
executable file
·68 lines (59 loc) · 1.62 KB
/
dockerbuild.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
#!/bin/bash
#
# Builds and pushes docker images for services used by CI and localdev
set -ue
set -x
declare -A projects=(\
["postgres"]="13.3-alpine"\
["rabbitmq"]="3.9.7-management-alpine"\
["bitnami/redis"]="4.0"\
)
# Should be set before running, else -u will exit non 0.
echo "DOCKER_REMOTE=$DOCKER_REMOTE"
export DOC_REPO="$DOCKER_REMOTE/services"
function build_step() {
# Builds a single target step in a multi-step build
local imagetag="$1"
local dockerpath="${DOC_REPO}/${imagetag}"
local dockerfile=$(echo ${imagetag}.Dockerfile |sed -r 's#[:/]#-#g')
echo "dockerpath: $dockerpath"
echo "dockerfile: $dockerfile"
docker pull $imagetag
user=$(
docker inspect \
-f '{{ .Config.User }}' \
"$imagetag"
)
echo FROM $imagetag > $dockerfile
[ -n "$user" ] && echo USER root >> $dockerfile
cat body.Dockerfile >> $dockerfile
[ -n "$user" ] && echo USER $(
docker inspect \
-f '{{ .Config.User }}' \
"$imagetag"
) >> "$dockerfile"
echo ENTRYPOINT $(
docker inspect \
-f '{{ .Config.Entrypoint | json }}' \
"$imagetag" \
| sed 's#^.#["/usr/local/bin/kubernetes-vault-wrapper.sh",#'
) >> "$dockerfile"
echo CMD $(
docker inspect \
-f '{{ .Config.Cmd | json }}' \
"$imagetag" \
) >> "$dockerfile"
echo "BUILDING $dockerpath with Dockerfile:"
echo "---------"
cat "$dockerfile"
echo "---------"
docker build \
-t $dockerpath \
-f "$dockerfile" \
.
echo docker push $dockerpath
}
export -f build_step
for project in "${!projects[@]}"; do
echo "$project:${projects[$project]}"
done | parallel build_step