2020-10-10 16:44:56 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
### Bash Environment Setup
|
|
|
|
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
|
|
|
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
|
|
|
# set -o xtrace
|
|
|
|
set -o errexit
|
|
|
|
set -o errtrace
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
IFS=$'\n'
|
|
|
|
|
|
|
|
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )"
|
2023-03-13 08:55:28 -04:00
|
|
|
cd "$REPO_DIR"
|
|
|
|
which docker > /dev/null || exit 1
|
|
|
|
|
|
|
|
|
|
|
|
TAG_NAME="dev"
|
2020-10-10 16:44:56 -04:00
|
|
|
VERSION="$(jq -r '.version' < "$REPO_DIR/package.json")"
|
2021-01-10 19:50:57 -05:00
|
|
|
SHORT_VERSION="$(echo "$VERSION" | perl -pe 's/(\d+)\.(\d+)\.(\d+)/$1.$2/g')"
|
2023-03-13 08:55:28 -04:00
|
|
|
REQUIRED_PLATFORMS=('linux/arm64','linux/amd64','linux/arm/v8','linux/arm/v7')
|
|
|
|
|
|
|
|
function check_platforms() {
|
|
|
|
INSTALLED_PLATFORMS="$(docker buildx inspect | grep 'Platforms:' )"
|
|
|
|
|
|
|
|
for REQUIRED_PLATFORM in ${REQUIRED_PLATFORMS//,/$IFS}; do
|
|
|
|
echo "[+] Checking for: $REQUIRED_PLATFORM..."
|
|
|
|
if ! (echo "$INSTALLED_PLATFORMS" | grep -q "$REQUIRED_PLATFORM"); then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_builder() {
|
|
|
|
echo "[+] Creating new xbuilder for: $REQUIRED_PLATFORMS"
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Switch to buildx builder if already present / previously created
|
|
|
|
docker buildx create --name xbuilder --driver docker-container --bootstrap --use --platform "$REQUIRED_PLATFORMS" || true
|
|
|
|
docker buildx inspect --bootstrap || true
|
|
|
|
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
function recreate_builder() {
|
|
|
|
# Install QEMU binaries for cross-platform building if not installed
|
|
|
|
docker run --privileged --rm 'tonistiigi/binfmt' --install all
|
2020-10-10 16:44:56 -04:00
|
|
|
|
2023-03-13 08:55:28 -04:00
|
|
|
# remove existing xbuilder
|
|
|
|
docker buildx stop xbuilder || true
|
|
|
|
docker buildx rm xbuilder || true
|
2020-10-10 16:44:56 -04:00
|
|
|
|
2023-03-13 08:55:28 -04:00
|
|
|
# Create Docker builder for cross-platform building
|
|
|
|
docker buildx use xbuilder && return 0
|
2023-03-13 07:57:20 -04:00
|
|
|
|
2023-03-13 08:55:28 -04:00
|
|
|
create_builder
|
|
|
|
}
|
2023-03-13 07:57:20 -04:00
|
|
|
|
|
|
|
|
2023-03-13 08:55:28 -04:00
|
|
|
# Check if docker is ready for cross-plaform builds, if not, recreate builder
|
|
|
|
docker buildx use xbuilder || create_builder
|
|
|
|
check_platforms || (recreate_builder && check_platforms) || exit 1
|
2023-03-13 07:57:20 -04:00
|
|
|
|
|
|
|
|
2021-02-01 03:09:31 -05:00
|
|
|
echo "[+] Building archivebox:$VERSION docker image..."
|
2023-03-13 07:57:20 -04:00
|
|
|
#docker build . \
|
2023-03-13 08:55:28 -04:00
|
|
|
docker buildx build --platform "$REQUIRED_PLATFORMS" --push . \
|
2023-03-13 07:57:20 -04:00
|
|
|
-t archivebox \
|
|
|
|
-t archivebox:$TAG_NAME \
|
2020-10-10 16:44:56 -04:00
|
|
|
-t archivebox:$VERSION \
|
2021-01-10 19:50:57 -05:00
|
|
|
-t archivebox:$SHORT_VERSION \
|
2023-03-13 07:57:20 -04:00
|
|
|
-t docker.io/nikisweeting/archivebox:$TAG_NAME \
|
2020-10-10 16:44:56 -04:00
|
|
|
-t docker.io/nikisweeting/archivebox:$VERSION \
|
2021-01-10 19:50:57 -05:00
|
|
|
-t docker.io/nikisweeting/archivebox:$SHORT_VERSION \
|
2023-03-13 07:57:20 -04:00
|
|
|
-t docker.io/archivebox/archivebox:$TAG_NAME \
|
2020-11-23 02:20:01 -05:00
|
|
|
-t docker.io/archivebox/archivebox:$VERSION \
|
2021-01-10 19:50:57 -05:00
|
|
|
-t docker.io/archivebox/archivebox:$SHORT_VERSION \
|
2023-03-13 07:57:20 -04:00
|
|
|
-t docker.pkg.github.com/archivebox/archivebox/archivebox:$TAG_NAME \
|
2021-02-01 03:09:31 -05:00
|
|
|
-t docker.pkg.github.com/archivebox/archivebox/archivebox:$VERSION \
|
|
|
|
-t docker.pkg.github.com/archivebox/archivebox/archivebox:$SHORT_VERSION
|