Use "git show" to get the Dockerfile for deferring based on FROM

This gives roughly a full 2x speedup when doing `./build.sh --no-build --all`.
This commit is contained in:
Tianon Gravi 2014-10-03 10:17:20 -06:00
parent 9756c6a8e0
commit 824cb8004f
1 changed files with 19 additions and 13 deletions

View File

@ -231,23 +231,17 @@ while [ "$#" -gt 0 ]; do
continue continue
fi fi
( set -x; cd "$gitRepo" && git reset -q HEAD && git checkout -q -- . && git clean -dfxq && git checkout -q "$gitRef" -- ) &>> "$thisLog" dockerfilePath="$gitDir/Dockerfile"
# TODO git tag dockerfilePath="${dockerfilePath#/}" # strip leading "/" (for when gitDir is '') because "git show" doesn't like it
if [ ! -d "$gitRepo/$gitDir" ]; then if ! dockerfile="$(cd "$gitRepo" && git show "$gitRef":"$dockerfilePath")"; then
echo "- failed; invalid dir: '$gitDir'" echo "- failed; missing '$dockerfilePath' at '$gitRef' ?"
didFail=1
continue
fi
if [ ! -f "$gitRepo/$gitDir/Dockerfile" ]; then
echo "- failed; missing $gitDir/Dockerfile"
didFail=1 didFail=1
continue continue
fi fi
IFS=$'\n' IFS=$'\n'
froms=( $(grep -i '^FROM[[:space:]]' "$gitRepo/$gitDir/Dockerfile" | awk '{ print $2 ~ /:/ ? $2 : $2":latest" }') ) froms=( $(echo "$dockerfile" | awk 'toupper($1) == "FROM" { print $2 ~ /:/ ? $2 : $2":latest" }') )
unset IFS unset IFS
for from in "${froms[@]}"; do for from in "${froms[@]}"; do
@ -262,9 +256,21 @@ while [ "$#" -gt 0 ]; do
done done
if [ "$doBuild" ]; then if [ "$doBuild" ]; then
( set -x; cd "$gitRepo/$gitDir" && "$dir/git-set-mtimes" ) &>> "$thisLog" (
set -x
cd "$gitRepo"
git reset -q HEAD
git checkout -q -- .
git clean -dfxq
git checkout -q "$gitRef" --
cd "$gitRepo/$gitDir"
"$dir/git-set-mtimes"
) &>> "$thisLog"
if ! ( set -x; docker build -t "$repoTag" "$gitRepo/$gitDir" ) &>> "$thisLog"; then if ! (
set -x
docker build -t "$repoTag" "$gitRepo/$gitDir"
) &>> "$thisLog"; then
echo "- failed; see $thisLog" echo "- failed; see $thisLog"
didFail=1 didFail=1
continue continue