You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wubloader/build

131 lines
3.6 KiB
Bash

#!/bin/bash
set -eu
# cd to location of script
cd "$(dirname "$(realpath "$0")")"
# Builds the docker images.
# Usage: ./build {COMPONENTS}, or just ./build to build all.
# The resulting images are named wubloader-COMPONENT.
# Pass PUSH=true to also push the resulting images, or PUSH=latest to push them as :latest tag
# The different images we can build
COMPONENTS=(
backfiller
buscribe
buscribe_api
chat_archiver
cutter
downloader
graphs
nginx
playlist_manager
postgres
restreamer
segment_coverage
sheetsync
thrimshim
)
# Define push if not already defined
PUSH=${PUSH:-}
# Base is the repository namespace information, not including the wubloader-component part.
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
TAG=$(./get-build-tag)
if [ "$#" -gt 0 ]; then
COMPONENTS=("$@")
fi
# If CACHE is set, image layers will be pushed to the registry during the build,
# and re-use any layers from this cache instead of rebuilding them.
# You can set CACHE=readonly to only use the cache and not write to it (eg. due to permissions)
# Setting CACHE requires buildah be installed and configured, as this is used for the build instead of docker.
case "${CACHE:-}" in
"")
CACHE_ARGS=()
BUILD_CMD="docker"
;;
readonly)
CACHE_ARGS+=("--cache-from" "$CACHE_NAME")
BUILD_CMD="buildah"
;;
*)
CACHE_ARGS+=("--layers" "--cache-to" "$CACHE_NAME" "--cache-from" "$CACHE_NAME")
BUILD_CMD="buildah"
;;
esac
# check for MULTIPLATFORM flag. error out if we're not using buildah for now. docker buildx should be able to do it too, but needs testing
if [ -n "$MULTIPLATFORM" ]; then
if [ "$BUILD_CMD" == "docker" ]; then
echo "Multiplatform builds are not yet supported with docker! Use buildah instead."
exit 1
fi
fi
for component in "${COMPONENTS[@]}"; do
echo "Building image for $component"
latest="$BASE/wubloader-$component:latest"
specific="$BASE/wubloader-$component:$TAG"
if [ -n "$MULTIPLATFORM" ]; then
echo "Creating multi-arch manifest"
"$BUILD_CMD" manifest create "wubloader-$component"
# no way to build multi-arch in parallel, so just build amd64 first and then arm64.
# caching should work with both, so that'll make things less painful at least.
"$BUILD_CMD" build \
-f "$component/Dockerfile" \
-t "$latest" \
-t "$specific" \
--manifest "wubloader-$component" \
--arch amd64 \
"${CACHE_ARGS[@]}" \
.
# buscribe doesn't (yet?) build under arm64 due to pulling in libc-bin, skip arm64 for it
if [ "$component" != "buscribe" ]; then
"$BUILD_CMD" build \
-f "$component/Dockerfile" \
-t "$latest" \
-t "$specific" \
--manifest "wubloader-$component" \
--arch arm64 \
"${CACHE_ARGS[@]}" \
.
fi
echo "Built image wubloader-$component:$TAG"
# manifest pushes are buildah-specific. docker buildx multiplatform builds have different syntax...
if [ -n "$PUSH" ]; then
echo "Pushing tag $specific"
"$BUILD_CMD" manifest push --all "$specific"
fi
if [ "$PUSH" == "latest" ]; then
echo "Pushing tag $latest"
"$BUILD_CMD" manifest push --all "$latest"
fi
else
"$BUILD_CMD" build \
-f "$component/Dockerfile" \
-t "$latest" \
-t "$specific" \
--manifest "wubloader-$component" \
"${CACHE_ARGS[@]}" \
.
echo "Built image wubloader-$component:$TAG"
if [ -n "$PUSH" ]; then
echo "Pushing tag $specific"
"$BUILD_CMD" push "$specific"
fi
if [ "$PUSH" == "latest" ]; then
echo "Pushing tag $latest"
"$BUILD_CMD" push "$latest"
fi
fi
done