-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sh
executable file
·76 lines (62 loc) · 1.36 KB
/
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
76
#!/bin/bash
#
# Handles building and publishing tags.
# Usage: `./build.sh silverstripe-web --publish`
#
PUBLISH=0
declare -a BUILD_FOLDERS
for arg in "$@"
do
if [ "$arg" == "--publish" ] || [ "$arg" == "-p" ]
then
PUBLISH=1
else
# arg is a path
if [ -d "$arg" ]; then
BUILD_FOLDERS+="$arg"
fi
fi
done
if [ "$PUBLISH" = 1 ]; then
echo "Building and publishing images: "
for i in "${BUILD_FOLDERS[*]}"; do echo " $i"; done
else
echo "Building images, not publishing. To publish use --publish: "
for i in "${BUILD_FOLDERS[*]}"; do echo " $i"; done
fi
echo ""
for FOLDER in "${BUILD_FOLDERS[@]}"
do
find "$FOLDER" -type d | while IFS= read -r d; do
# convert /7.3 to :7.3
NAME=${d//\//\:}
IMAGE="govtnz/${NAME}"
VERSION=""
# if resources folder then skip
if [[ $string == *":resources:"* ]]; then
continue
fi
# calculate version string
IFS='/'
read -ra ADDR <<< "$IMAGE"
for i in "${ADDR[@]}"; do
VERSION="$i"
done
IFS=' '
if [ "$VERSION" == "" ]; then
continue;
fi
if [ "$VERSION" == $FOLDER ]; then
continue;
fi
echo "### Removing existing ${IMAGE} ###"
docker image rm -f "${IMAGE}"
echo "### Building ${IMAGE} ###"
docker build -t "${IMAGE}" "${d}"
if [ "$PUBLISH" = 1 ]; then
echo "### Publishing {$IMAGE}"
docker push "${IMAGE}"
fi
done
done
echo "### DONE"