From 3d1809ce826193e2e8575b6c4af0be17bea4f090 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Tue, 18 Oct 2022 14:21:45 +0800 Subject: [PATCH 1/6] Add docker image support both amd64 and arm64 with doc update --- Dockerfile | 5 +++-- README.md | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index eaa859a9b1..c8c45437cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,13 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.18 AS build-env +FROM --platform=$BUILDPLATFORM golang:1.18 AS build-env RUN mkdir -p /go/src/sig.k8s.io/gateway-api WORKDIR /go/src/sig.k8s.io/gateway-api COPY . . +ARG TARGETARCH ARG TAG ARG COMMIT -RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -o gateway-api-webhook \ +RUN CGO_ENABLED=0 GOARCH=$TARGETARCH GOOS=linux go build -a -o gateway-api-webhook \ -ldflags "-s -w -X main.VERSION=$TAG -X main.COMMIT=$COMMIT" ./cmd/admission FROM gcr.io/distroless/static:nonroot diff --git a/README.md b/README.md index 2bb66e2130..65213c5137 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,10 @@ Participation in the Kubernetes community is governed by the [concepts]: https://gateway-api.sigs.k8s.io/concepts/api-overview [security-model]: https://gateway-api.sigs.k8s.io/concepts/security-model + +## ARM Image Support + +Use buildx for image building to support both amd64 and arm64: +``` +docker buildx build -f Dockerfile -t registry/admission-server:tag . --platform linux/amd64,linux/arm64 +``` From 362b0dd68d97650863b00ea616ba53f963f79a05 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Sun, 30 Oct 2022 22:01:32 +0800 Subject: [PATCH 2/6] Add default platform env --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c8c45437cc..c73c441559 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +ARG BUILDPLATFORM=linux/amd64 FROM --platform=$BUILDPLATFORM golang:1.18 AS build-env RUN mkdir -p /go/src/sig.k8s.io/gateway-api WORKDIR /go/src/sig.k8s.io/gateway-api From 67a7f179255ef1331ae55c7492196d89b5c38288 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Tue, 8 Nov 2022 17:19:12 +0800 Subject: [PATCH 3/6] > remove useless doc and update docker build and push --- README.md | 8 -------- hack/build-and-push.sh | 5 +++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 65213c5137..e3d885fbd9 100644 --- a/README.md +++ b/README.md @@ -67,11 +67,3 @@ Participation in the Kubernetes community is governed by the [spec]: https://gateway-api.sigs.k8s.io/v1alpha2/references/spec [concepts]: https://gateway-api.sigs.k8s.io/concepts/api-overview [security-model]: https://gateway-api.sigs.k8s.io/concepts/security-model - - -## ARM Image Support - -Use buildx for image building to support both amd64 and arm64: -``` -docker buildx build -f Dockerfile -t registry/admission-server:tag . --platform linux/amd64,linux/arm64 -``` diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index 5488eefd8c..553b91f65e 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -64,8 +64,9 @@ fi # 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. -docker build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ - -t ${REGISTRY}/admission-server:${GIT_TAG} . +docker buildx build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ + -t ${REGISTRY}/admission-server:${GIT_TAG} . --platform linux/amd64,linux/arm64 + docker push ${REGISTRY}/admission-server:${GIT_TAG} # Then, we add an extra version tag - either :latest or semver. From ae93d0955cbfa01d136b0d04c01c48dcbf9b799d Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Tue, 8 Nov 2022 17:28:45 +0800 Subject: [PATCH 4/6] add build and push latest or semver (because buildx command can't support load image to local) --- hack/build-and-push.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index 553b91f65e..c867b9de63 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -65,10 +65,8 @@ fi # 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. docker buildx build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ - -t ${REGISTRY}/admission-server:${GIT_TAG} . --platform linux/amd64,linux/arm64 - -docker push ${REGISTRY}/admission-server:${GIT_TAG} + -t ${REGISTRY}/admission-server:${GIT_TAG} . --platform linux/amd64,linux/arm64 --push # Then, we add an extra version tag - either :latest or semver. -docker tag ${REGISTRY}/admission-server:${GIT_TAG} ${REGISTRY}/admission-server:${VERSION_TAG} -docker push ${REGISTRY}/admission-server:${VERSION_TAG} +docker buildx build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ + -t ${REGISTRY}/admission-server:${VERSION_TAG} . --platform linux/amd64,linux/arm64 --push \ No newline at end of file From 27b1090c0c425131abeb87b8e19d30c549844a18 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Wed, 9 Nov 2022 12:25:25 +0800 Subject: [PATCH 5/6] fix build and push multi tags in one cmd --- hack/build-and-push.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index c867b9de63..e43173c1b8 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -64,9 +64,9 @@ fi # 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. +# The buildx integrate build and push in one line. docker buildx build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ - -t ${REGISTRY}/admission-server:${GIT_TAG} . --platform linux/amd64,linux/arm64 --push - -# Then, we add an extra version tag - either :latest or semver. -docker buildx build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ - -t ${REGISTRY}/admission-server:${VERSION_TAG} . --platform linux/amd64,linux/arm64 --push \ No newline at end of file + -t ${REGISTRY}/admission-server:${GIT_TAG} \ + -t ${REGISTRY}/admission-server:${VERSION_TAG} \ + . --platform linux/amd64,linux/arm64 --push From d011951d3e63d4474d05a995ca12e52a4e6281ce Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Thu, 10 Nov 2022 00:14:09 +0800 Subject: [PATCH 6/6] fix indent --- hack/build-and-push.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index e43173c1b8..e5d18ec8f0 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -67,6 +67,6 @@ fi # And, we add an extra version tag - either :latest or semver. # The buildx integrate build and push in one line. docker buildx build --build-arg COMMIT=${COMMIT} --build-arg TAG=${BINARY_TAG} \ - -t ${REGISTRY}/admission-server:${GIT_TAG} \ + -t ${REGISTRY}/admission-server:${GIT_TAG} \ -t ${REGISTRY}/admission-server:${VERSION_TAG} \ . --platform linux/amd64,linux/arm64 --push