@@ -35,8 +35,24 @@ get_caches_for_service() {
3535 fi
3636}
3737
38+ get_caches_to_service () {
39+ local service=" $1 "
40+
41+ # Read any cache-to parameters provided
42+ for line in $( plugin_read_list CACHE_TO) ; do
43+ IFS=' :' read -r -a tokens <<< " $line"
44+ service_name=${tokens[0]}
45+ service_image=$( IFS=' :' ; echo " ${tokens[*]: 1} " )
46+
47+ if [ " ${service_name} " == " ${service} " ]; then
48+ echo " $service_image "
49+ fi
50+ done
51+ }
52+
53+
3854# Run through all images in the build property, either a single item or a list
39- # and build up a list of service name, image name and optional cache-froms to
55+ # and build up a list of service name, image name and optional cache-froms and cache-tos to
4056# write into a docker-compose override file
4157for service_name in $( plugin_read_list BUILD) ; do
4258 target=" $( plugin_read_config TARGET " " ) "
@@ -47,19 +63,29 @@ for service_name in $(plugin_read_list BUILD) ; do
4763 cache_from+=(" $cache_line " )
4864 done
4965
66+ cache_to=()
67+ for cache_line in $( get_caches_to_service " $service_name " ) ; do
68+ cache_to+=(" $cache_line " )
69+ done
70+
5071 labels=()
5172 while read -r label ; do
5273 [[ -n " ${label:- } " ]] && labels+=(" ${label} " )
5374 done <<< " $(plugin_read_list BUILD_LABELS)"
5475
55- if [[ -n " ${target} " ]] || [[ " ${# labels[@]} " -gt 0 ]] || [[ " ${# cache_from[@]} " -gt 0 ]]; then
76+ if [[ -n " ${target} " ]] || [[ " ${# labels[@]} " -gt 0 ]]|| [[ " ${ # cache_to[@]} " -gt 0 ]] || [[ " ${# cache_from[@]} " -gt 0 ]]; then
5677 build_images+=(" $service_name " " ${image_name} " " ${target} " )
57-
78+
5879 build_images+=(" ${# cache_from[@]} " )
5980 if [[ " ${# cache_from[@]} " -gt 0 ]]; then
6081 build_images+=(" ${cache_from[@]} " )
6182 fi
62-
83+
84+ build_images+=(" ${# cache_to[@]} " )
85+ if [[ " ${# cache_to[@]} " -gt 0 ]]; then
86+ build_images+=(" ${cache_to[@]} " )
87+ fi
88+
6389 build_images+=(" ${# labels[@]} " )
6490 if [[ " ${# labels[@]} " -gt 0 ]]; then
6591 build_images+=(" ${labels[@]} " )
0 commit comments