Repository navigation
Expand file tree
/
Copy pathmakeimage.sh
More file actions
executable file
·124 lines (105 loc) · 3.84 KB
/
Copy pathmakeimage.sh
File metadata and controls
executable file
·124 lines (105 loc) · 3.84 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
121
122
123
124
#!/bin/bash
set -xeo pipefail
cd "$(dirname "$0")"
source util/vars.sh
docker buildx inspect ffbuilder &>/dev/null || docker buildx create \
--bootstrap \
--name ffbuilder \
--buildkitd-flags "--oci-max-parallelism=4" \
--driver-opt network=host \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=-1
if [[ -z "$NOCLEAN" ]]; then
trap 'rc=$?; [[ $rc -eq 0 ]] && docker buildx rm -f ffbuilder; exit $rc' EXIT
fi
GH_REPO="${REGISTRY}/${REPO}"
BAKE_TARGETS=( image )
if [[ -z "$QUICKBUILD" ]]; then
BAKE_TARGETS+=( target-base )
fi
to_bake() {
printf "$@"
echo
}
trim_cache_spec() {
local value="$1"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
printf '%s' "$value"
}
to_bake_list() {
local key="$1"
shift
printf ' %s = [' "$key"
local separator=""
local value
for value in "$@"; do
printf '%s"%s"' "$separator" "$value"
separator=', '
done
printf ']\n'
}
bake_images() {
local -; set +x
local final_cache_from=()
local final_cache_to=()
local cache_spec
if [[ "${FFBUILD_LOCAL_FINAL_CACHE:-1}" != 0 ]]; then
final_cache_from+=("type=local,src=.cache/${IMAGE/:/_}")
final_cache_to+=("type=local,mode=max,compression=zstd,compression-level=1,dest=.cache/${IMAGE/:/_}")
fi
if [[ -n "${FFBUILD_DOCKER_CACHE_FROM:-}" ]]; then
while IFS= read -r cache_spec; do
cache_spec="$(trim_cache_spec "$cache_spec")"
[[ -n "$cache_spec" ]] || continue
final_cache_from+=("$cache_spec")
done <<< "$FFBUILD_DOCKER_CACHE_FROM"
fi
if [[ -n "${FFBUILD_DOCKER_CACHE_TO:-}" ]]; then
while IFS= read -r cache_spec; do
cache_spec="$(trim_cache_spec "$cache_spec")"
[[ -n "$cache_spec" ]] || continue
final_cache_to+=("$cache_spec")
done <<< "$FFBUILD_DOCKER_CACHE_TO"
fi
{
if [[ -z "$QUICKBUILD" ]]; then
to_bake 'target "base" {'
to_bake ' context = "images/base"'
to_bake ' tags = ["%s"]' "$BASE_IMAGE"
to_bake ' output = ["type=docker"]'
to_bake ' cache-from = ["type=local,src=.cache/%s"]' "${BASE_IMAGE/:/_}"
to_bake ' cache-to = ["type=local,mode=max,compression=zstd,compression-level=1,dest=.cache/%s"]' "${BASE_IMAGE/:/_}"
to_bake '}'
to_bake 'target "target-base" {'
to_bake ' context = "images/base-%s"' "$TARGET"
to_bake ' args = { GH_REPO = "%s" }' "$GH_REPO"
to_bake ' contexts = { "%s/base" = "target:base" }' "$GH_REPO"
to_bake ' tags = ["%s"]' "$TARGET_IMAGE"
to_bake ' output = ["type=docker"]'
to_bake ' cache-from = ["type=local,src=.cache/%s"]' "${TARGET_IMAGE/:/_}"
to_bake ' cache-to = ["type=local,mode=max,compression=zstd,compression-level=1,dest=.cache/%s"]' "${TARGET_IMAGE/:/_}"
to_bake '}'
fi
to_bake 'target "image" {'
to_bake ' context = "."'
if [[ -z "$QUICKBUILD" ]]; then
to_bake ' contexts = { "%s/base-%s" = "target:target-base" }' "$GH_REPO" "$TARGET"
fi
to_bake ' tags = ["%s"]' "$IMAGE"
to_bake ' output = ["type=docker"]'
if (( ${#final_cache_from[@]} )); then
to_bake_list 'cache-from' "${final_cache_from[@]}"
fi
if (( ${#final_cache_to[@]} )); then
to_bake_list 'cache-to' "${final_cache_to[@]}"
fi
to_bake '}'
} | tee /dev/stderr | docker buildx --builder ffbuilder bake -f - "$@"
}
if [[ -z "$QUICKBUILD" ]]; then
bake_images base
fi
./download.sh
./generate.sh "$TARGET" "$VARIANT" "${ADDINS[@]}"
bake_images "${BAKE_TARGETS[@]}"