fix(image-build): use default builder for local docker builds#442
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the local Docker builder script to use the default builder when a push is not requested. The reviewer suggested using the BUILDX_BUILDER environment variable instead of running 'docker buildx use' to avoid mutating the user's global Docker CLI configuration.
| if [[ "${PUSH:-false}" != "true" ]]; then | ||
| if [[ "${DRY_RUN:-false}" == "true" ]]; then | ||
| echo "[dry-run] docker buildx use default" | ||
| return 0 | ||
| fi | ||
| echo "Using default docker builder for local build..." | ||
| docker buildx use default | ||
| return 0 | ||
| fi |
There was a problem hiding this comment.
Using docker buildx use <builder> mutates the user's global Docker CLI configuration (specifically ~/.docker/buildx/current), which permanently changes their active builder even after this script finishes executing. This can be disruptive to developers running the script locally.
Instead, you can use the BUILDX_BUILDER environment variable. Setting export BUILDX_BUILDER=default achieves the same result but is scoped only to the current script execution, leaving the user's global configuration untouched.
Note: You should also apply this pattern to the PUSH == true branch (lines 52-57) by using export BUILDX_BUILDER="${BUILDX_INSTANCE}" and removing the --use flag from docker buildx create.
| if [[ "${PUSH:-false}" != "true" ]]; then | |
| if [[ "${DRY_RUN:-false}" == "true" ]]; then | |
| echo "[dry-run] docker buildx use default" | |
| return 0 | |
| fi | |
| echo "Using default docker builder for local build..." | |
| docker buildx use default | |
| return 0 | |
| fi | |
| if [[ "${PUSH:-false}" != "true" ]]; then | |
| if [[ "${DRY_RUN:-false}" == "true" ]]; then | |
| echo "[dry-run] export BUILDX_BUILDER=default" | |
| return 0 | |
| fi | |
| echo "Using default docker builder for local build..." | |
| export BUILDX_BUILDER="default" | |
| return 0 | |
| fi |
Using a custom docker-container builder (scion-builder) prevents BuildKit from resolving intermediate images built in previous steps when PUSH is false, because the container driver doesn't share the host's daemon image cache. Switching to the default builder for local builds resolves this.
… config Address PR GoogleCloudPlatform#442 reviewer feedback: - Use the BUILDX_BUILDER environment variable instead of 'docker buildx use' to prevent mutating the user's global Docker CLI configuration. - For push builds, export BUILDX_BUILDER="${BUILDX_INSTANCE}" and remove the --use flag from 'docker buildx create'.
4ccb1f3 to
2ebea3c
Compare
Using a custom docker-container builder (scion-builder) prevents BuildKit from resolving intermediate images built in previous steps when PUSH is false, because the container driver doesn't share the host's daemon image cache. Switching to the default builder for local builds resolves this.