-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_functions.sh
executable file
·80 lines (68 loc) · 2.2 KB
/
make_functions.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
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
#!/bin/bash
set -euf
_build_args_builder() {
build_args=$1
output=""
for build_arg in ${build_args}; do
output="${output} --build-arg ${build_arg}"
done
echo "$output"
}
_tag_argument_builder() {
reg_paths=$1
tags=$2
output=""
for reg_path in ${reg_paths//,/ }; do
for tag in ${tags//,/ }; do
output="${output} -t ${reg_path}:${tag}"
done
done
echo "$output"
}
build_image() {
image=${1-""}
if [ -z "$image" ]; then
echo "You must supply the image to build in images.yaml"
exit 1
fi
output=${2-""}
if [ -z "$output" ]; then
echo "You must supply the docker buildx output to use for image ${image}"
exit 1
fi
is_local=${3-0}
dockerfile=Dockerfile
reg_paths=$(yq -o=c ".images.[\"${image}\"].registry_paths" < images.yaml)
tags=$(yq -o=c ".images.[\"${image}\"].tags" < images.yaml)
platforms=$(yq -o=c ".images.[\"${image}\"].platforms" < images.yaml)
build_args=$(yq -o=t ".images.[\"${image}\"].build_args" < images.yaml)
cmd_build_args=$(_build_args_builder "$build_args")
cmd_tags=$(_tag_argument_builder "$reg_paths" "$tags")
if [[ "${is_local}" -eq 1 ]]; then
cmd_platforms=""
else
cmd_platforms="--platform ${platforms}"
fi
echo "Building ${image} for build args \"$build_args\" and platforms \"$platforms\""
BUILDX_NO_DEFAULT_ATTESTATIONS=true DOCKER_BUILDKIT=1 docker buildx build ${cmd_platforms} ${cmd_build_args} \
-f "$dockerfile" . ${cmd_tags} -o "$output" --progress=auto \
--provenance=false
}
microk8s_image_update() {
image=${1-""}
if [ -z "$image" ]; then
echo "You must supply the image to build in images.yaml"
exit 1
fi
reg_paths=$(yq -o=c ".images.[\"${image}\"].registry_paths" < images.yaml)
tags=$(yq -o=c ".images.[\"${image}\"].tags" < images.yaml)
test_tag=$(yq ".images.[\"${image}\"].test_tag" < images.yaml)
for reg_path in ${reg_paths//,/ }; do
for tag in ${tags//,/ }; do
last_tag=${tag}
docker save "${reg_path}:${tag}" | sudo microk8s.ctr --namespace k8s.io image import -
done
docker tag "${reg_path}:${last_tag}" "${reg_path}:${test_tag}"
docker save "${reg_path}:${test_tag}" | sudo microk8s.ctr --namespace k8s.io image import -
done
}