@ -34,6 +34,9 @@ PUSH=${PUSH:-}
# Base is the repository namespace information, not including the wubloader-component part.
# Base is the repository namespace information, not including the wubloader-component part.
BASE="ghcr.io/dbvideostriketeam"
BASE="ghcr.io/dbvideostriketeam"
# cache name is the name of the repository we store shared layer cache in
CACHE_NAME="$BASE/wubloader-cache"
# The docker image tag, derived from the git commit + whether working tree is clean
# The docker image tag, derived from the git commit + whether working tree is clean
TAG=$(./get-build-tag)
TAG=$(./get-build-tag)
@ -41,34 +44,30 @@ if [ "$#" -gt 0 ]; then
COMPONENTS=("$@")
COMPONENTS=("$@")
fi
fi
# If CACHE_FROM is set, explicitly pull and re-use specified image versions
# If CACHE is set, image layers will be pushed to the registry during the build,
CACHE_IMAGES=()
# and re-use any layers from this cache instead of rebuilding them.
CACHE_ARGS=()
# You can set CACHE=readonly to only use the cache and not write to it (eg. due to permissions)
if [ -n "${CACHE_FROM:-}" ]; then
# Setting CACHE requires buildah be installed and configured, as this is used for the build instead of docker.
# Note lack of quotes here - we want to word split
case "${CACHE:-}" in
for commit in $CACHE_FROM; do
"")
if [ "$commit" == "latest" ]; then
CACHE_ARGS=()
tag="latest"
BUILD_CMD="docker"
else
;;
tag=$(git rev-parse --short "$commit")
readonly)
fi
CACHE_ARGS+=("--cache-from" "$CACHE_NAME")
for component in "${COMPONENTS[@]}"; do
BUILD_CMD="buildah"
CACHE_IMAGES+=("$BASE/wubloader-$component:$tag")
;;
CACHE_ARGS+=("--cache-from" "$BASE/wubloader-$component:$tag")
*)
done
CACHE_ARGS+=("--layers" "--cache-to" "$CACHE_NAME" "--cache-from" "$CACHE_NAME")
done
BUILD_CMD="buildah"
echo "Trying to pull images for commits $CACHE_FROM if they exist, to re-use layers if possible"
;;
for image in "${CACHE_IMAGES[@]}"; do
esac
echo "Pulling $image"
docker pull "$image" || true # don't exit on failure
done
fi
for component in "${COMPONENTS[@]}"; do
for component in "${COMPONENTS[@]}"; do
echo "Building image for $component"
echo "Building image for $component"
latest="$BASE/wubloader-$component:latest"
latest="$BASE/wubloader-$component:latest"
specific="$BASE/wubloader-$component:$TAG"
specific="$BASE/wubloader-$component:$TAG"
docker build \
"$BUILD_CMD" build \
-f "$component/Dockerfile" \
-f "$component/Dockerfile" \
-t "$latest" \
-t "$latest" \
-t "$specific" \
-t "$specific" \
@ -77,10 +76,10 @@ for component in "${COMPONENTS[@]}"; do
echo "Built image wubloader-$component:$TAG"
echo "Built image wubloader-$component:$TAG"
if [ -n "$PUSH" ]; then
if [ -n "$PUSH" ]; then
echo "Pushing tag $specific"
echo "Pushing tag $specific"
docker push "$specific"
"$BUILD_CMD" push "$specific"
fi
fi
if [ "$PUSH" == "latest" ]; then
if [ "$PUSH" == "latest" ]; then
echo "Pushing tag $latest"
echo "Pushing tag $latest"
docker push "$latest"
"$BUILD_CMD" push "$latest"
fi
fi
done
done