forked from bokysan/docker-postfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·38 lines (28 loc) · 1.01 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
# Do a multistage build
export DOCKER_BUILDKIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled
export BUILDKIT_PROGRESS=plain
declare cache_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/cache"
declare arg_list
declare PLATFORMS
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
arg_list=" --cache-to type=local,dest=${cache_dir}"
if [[ -f "${cache_dir}/index.json" ]]; then
arg_list="$arg_list --cache-from type=local,src=${cache_dir}"
else
mkdir -p "${cache_dir}"
fi
if [[ -z "$PLATFORMS" ]]; then
PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7"
fi
docker buildx build ${arg_list} --platform $PLATFORMS . $*