CircleCI-Public / aws-ecr-orb

CircleCI orb for interacting with Amazon's Elastic Container Registry (ECR)
https://circleci.com/orbs/registry/orb/circleci/aws-ecr
MIT License
81 stars 142 forks source link

fix: docker layer caching with docker buildx #249

Closed brivu closed 1 year ago

brivu commented 1 year ago

This PR fixes the Docker Layer Caching issue with the use of docker buildx. DLC only works when there is no docker context being used to build an image. This means that DLC will work with any platform as long as it's being built one at a time.

If more than one platform is provided (i.e. arm64, amd64, etc ) , the builder context will be used to support multi-architecture image builds. However, DLC is not currently supported if more than platform is provided.

brivu commented 1 year ago

Thanks for the suggestions @EricRibeiro! I really like the expansion at runtime. That's really slick!

However, I've tried our your suggestion but it doesn't seem to work with this command. Using ${context_args:+"$context_args"} gives me the following error:

unknown flag: --context builder
See 'docker buildx build --help'.

I've also tried using just $context_args in the docker buildx command without quotations and it still doesn't like it:

error: "docker buildx build" requires exactly 1 argument.
See 'docker buildx build --help'.

I tried to do the runtime expansion with docker_tag_args and it doesn't work as well. Interestingly though, that variable has to be unquoted for it to work.

I'm adding set +x though. Thank you!

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/aws-ecr?version=dev:fe5a7db8448c601d36371254e96ba47468f89cc8

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/aws-ecr?version=dev:a63ea7fc95cc7231235b1a5b2312273e84341858

brivu commented 1 year ago

Hey @EricRibeiro,

After some more testing, I finally got it to work with the code below. Thanks again for your suggestions!

 set -x
  docker \
    ${context_args} \
    buildx build \
    -f "${ORB_EVAL_PATH}"/"${ORB_VAL_DOCKERFILE}" \
    ${docker_tag_args} \
    --platform "${ORB_VAL_PLATFORM}" \
    --progress plain \
    "$@" \
    "${ORB_EVAL_PATH}"
  set +x

-Brian

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/aws-ecr?version=dev:e0ee5704fa4746ce6129c70344ced37a73dbb270

orb-publisher commented 1 year ago

Your development orb has been published. It will expire in 30 days. You can preview what this will look like on the CircleCI Orb Registry at the following link: https://circleci.com/developer/orbs/orb/circleci/aws-ecr?version=dev:2b2d94689a35f2e963514747d86c60bd253c5dbf