CircleCI-Public / docker-orb

Install/use various Docker-related tools on CircleCI
https://circleci.com/orbs/registry/orb/circleci/docker
MIT License
29 stars 63 forks source link

[FEATURE] Expand ENV variables in `cache_from` parameter value #166

Closed jgarber623 closed 1 year ago

jgarber623 commented 2 years ago

Orb version

2.1.4

What happened

Using the following abbreviated configuration in a job step:

- docker/build:
    cache_from: us.gcr.io/${GOOGLE_PROJECT_ID}/xxx:${CIRCLE_BRANCH}-${CIRCLE_SHA1},us.gcr.io/${GOOGLE_PROJECT_ID}/xxx:${CIRCLE_BRANCH}-latest
    registry: us.gcr.io
    tag: ${CIRCLE_BRANCH}-${CIRCLE_SHA1},${CIRCLE_BRANCH}-latest
    use-buildkit: true

I'm seeing (correctly) that the pull_images_from_cache function pulls one of the requested images meaning that ENV variables are correctly expanded by that function. In subsequent log messages during the build process, I'm seeing messages like:

#4 importing cache manifest from us.gcr.io/${GOOGLE_PROJECT_ID}/xxx:${CIRCLE_BRANCH}-${CIRCLE_SHA1}
#4 sha256:xxx
#4 ERROR: invalid reference format: repository name must be lowercase

I did some digging and found #149 dealt with a similar issue with the extra_build_args parameter value. I think a similar change to these lines in build.sh would do the trick:

if [ -n "$PARAM_CACHE_FROM" ]; then
  cache_from="$(eval echo "$PARAM_CACHE_FROM")"
  build_args+=("--cache-from=$cache_from")
fi

Expected behavior

ENV vars referenced in the cache_from parameter should properly expand.