Browse Source

Add uniq option to bashbrew

Joe Ferguson 10 years ago
parent
commit
0a16236a1f
2 changed files with 31 additions and 5 deletions
  1. 30 5
      bashbrew/bashbrew.sh
  2. 1 0
      bashbrew/travis.sh

+ 30 - 5
bashbrew/bashbrew.sh

@@ -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
-		queue+=( "$repoTag" )
+		if [ "$onlyUniq" ]; then
+			uniqLine="${repoGitRepo[$repoTag]}@${repoGitRef[$repoTag]} ${repoGitDir[$repoTag]}"
+			if [ -z "${repoUniq[$uniqLine]}" ]; then
+				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
 
 

+ 1 - 0
bashbrew/travis.sh

@@ -36,6 +36,7 @@ fi
 # TODO that will change eventually!
 # TODO that will change eventually!
 
 
 set -x
 set -x
+./bashbrew.sh list --uniq "${repos[@]}"
 ./bashbrew.sh list "${repos[@]}"
 ./bashbrew.sh list "${repos[@]}"
 ./bashbrew.sh build --no-build "${repos[@]}"
 ./bashbrew.sh build --no-build "${repos[@]}"
 ./bashbrew.sh push --no-push "${repos[@]}"
 ./bashbrew.sh push --no-push "${repos[@]}"