forked from docker-library/official-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-and-push.sh
executable file
·76 lines (64 loc) · 1.87 KB
/
build-and-push.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
set -eu -o pipefail
# set "$0" so that tmux shows something more useful than "bash" in the statusbar
desired0='b-a-p'
if ! grep -q "$desired0" "/proc/$$/cmdline"; then
exec -a "$desired0" "$SHELL" -- "$BASH_SOURCE" "$@"
fi
if [ "$#" -eq 0 ]; then
self="$(basename "$0")"
cat >&2 <<-EOF
error: missing arguments
usage: $self <build args>
ie: $self debian ubuntu
EOF
exit 1
fi
# allow for specifying an alternate path to "bashbrew"
: "${BASHBREW:=bashbrew}"
# normalize "$@" to be the "--uniq" versions (and deduplicate)
# also grab the list of associated repos in explicit build order (so we can build/push grouped by repo)
IFS=$'\n'
set -- $("$BASHBREW" list --uniq --repos "$@" | sort -u | xargs "$BASHBREW" list --uniq --repos --build-order --apply-constraints)
repos=( $(echo "$*" | cut -d: -f1 | xargs "$BASHBREW" list --repos --build-order --apply-constraints) )
unset IFS
declare -A repoTags=()
for repoTag; do
repo="${repoTag%%:*}"
repoTags[$repo]+=" $repoTag"
done
# fill "$@" back up with the corrected build order (especially for the "Children:" output)
set --
for repo in "${repos[@]}"; do
set -- "$@" ${repoTags[$repo]}
done
children="$("$(dirname "$BASH_SOURCE")/children.sh" "$@")"
echo
echo
echo "Children: (of $*)"
echo "${children:-<none>}"
echo
echo
for repo in "${repos[@]}"; do
tags=( ${repoTags[$repo]} )
(
set -x
time "$BASHBREW" build "${tags[@]}"
time "$BASHBREW" tag "${tags[@]}"
time "$BASHBREW" push "${tags[@]}"
)
done
echo
echo
echo "Children: (of $*)"
echo "${children:-<none>}"
echo
echo
if [ "$children" ]; then
echo 'Suggested command:'
echo " ./children.sh $* | xargs ./build-and-push.sh"
echo
fi
# end by printing only warnings (stderr) for images we skipped (such as "windowsservercore" when building on Linux)
# this helps remind us to switch BASHBREW or servers
"$BASHBREW" list --apply-constraints "$@" > /dev/null