Repository navigation
Expand file tree
/
Copy path_docker.sh
More file actions
120 lines (96 loc) · 2.82 KB
/
Copy path_docker.sh
File metadata and controls
120 lines (96 loc) · 2.82 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
set -eu
docker buildx &> /dev/null || { echo 'Please install docker buildx before proceeding'; exit 1; }
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
# shellcheck source=_log.sh
. "$bindir"/_log.sh
# shellcheck source=_os.sh
. "$bindir"/_os.sh
# TODO this should be set to the canonical public docker registry; we can override this
# docker registry in, for instance, CI.
export DOCKER_REGISTRY=${DOCKER_REGISTRY:-cr.l5d.io/linkerd}
# buildx cache directory
export DOCKER_BUILDKIT_CACHE=${DOCKER_BUILDKIT_CACHE:-}
export DOCKER_TARGET=${DOCKER_TARGET:-$(os)}
# When set together with DOCKER_TARGET=multi-arch, it will push the multi-arch images to the registry
export DOCKER_PUSH=${DOCKER_PUSH:-}
# Default supported docker image architectures
export SUPPORTED_ARCHS=${SUPPORTED_ARCHS:-linux/amd64,linux/arm64,linux/arm/v7}
# Splitting of DOCKER_IMAGES variable is desired.
# shellcheck disable=SC2206
export DOCKER_IMAGES=(${DOCKER_IMAGES:-
cli-bin
cni-plugin
controller
policy-controller
metrics-api
debug
grafana
proxy
web
jaeger-webhook
tap
})
docker_repo() {
repo=$1
name=$repo
if [ -n "${DOCKER_REGISTRY:-}" ]; then
name="$DOCKER_REGISTRY/$name"
fi
echo "$name"
}
docker_build() {
repo=$(docker_repo "$1")
shift
tag=$1
shift
file=$1
shift
rootdir=${ROOTDIR:-$( cd "$bindir"/.. && pwd )}
cache_params=""
if [ -n "$DOCKER_BUILDKIT_CACHE" ]; then
cache_params="--cache-from type=local,src=${DOCKER_BUILDKIT_CACHE} --cache-to type=local,dest=${DOCKER_BUILDKIT_CACHE},mode=max"
fi
if [ -n "$DOCKER_PUSH" ]; then
output_params="--push"
else
output_params="--load"
fi
if [ "$DOCKER_TARGET" = 'multi-arch' ]; then
output_params+=" --platform $SUPPORTED_ARCHS"
if [ -z "$DOCKER_PUSH" ]; then
echo "Error: env DOCKER_PUSH=1 is missing"
echo "When building the multi-arch images it is required to push the images to the registry"
echo "See https://github.com/docker/buildx/issues/59 for more details"
exit 1
fi
fi
log_debug " :; docker buildx $rootdir $cache_params $output_params -t $repo:$tag -f $file $*"
# shellcheck disable=SC2086
docker buildx build "$rootdir" $cache_params \
$output_params \
-t "$repo:$tag" \
-f "$file" \
"$@"
echo "$repo:$tag"
}
docker_pull() {
repo=$(docker_repo "$1")
tag=$2
log_debug " :; docker pull $repo:$tag"
docker pull "$repo:$tag"
}
docker_push() {
repo=$(docker_repo "$1")
tag=$2
log_debug " :; docker push $repo:$tag"
docker push "$repo:$tag"
}
docker_retag() {
repo=$(docker_repo "$1")
from=$2
to=$3
log_debug " :; docker tag $repo:$from $repo:$to"
docker tag "$repo:$from" "$repo:$to"
echo "$repo:$to"
}