Parameterize library, src, logs, and namespaces
This commit is contained in:
parent
02592be363
commit
2f9fd1c571
85
build.sh
85
build.sh
|
|
@ -3,15 +3,14 @@ set -e
|
||||||
|
|
||||||
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
||||||
|
|
||||||
# TODO config file of some kind
|
library="$dir/../library"
|
||||||
: ${LIBRARY:="$dir/../library"} # where we get the "library/*" repo manifests
|
src="$dir/src"
|
||||||
: ${SRC:="$dir/src"} # where we clone all the repos, go-style
|
logs="$dir/logs"
|
||||||
: ${LOGS:="$dir/logs"} # where "docker build" logs go
|
namespaces='library stackbrew'
|
||||||
: ${NAMESPACES:='library stackbrew'} # after we build, also tag each image as "NAMESPACE/repo:tag"
|
|
||||||
|
|
||||||
LIBRARY="$(readlink -f "$LIBRARY")"
|
library="$(readlink -f "$library")"
|
||||||
SRC="$(readlink -f "$SRC")"
|
src="$(readlink -f "$src")"
|
||||||
LOGS="$(readlink -f "$LOGS")"
|
logs="$(readlink -f "$logs")"
|
||||||
|
|
||||||
# arg handling: all args are [repo|repo:tag]
|
# arg handling: all args are [repo|repo:tag]
|
||||||
usage() {
|
usage() {
|
||||||
|
|
@ -26,28 +25,23 @@ usage: $0 [options] [repo[:tag] ...]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
--help, -h, -? Print this help message
|
--help, -h, -? Print this help message
|
||||||
--all Builds all docker repos specified in LIBRARY
|
--all Builds all docker repos specified in library
|
||||||
--no-clone Don't pull the git repos
|
--no-clone Don't pull the git repos
|
||||||
--no-build Don't build, just echo what would have built
|
--no-build Don't build, just echo what would have built
|
||||||
|
--library="$library"
|
||||||
variables:
|
Where to find repository manifest files
|
||||||
# where to find repository manifest files
|
--src="$src"
|
||||||
LIBRARY="$LIBRARY"
|
Where to store the cloned git repositories
|
||||||
|
--logs="$logs"
|
||||||
# where to store the cloned git repositories
|
Where to store the build logs
|
||||||
SRC="$SRC"
|
--namespaces="$namespaces"
|
||||||
|
Space separated list of namespaces to tag images in after
|
||||||
# where to store the build logs
|
building
|
||||||
LOGS="$LOGS"
|
|
||||||
|
|
||||||
# which additional namespaces to tag images under
|
|
||||||
# NOTE: all images will be tagged in the empty namespace
|
|
||||||
NAMESPACES="$NAMESPACES"
|
|
||||||
|
|
||||||
EOUSAGE
|
EOUSAGE
|
||||||
}
|
}
|
||||||
|
|
||||||
opts="$(getopt -o 'h?' --long 'all,help,no-build,no-clone' -- "$@" || { usage >&2 && false; })"
|
opts="$(getopt -o 'h?' --long 'all,help,no-build,no-clone,library:,src:,logs:,namespaces:' -- "$@" || { usage >&2 && false; })"
|
||||||
eval set -- "$opts"
|
eval set -- "$opts"
|
||||||
|
|
||||||
doClone=1
|
doClone=1
|
||||||
|
|
@ -58,24 +52,24 @@ while true; do
|
||||||
shift
|
shift
|
||||||
case "$flag" in
|
case "$flag" in
|
||||||
--help|-h|'-?')
|
--help|-h|'-?')
|
||||||
uasge
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--all)
|
--all) buildAll=1 ;;
|
||||||
buildAll=1
|
--no-clone) doClone= ;;
|
||||||
;;
|
--no-build) doBuild= ;;
|
||||||
--no-clone)
|
--library) library="$1" && shift ;;
|
||||||
doClone=
|
--src) src="$1" && shift ;;
|
||||||
;;
|
--logs) logs="$1" && shift ;;
|
||||||
--no-build)
|
--namespaces) namespaces="$1" && shift ;;
|
||||||
doBuild=
|
|
||||||
;;
|
|
||||||
--)
|
--)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo >&2 "error: unknown flag: $flag"
|
{
|
||||||
usage >&2
|
echo "error: unknown flag: $flag"
|
||||||
|
usage
|
||||||
|
} >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -83,10 +77,10 @@ done
|
||||||
|
|
||||||
repos=()
|
repos=()
|
||||||
if [ "$buildAll" ]; then
|
if [ "$buildAll" ]; then
|
||||||
repos=( $(cd "$LIBRARY" && echo *) )
|
repos=( $(cd "$library" && echo *) )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
repos+=( "$@" )
|
repos+=( "$@" )
|
||||||
|
|
||||||
repos=( "${repos[@]%/}" )
|
repos=( "${repos[@]%/}" )
|
||||||
|
|
||||||
if [ "${#repos[@]}" -eq 0 ]; then
|
if [ "${#repos[@]}" -eq 0 ]; then
|
||||||
|
|
@ -101,13 +95,10 @@ declare -A repoGitRepo=()
|
||||||
declare -A repoGitRef=()
|
declare -A repoGitRef=()
|
||||||
declare -A repoGitDir=()
|
declare -A repoGitDir=()
|
||||||
|
|
||||||
logDir="$LOGS/build-$(date +'%Y-%m-%d--%H-%M-%S')"
|
logDir="$logs/build-$(date +'%Y-%m-%d--%H-%M-%S')"
|
||||||
mkdir -p "$logDir"
|
mkdir -p "$logDir"
|
||||||
for repo in "${repos[@]}"; do
|
|
||||||
echo "$repo" >> "$logDir/repos.txt"
|
|
||||||
done
|
|
||||||
|
|
||||||
latestLogDir="$LOGS/latest" # this gets shiny symlinks to the latest buildlog for each repo we've seen since the creation of the LOGS dir
|
latestLogDir="$logs/latest" # this gets shiny symlinks to the latest buildlog for each repo we've seen since the creation of the logs dir
|
||||||
mkdir -p "$latestLogDir"
|
mkdir -p "$latestLogDir"
|
||||||
|
|
||||||
# gather all the `repo:tag` combos to build
|
# gather all the `repo:tag` combos to build
|
||||||
|
|
@ -116,6 +107,8 @@ for repoTag in "${repos[@]}"; do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "$repoTag" >> "$logDir/repos.txt"
|
||||||
|
|
||||||
if [ "${repoGitRepo[$repoTag]}" ]; then
|
if [ "${repoGitRepo[$repoTag]}" ]; then
|
||||||
queue+=( "$repoTag" )
|
queue+=( "$repoTag" )
|
||||||
continue
|
continue
|
||||||
|
|
@ -125,7 +118,7 @@ for repoTag in "${repos[@]}"; do
|
||||||
|
|
||||||
# parse the repo library file
|
# parse the repo library file
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
repoTagLines=( $(cat "$LIBRARY/$repo" | grep -vE '^#|^\s*$') )
|
repoTagLines=( $(cat "$library/$repo" | grep -vE '^#|^\s*$') )
|
||||||
unset IFS
|
unset IFS
|
||||||
|
|
||||||
tags=()
|
tags=()
|
||||||
|
|
@ -141,7 +134,7 @@ for repoTag in "${repos[@]}"; do
|
||||||
gitRepo="${gitRepo%/}"
|
gitRepo="${gitRepo%/}"
|
||||||
gitRepo="${gitRepo%.git}"
|
gitRepo="${gitRepo%.git}"
|
||||||
gitRepo="${gitRepo%/}"
|
gitRepo="${gitRepo%/}"
|
||||||
gitRepo="$SRC/$gitRepo"
|
gitRepo="$src/$gitRepo"
|
||||||
|
|
||||||
if [ -z "$doClone" ]; then
|
if [ -z "$doClone" ]; then
|
||||||
if [ "$doBuild" -a ! -d "$gitRepo" ]; then
|
if [ "$doBuild" -a ! -d "$gitRepo" ]; then
|
||||||
|
|
@ -213,7 +206,7 @@ while [ "$#" -gt 0 ]; do
|
||||||
ln -sf "$thisLog" "$latestLogDir/$(basename "$thisLog")"
|
ln -sf "$thisLog" "$latestLogDir/$(basename "$thisLog")"
|
||||||
docker build -t "$repoTag" "$gitRepo/$gitDir" &> "$thisLog"
|
docker build -t "$repoTag" "$gitRepo/$gitDir" &> "$thisLog"
|
||||||
|
|
||||||
for namespace in $NAMESPACES; do
|
for namespace in $namespaces; do
|
||||||
docker tag "$repoTag" "$namespace/$repoTag"
|
docker tag "$repoTag" "$namespace/$repoTag"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue