#!/bin/sh trap "exit" INT REPO=apotdevin/thunderhub BASE=base TEST_MODE=false # Parse flags while [ "$#" -gt 0 ]; do case "$1" in --test) TEST_MODE=true; shift;; *) echo "Unknown option: $1"; exit 1;; esac done if [ "$TEST_MODE" = true ]; then echo echo "------------------------------------------" echo "Test build (local, no push, no branch switch)" echo "------------------------------------------" echo docker buildx create --name mybuilder --driver-opt network=host --use 2>/dev/null || true START=`date +%s` docker buildx build \ --platform linux/amd64,linux/arm64 \ --tag $REPO:test \ --file ./Dockerfile \ ./ END=`date +%s` RUNTIME=$((END-START)) echo echo "------------------------------------------" echo "DONE - Test build took $RUNTIME seconds" echo "------------------------------------------" echo exit 0 fi echo echo echo "------------------------------------------" echo "Building multiarch image for" $REPO echo "------------------------------------------" echo echo git checkout master || exit git pull || exit VERSION=$(git describe --tags --abbrev=0 2>&1) git checkout $VERSION || exit NOT_LATEST=false echo "Do you want to build images for version" $VERSION "?" select yn in "Yes" "No" "Specify"; do case $yn in Yes ) break;; Specify) NOT_LATEST=true; break;; No ) exit;; esac done if [ "$NOT_LATEST" = true ]; then read -p "Enter the version you want to build: " VERSION git checkout $VERSION || exit fi START=`date +%s` docker buildx create --name mybuilder --driver-opt network=host --use 2>/dev/null || true LATEST_TAGS="" if [ "$NOT_LATEST" = false ]; then LATEST_TAGS="--tag $REPO:latest" fi docker buildx build \ --platform linux/amd64,linux/arm64 \ --tag $REPO:$VERSION \ $LATEST_TAGS \ --file ./Dockerfile \ --push ./ END=`date +%s` echo echo echo "Building basepath multiarch image for" $REPO echo echo docker buildx build \ --build-arg BASE_PATH='/thub' \ --platform linux/amd64,linux/arm64 \ --tag $REPO:$BASE-$VERSION \ --file ./Dockerfile \ --push ./ ENDBASE=`date +%s` RUNTIME=$((END-START)) RUNTIME1=$((ENDBASE-END)) echo echo echo "------------------------------------------" echo "DONE" echo "------------------------------------------" echo echo echo "Finished building and pushing images for" $REPO:$VERSION "and for" $REPO:$BASE-$VERSION echo echo "multiarch took" $RUNTIME "seconds" echo "multiarch base took" $RUNTIME1 "seconds" echo echo