Finish combining to one script, make nifty helpers
This commit is contained in:
parent
0c8a366888
commit
9318c9a41f
|
|
@ -254,14 +254,14 @@ while [ "$#" -gt 0 ]; do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Processing $repoTag ..."
|
|
||||||
|
|
||||||
thisLog="$logDir/$subcommand-$repoTag.log"
|
thisLog="$logDir/$subcommand-$repoTag.log"
|
||||||
touch "$thisLog"
|
touch "$thisLog"
|
||||||
ln -sf "$thisLog" "$latestLogDir/$(basename "$thisLog")"
|
ln -sf "$thisLog" "$latestLogDir/$(basename "$thisLog")"
|
||||||
|
|
||||||
case "$subcommand" in
|
case "$subcommand" in
|
||||||
build)
|
build)
|
||||||
|
echo "Processing $repoTag ..."
|
||||||
|
|
||||||
if ! ( cd "$gitRepo" && git rev-parse --verify "${gitRef}^{commit}" &> /dev/null ); then
|
if ! ( cd "$gitRepo" && git rev-parse --verify "${gitRef}^{commit}" &> /dev/null ); then
|
||||||
echo "- failed; invalid ref: $gitRef"
|
echo "- failed; invalid ref: $gitRef"
|
||||||
didFail=1
|
didFail=1
|
||||||
|
|
@ -321,8 +321,9 @@ while [ "$#" -gt 0 ]; do
|
||||||
push)
|
push)
|
||||||
for namespace in $namespaces; do
|
for namespace in $namespaces; do
|
||||||
if [ "$doPush" ]; then
|
if [ "$doPush" ]; then
|
||||||
if ! "$docker" push "$namespace/$repoTag"; then
|
echo "Pushing $namespace/$repoTag..."
|
||||||
echo >&2 "- $namespace/$repoTag failed to push!"
|
if ! "$docker" push "$namespace/$repoTag" &> "$thisLog"; then
|
||||||
|
echo >&2 "- $namespace/$repoTag failed to push; see $thisLog"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$docker push" "$namespace/$repoTag"
|
echo "$docker push" "$namespace/$repoTag"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
||||||
|
|
||||||
|
exec "$dir/bashbrew.sh" build "$@"
|
||||||
129
push.sh
129
push.sh
|
|
@ -1,133 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# so we can have fancy stuff like !(pattern)
|
|
||||||
shopt -s extglob
|
|
||||||
|
|
||||||
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
||||||
|
|
||||||
library="$dir/../library"
|
exec "$dir/bashbrew.sh" push "$@"
|
||||||
logs="$dir/logs"
|
|
||||||
namespaces='library stackbrew'
|
|
||||||
docker='docker'
|
|
||||||
|
|
||||||
library="$(readlink -f "$library")"
|
|
||||||
logs="$(readlink -f "$logs")"
|
|
||||||
# TODO actually log stuff
|
|
||||||
|
|
||||||
# arg handling: all args are [repo|repo:tag]
|
|
||||||
usage() {
|
|
||||||
cat <<EOUSAGE
|
|
||||||
|
|
||||||
usage: $0 [options] [repo[:tag] ...]
|
|
||||||
ie: $0 --all
|
|
||||||
$0 debian ubuntu:12.04
|
|
||||||
|
|
||||||
This script pushes the specified Docker images from library that are built
|
|
||||||
and tagged in the specified namespaces.
|
|
||||||
|
|
||||||
options:
|
|
||||||
--help, -h, -? Print this help message
|
|
||||||
--all Pushes all Docker images built for the given namespaces
|
|
||||||
--no-push Don't actually push the images to the Docker Hub
|
|
||||||
--library="$library"
|
|
||||||
Where to find repository manifest files
|
|
||||||
--namespaces="$namespaces"
|
|
||||||
Space separated list of namespaces to tag images in after
|
|
||||||
building
|
|
||||||
--docker="$docker"
|
|
||||||
Use a custom Docker binary.
|
|
||||||
|
|
||||||
EOUSAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
opts="$(getopt -o 'h?' --long 'help,all,no-push,library:,logs:,namespaces:,docker:' -- "$@" || { usage >&2 && false; })"
|
|
||||||
eval set -- "$opts"
|
|
||||||
|
|
||||||
doPush=1
|
|
||||||
buildAll=
|
|
||||||
while true; do
|
|
||||||
flag=$1
|
|
||||||
shift
|
|
||||||
case "$flag" in
|
|
||||||
--help|-h|'-?')
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--all) buildAll=1 ;;
|
|
||||||
--no-push) doPush= ;;
|
|
||||||
--library) library="$1" && shift ;;
|
|
||||||
--logs) logs="$1" && shift ;;
|
|
||||||
--namespaces) namespaces="$1" && shift ;;
|
|
||||||
--docker) docker="$1" && shift ;;
|
|
||||||
--)
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
{
|
|
||||||
echo "error: unknown flag: $flag"
|
|
||||||
usage
|
|
||||||
} >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
repos=()
|
|
||||||
if [ "$buildAll" ]; then
|
|
||||||
repos=( "$library"/!(MAINTAINERS) )
|
|
||||||
fi
|
|
||||||
repos+=( "$@" )
|
|
||||||
|
|
||||||
repos=( "${repos[@]%/}" )
|
|
||||||
|
|
||||||
if [ "${#repos[@]}" -eq 0 ]; then
|
|
||||||
echo >&2 'error: no repos specified'
|
|
||||||
usage >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
for repoTag in "${repos[@]}"; do
|
|
||||||
repo="${repoTag%%:*}"
|
|
||||||
tag="${repoTag#*:}"
|
|
||||||
[ "$repo" != "$tag" ] || tag=
|
|
||||||
|
|
||||||
if [ -f "$repo" ]; then
|
|
||||||
repoFile="$repo"
|
|
||||||
repo="$(basename "$repoFile")"
|
|
||||||
repoTag="${repo}${tag:+:$tag}"
|
|
||||||
else
|
|
||||||
repoFile="$library/$repo"
|
|
||||||
fi
|
|
||||||
|
|
||||||
repoFile="$(readlink -f "$repoFile")"
|
|
||||||
|
|
||||||
# parse the repo library file
|
|
||||||
IFS=$'\n'
|
|
||||||
tagList=( $(awk -F ': +' '!/^#|^\s*$/ { print $1 }' "$repoFile") )
|
|
||||||
unset IFS
|
|
||||||
|
|
||||||
tags=()
|
|
||||||
for tag in "${tagList[@]}"; do
|
|
||||||
tags+=( "$repo:$tag" )
|
|
||||||
done
|
|
||||||
|
|
||||||
pushes=()
|
|
||||||
if [ "$repo" = "$repoTag" ]; then
|
|
||||||
pushes=( "${tags[@]}" )
|
|
||||||
else
|
|
||||||
pushes+=( "$repoTag" )
|
|
||||||
fi
|
|
||||||
|
|
||||||
for pushTag in "${pushes[@]}"; do
|
|
||||||
for namespace in $namespaces; do
|
|
||||||
if [ "$doPush" ]; then
|
|
||||||
if ! "$docker" push "$namespace/$pushTag"; then
|
|
||||||
echo >&2 "- $namespace/$pushTag failed to push!"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "$docker push" "$namespace/$pushTag"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue