Skip to content

Commit 2a54c39

Browse files
committed
feat: update func to load cache_to arrya for formatting docker-compose file
1 parent 47d0a0a commit 2a54c39

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

lib/shared.bash

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ function build_image_override_file_with_version() {
176176
done
177177
fi
178178

179+
# load cache_to array
180+
cache_to_amt="${1:-0}"
181+
[[ -n "${1:-}" ]] && shift; # remove the value if not empty
182+
if [[ "${cache_to_amt}" -gt 0 ]]; then
183+
cache_to=()
184+
for _ in $(seq 1 "$cache_to_amt"); do
185+
cache_to+=( "$1" ); shift
186+
done
187+
fi
188+
179189
# load labels array
180190
labels_amt="${1:-0}"
181191
[[ -n "${1:-}" ]] && shift; # remove the value if not empty
@@ -186,7 +196,7 @@ function build_image_override_file_with_version() {
186196
done
187197
fi
188198

189-
if [[ -z "$image_name" ]] && [[ -z "$target" ]] && [[ "$cache_from_amt" -eq 0 ]] && [[ "$labels_amt" -eq 0 ]]; then
199+
if [[ -z "$image_name" ]] && [[ -z "$target" ]] && [[ "$cache_from_amt" -eq 0 ]] && [[ "$cache_to_amt" -eq 0 ]] && [[ "$labels_amt" -eq 0 ]]; then
190200
# should not print out an empty service
191201
continue
192202
fi
@@ -197,7 +207,7 @@ function build_image_override_file_with_version() {
197207
printf " image: %s\\n" "$image_name"
198208
fi
199209

200-
if [[ "$cache_from_amt" -gt 0 ]] || [[ -n "$target" ]] || [[ "$labels_amt" -gt 0 ]]; then
210+
if [[ "$cache_from_amt" -gt 0 ]] || [[ "$cache_to_amt" -gt 0 ]] || [[ -n "$target" ]] || [[ "$labels_amt" -gt 0 ]]; then
201211
printf " build:\\n"
202212
fi
203213

@@ -220,6 +230,21 @@ function build_image_override_file_with_version() {
220230
done
221231
fi
222232

233+
if [[ "$cache_to_amt" -gt 0 ]] ; then
234+
if ! docker_compose_supports_cache "$version" ; then
235+
echo "Unsupported Docker Compose config file version: $version"
236+
echo "The 'cache_to' option can only be used with Compose file versions 2.2 or 3.2 and above."
237+
echo "For more information on Docker Compose configuration file versions, see:"
238+
echo "https://docs.docker.com/compose/compose-file/compose-versioning/#versioning"
239+
exit 1
240+
fi
241+
242+
printf " cache_to:\\n"
243+
for cache_to_i in "${cache_to[@]}"; do
244+
printf " - %s\\n" "${cache_to_i}"
245+
done
246+
fi
247+
223248
if [[ "$labels_amt" -gt 0 ]] ; then
224249
printf " labels:\\n"
225250
for label in "${labels[@]}"; do

0 commit comments

Comments
 (0)