Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions image-build/scripts/builders/local-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@ builder_check() {
}

builder_prepare() {
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
Comment on lines +37 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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


if [[ "${DRY_RUN:-false}" == "true" ]]; then
echo "[dry-run] docker buildx create --name ${BUILDX_INSTANCE} --use # if missing"
echo "[dry-run] docker buildx create --name ${BUILDX_INSTANCE} # if missing"
echo "[dry-run] export BUILDX_BUILDER=${BUILDX_INSTANCE}"
echo "[dry-run] docker buildx inspect --bootstrap"
return 0
fi
if ! docker buildx inspect "${BUILDX_INSTANCE}" >/dev/null 2>&1; then
echo "Creating buildx builder '${BUILDX_INSTANCE}'..."
docker buildx create --name "${BUILDX_INSTANCE}" --use
else
docker buildx use "${BUILDX_INSTANCE}"
docker buildx create --name "${BUILDX_INSTANCE}"
fi
export BUILDX_BUILDER="${BUILDX_INSTANCE}"
docker buildx inspect --bootstrap >/dev/null
}

Expand Down