forked from bokysan/docker-postfix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·59 lines (47 loc) · 1.51 KB
/
build.sh
File metadata and controls
executable file
·59 lines (47 loc) · 1.51 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -e
# Do a multistage build
export DOCKER_BUILDKIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled
export BUILDKIT_PROGRESS=plain
declare cache_dir
declare arg_list
if [[ "$CI" == "true" ]]; then
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
fi
if command -v docker >/dev/null 2>&1; then
DOCKER="docker"
elif command -v podman >/dev/null 2>&1; then
DOCKER="podman"
else
echo "Neither `docker` or `podman` installed. Cannot execute tests."
exit 1
fi
if ! ${DOCKER} buildx inspect multiarch > /dev/null; then
${DOCKER} buildx create --name multiarch
fi
if [[ "${DOCKER}" == "docker" ]]; then
cache_from="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/cache"
cache_to="${cache_from}"
${DOCKER} buildx use multiarch
fi
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
if [[ -n "${cache_to}" ]]; then
arg_list=" --cache-to type=local,dest=${cache_to}"
fi
if [[ -n "${cache_from}" ]]; then
if [[ -f "${cache_from}/index.json" ]]; then
arg_list="$arg_list --cache-from type=local,src=${cache_from}"
else
mkdir -p "${cache_from}"
fi
fi
set -x
exec ${DOCKER} buildx build ${arg_list} $* .