-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·126 lines (101 loc) · 2.94 KB
/
build.sh
File metadata and controls
executable file
·126 lines (101 loc) · 2.94 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)
COMMON_ARGS=
TAG="local"
USERNAME=joelnb
VERBOSE=
build_all_images() {
while read -rd $'\0' imagedir; do
build_image_dir "${imagedir}"
done < <(find "${DIR}" -mindepth 1 -maxdepth 1 -not -name ".git*" -type d -print0 | sort)
}
build_image_dir() {
local path="${1:-}"
if [ -z "${path}" ]; then
return 1
fi
local image_name
image_name="$(basename "${path}")"
local whole_tag="${TAG}"
if [ -n "${whole_tag}" ]; then
whole_tag=":${whole_tag}"
fi
echo "==>" docker build -t "${USERNAME}/${image_name}${whole_tag}""${COMMON_ARGS}" "${path}"
eval sudo docker build -t "${USERNAME}/${image_name}${whole_tag}""${COMMON_ARGS}" "${path}"
while read -rd $'\0' dockerfile; do
local dockerfile_dir
dockerfile_dir="$(dirname "${dockerfile}")"
local variant
variant="$(basename "${dockerfile_dir}")"
local this_image_tag=":${variant}"
if [ -n "${TAG}" ]; then
this_image_tag=":${TAG}-${variant}"
fi
echo "==>" docker build -t "${USERNAME}/${image_name}${this_image_tag}""${COMMON_ARGS}" -f "${dockerfile}" "${dockerfile_dir}"
eval sudo docker build -t "${USERNAME}/${image_name}${this_image_tag}""${COMMON_ARGS}" -f "${dockerfile}" "${dockerfile_dir}"
done < <(find "${path}" -mindepth 2 -name 'Dockerfile' -print0)
while read -rd $'\0' dockerfile; do
dockerfile="$(basename "${dockerfile}")"
local variant
variant="${dockerfile//Dockerfile-/}"
local this_image_tag=":${variant}"
if [ -n "${TAG}" ]; then
this_image_tag=":${TAG}-${variant}"
fi
echo "==>" docker build -t "${USERNAME}/${image_name}${this_image_tag}""${COMMON_ARGS}" -f "${path}/${dockerfile}" "${path}"
eval sudo docker build -t "${USERNAME}/${image_name}${this_image_tag}""${COMMON_ARGS}" -f "${path}/${dockerfile}" "${path}"
done < <(find "${path}" -mindepth 1 -maxdepth 1 -name 'Dockerfile-*' -print0)
}
usage() {
cat <<EOF
usage: $(basename "$0") [DIRECTORY]
Build dockerfiles for testing.
ARGUMENTS:
DIRECTORY The directory containing the Dockerfile. If no directory
is specified as then all directories in the same location
as this script will be built.
OPTIONS:
-h Show this message.
-n Pass the '--no-cache' option to docker build.
-t TAG A tag to apply to the built image [default: local].
-u USER The username to name images under [default: ${USERNAME}]
-V Increase output verbosity.
EOF
exit 1
}
while getopts "hnt:u:V" OPTION; do
case $OPTION in
h)
usage
;;
n)
COMMON_ARGS="${COMMON_ARGS} --no-cache"
;;
t)
TAG="$OPTARG"
;;
u)
USERNAME=$OPTARG
;;
V)
VERBOSE=1
;;
?)
usage
;;
esac
done
shift $((OPTIND - 1))
DIRECTORY="${1:-}"
[ -n "${DIRECTORY}" ] && shift
if [ -n "${1:-}" ]; then
echo "Unknown arguments: $*"
usage
fi
if [ -z "${DIRECTORY}" ]; then
build_all_images
else
build_image_dir "${DIRECTORY}"
fi