Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add buildx context setup before starting build #1553

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,21 @@ image.buildx.verify:
docker buildx version; \
fi

BUILDX_CONTEXT = gateway-api-builder
BUILDX_PLATFORMS = linux/amd64,linux/arm64
Comment on lines +133 to +134
Copy link
Member

Choose a reason for hiding this comment

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

Tiny nit: All other environment variables are defined with comments at the top of this file. I'd recommend moving these to the top as well and adding comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I will update it later.


# Setup multi-arch enviroment
# Recreate a buildx context for multi-arch images.
.PHONY: image.multiarch.setup
image.multiarch.setup: image.buildx.verify
@if [ "$(shell uname)" == "Linux" ]; then \
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \
Copy link
Member

Choose a reason for hiding this comment

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

For future readers it could be helpful to add some comments about this line: firstly what it does and why its needed, and secondly a helpful link to the source of the image.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

fi
docker buildx rm $(BUILDX_CONTEXT) || :
docker buildx create --use --name $(BUILDX_CONTEXT) --platform "${BUILDX_PLATFORMS}"
Comment on lines +146 to +147
Copy link
Member

Choose a reason for hiding this comment

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

Comments here explaining what these are doing could go a long way for future code readers as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


.PHONY: release-staging
release-staging: image.buildx.verify
release-staging: image.multiarch.setup
hack/build-and-push.sh

# Generate a virtualenv install, which is useful for hacking on the
Expand Down
7 changes: 6 additions & 1 deletion hack/build-and-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ then
BINARY_TAG="${BASE_REF}"
fi

# Support multi-arch image build and push.
BUILDX_PLATFORMS="linux/amd64,linux/arm64"

echo "Building and pushing admission-server image...${BUILDX_PLATFORMS}"

# First, build the image, with the version info passed in.
# Note that an image will *always* be built tagged with the GIT_TAG, so we know when it was built.
# And, we add an extra version tag - either :latest or semver.
Expand All @@ -71,6 +76,6 @@ docker buildx build \
-t ${REGISTRY}/admission-server:${VERSION_TAG} \
--build-arg "COMMIT=${COMMIT}" \
--build-arg "TAG=${BINARY_TAG}" \
--platform linux/amd64,linux/arm64 \
--platform ${BUILDX_PLATFORMS} \
--push \
.