2020-02-01 04:07:42 +08:00
|
|
|
#!/usr/bin/env bash
|
2022-06-09 17:19:56 +08:00
|
|
|
set -e
|
2020-02-01 04:07:42 +08:00
|
|
|
# Do a multistage build
|
|
|
|
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
export DOCKER_CLI_EXPERIMENTAL=enabled
|
2021-11-10 21:12:14 +08:00
|
|
|
export BUILDKIT_PROGRESS=plain
|
2020-02-01 04:07:42 +08:00
|
|
|
|
2022-04-13 16:16:42 +08:00
|
|
|
declare cache_dir
|
2022-04-13 15:57:46 +08:00
|
|
|
declare arg_list
|
2022-04-13 16:16:42 +08:00
|
|
|
|
|
|
|
if [[ "$CI" == "true" ]]; then
|
2022-04-13 17:34:37 +08:00
|
|
|
if [[ -f "/tmp/.buildx-cache/alpine/index.json" ]]; then
|
|
|
|
arg_list="$arg_list --cache-from type=local,src=/tmp/.buildx-cache/alpine/index.json"
|
|
|
|
fi
|
2022-04-13 16:16:42 +08:00
|
|
|
fi
|
2022-04-13 15:57:46 +08:00
|
|
|
|
2022-04-13 17:34:37 +08:00
|
|
|
cache_from="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/cache"
|
|
|
|
cache_to="${cache_from}"
|
|
|
|
|
2020-02-01 04:07:42 +08:00
|
|
|
if ! docker buildx inspect multiarch > /dev/null; then
|
|
|
|
docker buildx create --name multiarch
|
|
|
|
fi
|
|
|
|
docker buildx use multiarch
|
|
|
|
|
|
|
|
if [[ "$*" == *--push* ]]; then
|
|
|
|
if [[ -n "$DOCKER_USERNAME" ]] && [[ -n "$DOCKER_PASSWORD" ]]; then
|
|
|
|
echo "Logging into docker registry $DOCKER_REGISTRY_URL...."
|
|
|
|
echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USERNAME --password-stdin $DOCKER_REGISTRY_URL
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-04-13 16:16:42 +08:00
|
|
|
arg_list=" --cache-to type=local,dest=${cache_to}"
|
2022-06-09 17:19:56 +08:00
|
|
|
if [[ -f "${cache_from}/index.json" ]]; then
|
|
|
|
arg_list="$arg_list --cache-from type=local,src=${cache_from}"
|
2022-04-13 15:57:46 +08:00
|
|
|
else
|
2022-06-09 17:19:56 +08:00
|
|
|
mkdir -p "${cache_from}"
|
2022-04-13 15:57:46 +08:00
|
|
|
fi
|
|
|
|
|
2022-04-13 16:16:42 +08:00
|
|
|
#if [[ -z "$PLATFORMS" ]]; then
|
2022-06-09 17:19:56 +08:00
|
|
|
# arg_list="$arg_list --platform linux/amd64,linux/arm64,linux/arm/v7"
|
2022-04-13 16:16:42 +08:00
|
|
|
#fi
|
2022-04-13 15:57:46 +08:00
|
|
|
|
2024-01-07 23:51:33 +08:00
|
|
|
set -x
|
|
|
|
exec docker buildx build ${arg_list} $* .
|
2020-02-01 04:07:42 +08:00
|
|
|
|