forked from jlesage/docker-baseimage-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·83 lines (70 loc) · 1.89 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
77
78
79
80
81
82
83
#!/bin/bash
set -e
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
usage() {
if [ "$*" ]; then
echo "$*"
echo
fi
echo "usage: $( basename $0 ) [OPTION]... DOCKER_TAG [DOCKER_TAG]...
Arguments:
DOCKER_TAG Defines the container flavor to build. Valid values are:
$(find "$SCRIPT_DIR"/versions -type f -printf ' %f\n' | sort)
all
Options:
-c, --without-cache Do not use the Docker cache when building.
-h, --help Display this help.
"
}
requirements() {
if [ -z "$( which bats )" ]; then
echo "ERROR: To run test, bats needs to be installed."
fi
}
# Parse arguments.
while [[ $# > 0 ]]
do
key="$1"
case $key in
-c|--without-cache)
USE_DOCKER_BUILD_CACHE=0
;;
-h|--help)
usage
exit 0
;;
-*)
usage "ERROR: Unknown argument: $key"
exit 1
;;
*)
break
;;
esac
shift
done
DOCKER_TAGS="$*"
[ -z "$DOCKER_TAGS" ] && usage "ERROR: At least one Docker tag must be specified." && exit 1
[ "$DOCKER_TAGS" == "all" ] && DOCKER_TAGS="$(find "$SCRIPT_DIR"/versions -type f -printf '%f ' | sort)"
for DOCKER_TAG in $DOCKER_TAGS; do
if [ ! -f "$SCRIPT_DIR"/versions/"$DOCKER_TAG" ]; then
usage "ERROR: Invalid docker tag: $DOCKER_TAG."
exit 1
fi
done
for DOCKER_TAG in $DOCKER_TAGS; do
# Export build variables.
export DOCKER_REPO=jlesage/baseimage-gui
export DOCKER_TAG=$DOCKER_TAG
export USE_DOCKER_BUILD_CACHE=${USE_DOCKER_BUILD_CACHE:-1}
# Build.
hooks/pre_build
hooks/build
# Run tests.
for i in $(seq -s ' ' 1 5 | rev)
do
echo "Starting tests of Docker image $DOCKER_REPO:$DOCKER_TAG in $i..."
sleep 1
done
env DOCKER_IMAGE="$DOCKER_REPO:$DOCKER_TAG" bats tests
done