Add uniq option to bashbrew

This commit is contained in:
Joe Ferguson 2015-03-27 16:42:00 -07:00
parent 80748c209c
commit 2f0fbee231
1 changed files with 30 additions and 5 deletions

View File

@ -49,6 +49,10 @@ usage() {
namespace because it is necessary to do so for dependent namespace because it is necessary to do so for dependent
images to use FROM correctly (think "onbuild" variants that images to use FROM correctly (think "onbuild" variants that
are "FROM base-image:some-version") are "FROM base-image:some-version")
--uniq
Only process the first tag of identical images
This is not recommended for build or push
i.e. process python:2.7, but not python:2
build options: build options:
--no-build Don't build, print what would build --no-build Don't build, print what would build
@ -63,13 +67,14 @@ usage() {
} }
# arg handling # arg handling
opts="$(getopt -o 'h?' --long 'all,docker:,help,library:,logs:,namespaces:,no-build,no-clone,no-push,src:' -- "$@" || { usage >&2 && false; })" opts="$(getopt -o 'h?' --long 'all,docker:,help,library:,logs:,namespaces:,no-build,no-clone,no-push,src:,uniq' -- "$@" || { usage >&2 && false; })"
eval set -- "$opts" eval set -- "$opts"
doClone=1 doClone=1
doBuild=1 doBuild=1
doPush=1 doPush=1
buildAll= buildAll=
onlyUniq=
while true; do while true; do
flag="$1" flag="$1"
shift shift
@ -84,6 +89,7 @@ while true; do
--no-clone) doClone= ;; --no-clone) doClone= ;;
--no-push) doPush= ;; --no-push) doPush= ;;
--src) src="$1" && shift ;; --src) src="$1" && shift ;;
--uniq) onlyUniq=1 ;;
--) break ;; --) break ;;
*) *)
{ {
@ -130,6 +136,7 @@ queue=()
declare -A repoGitRepo=() declare -A repoGitRepo=()
declare -A repoGitRef=() declare -A repoGitRef=()
declare -A repoGitDir=() declare -A repoGitDir=()
declare -A repoUniq=()
logDir="$logs/$subcommand-$(date +'%Y-%m-%d--%H-%M-%S')" logDir="$logs/$subcommand-$(date +'%Y-%m-%d--%H-%M-%S')"
mkdir -p "$logDir" mkdir -p "$logDir"
@ -175,7 +182,15 @@ for repoTag in "${repos[@]}"; do
fi fi
if [ "${repoGitRepo[$repoTag]}" ]; then if [ "${repoGitRepo[$repoTag]}" ]; then
if [ "$onlyUniq" ]; then
uniqLine="${repoGitRepo[$repoTag]}@${repoGitRef[$repoTag]} ${repoGitDir[$repoTag]}"
if [ -z "${repoUniq[$uniqLine]}" ]; then
queue+=( "$repoTag" ) queue+=( "$repoTag" )
repoUniq[$uniqLine]=$repoTag
fi
else
queue+=( "$repoTag" )
fi
continue continue
fi fi
@ -247,11 +262,21 @@ for repoTag in "${repos[@]}"; do
tags+=( "$repo:$tag" ) tags+=( "$repo:$tag" )
done done
if [ "$repo" = "$repoTag" ]; then if [ "$repo" != "$repoTag" ]; then
tags=( "$repoTag" )
fi
if [ "$onlyUniq" ]; then
for rt in "${tags[@]}"; do
uniqLine="${repoGitRepo[$rt]}@${repoGitRef[$rt]} ${repoGitDir[$rt]}"
if [ -z "${repoUniq[$uniqLine]}" ]; then
queue+=( "$rt" )
repoUniq[$uniqLine]=$rt
fi
done
else
# add all tags we just parsed # add all tags we just parsed
queue+=( "${tags[@]}" ) queue+=( "${tags[@]}" )
else
queue+=( "$repoTag" )
fi fi
done done