From f77bbc9797908fbac983ec37ae87c5b89f335156 Mon Sep 17 00:00:00 2001 From: Xin Wang <38582160+MrXinWang@users.noreply.github.com> Date: Sat, 6 Jun 2020 06:33:46 +0800 Subject: [PATCH] Update: Enable arm64 kfctl binary build and fix docker build error (#349) 1. Adds support for building and releasing arm64 kfctl binary. Note: This updated PR used a safer support method without changing current building targets and release names. 2. Fixes building error for target `build-kfctl-container` when executing `RUN go mod download` by upgrading the Golang version to v1.13.7. 3. Only installing google-cloud on x86_64 machines. Signed-off-by: Henry Wang --- Dockerfile | 18 +++++++++++------- Makefile | 22 +++++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 79e25fddb..9d9199d3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ #********************************************************************** # Builder # Create a go runtime suitable for building and testing kfctl -ARG GOLANG_VERSION=1.12.7 +ARG GOLANG_VERSION=1.13.7 FROM golang:$GOLANG_VERSION as builder ARG BRANCH=master @@ -14,11 +14,12 @@ RUN apt-get install -y git unzip jq vim RUN go get -u github.com/jstemmer/go-junit-report # We need gcloud to get gke credentials. -RUN \ - cd /tmp && \ - wget -nv https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash && \ - chmod +x install_google_cloud_sdk.bash && \ - ./install_google_cloud_sdk.bash --disable-prompts --install-dir=/opt/ +RUN if [ "$(uname -m)" = "x86_64" ]; then \ + cd /tmp && \ + wget -nv https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash && \ + chmod +x install_google_cloud_sdk.bash && \ + ./install_google_cloud_sdk.bash --disable-prompts --install-dir=/opt/; \ + fi ENV PATH /go/bin:/usr/local/go/bin:/opt/google-cloud-sdk/bin:${PATH} @@ -49,7 +50,10 @@ COPY . . # FROM builder as kfctl_base -RUN make build-kfctl +RUN make build-kfctl && \ + if [ "$(uname -m)" = "aarch64" ]; then \ + cp bin/arm64/kfctl bin/kfctl; \ + fi #********************************************************************** # diff --git a/Makefile b/Makefile index 0f5a96b84..faf500ab7 100755 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ # limitations under the License. # GCLOUD_PROJECT ?= kubeflow-images-public -GOLANG_VERSION ?= 1.12.7 +GOLANG_VERSION ?= 1.13.7 GOPATH ?= $(HOME)/go # To build without the cache set the environment variable # export DOCKER_BUILD_OPTS=--no-cache @@ -126,15 +126,16 @@ build: build-kfctl build-kfctl: deepcopy generate fmt vet # TODO(swiftdiaries): figure out import conflict errors for windows - #GOOS=windows GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/windows/kfctl.exe cmd/kfctl/main.go - GOOS=darwin GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=${TAG}" -o bin/darwin/kfctl cmd/kfctl/main.go - GOOS=linux GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/linux/kfctl cmd/kfctl/main.go + #CGO_ENABLED=0 GOOS=windows GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/windows/kfctl.exe cmd/kfctl/main.go + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=${TAG}" -o bin/darwin/kfctl cmd/kfctl/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/linux/kfctl cmd/kfctl/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/arm64/kfctl cmd/kfctl/main.go cp bin/$(ARCH)/kfctl bin/kfctl # Fast rebuilds useful for development. # Does not regenerate code; assumes you already ran build-kfctl once. build-kfctl-fast: fmt vet - GOOS=linux GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/linux/kfctl cmd/kfctl/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${GO} build -gcflags '-N -l' -ldflags "-X main.VERSION=$(TAG)" -o bin/linux/kfctl cmd/kfctl/main.go # Release tarballs suitable for upload to GitHub release pages build-kfctl-tgz: build-kfctl @@ -142,6 +143,7 @@ build-kfctl-tgz: build-kfctl rm -f bin/*.tgz cd bin/linux && tar -cvzf kfctl_$(TAG)_linux.tar.gz ./kfctl cd bin/darwin && tar -cvzf kfctl_${TAG}_darwin.tar.gz ./kfctl + cd bin/arm64 && tar -cvzf kfctl_${TAG}_arm64.tar.gz ./kfctl build-and-push-operator: build-operator push-operator build-push-update-operator: build-operator push-operator update-operator-image @@ -190,13 +192,19 @@ push-to-github-release: build-kfctl-tgz --repo kubeflow \ --tag $(TAG) \ --name "kfctl_$(TAG)_linux.tar.gz" \ - --file bin/kfctl_$(TAG)_linux.tar.gz + --file bin/linux/kfctl_$(TAG)_linux.tar.gz github-release upload \ --user kubeflow \ --repo kubeflow \ --tag $(TAG) \ --name "kfctl_$(TAG)_darwin.tar.gz" \ - --file bin/kfctl_$(TAG)_darwin.tar.gz + --file bin/darwin/kfctl_$(TAG)_darwin.tar.gz + github-release upload \ + --user kubeflow \ + --repo kubeflow \ + --tag $(TAG) \ + --name "kfctl_$(TAG)_arm64.tar.gz" \ + --file bin/arm64/kfctl_$(TAG)_arm64.tar.gz build-kfctl-container: DOCKER_BUILDKIT=1 docker build \