From 22fb8b62f8ac2ed85f6ebf3f5eae59ec3f6b7c19 Mon Sep 17 00:00:00 2001 From: "Oleksii S. Malakhov" Date: Wed, 17 Apr 2019 17:06:41 +0300 Subject: [PATCH] Fixup arm and arm64 builds; Refactor Makefile; --- Makefile | 35 +++++++++++++++++++++------- bin/upload-binaries | 33 +++++++++++++++++--------- checkpoint/checkpoint_linux_arm64.go | 22 +++++++++++++++++ docker/helm.version | 4 +++- docker/kubectl.version | 5 +++- site/building.md | 7 ++++++ 6 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 checkpoint/checkpoint_linux_arm64.go diff --git a/Makefile b/Makefile index 4052df7a5..04723e65f 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,12 @@ TEST_FLAGS?= include docker/kubectl.version include docker/helm.version +# NB default target architecture is amd64. If you would like to try the +# other one -- pass an ARCH variable, e.g., +# `make ARCH=arm64` +ifeq ($(ARCH),) + ARCH=amd64 +endif CURRENT_OS_ARCH=$(shell echo `go env GOOS`-`go env GOARCH`) # NB because this outputs absolute file names, you have to be careful @@ -27,11 +33,21 @@ BUILD_DATE:=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') all: $(GOPATH)/bin/fluxctl $(GOPATH)/bin/fluxd $(GOPATH)/bin/helm-operator build/.flux.done build/.helm-operator.done release-bins: + function do_build() { \ + os=$$1 \ + arch=$$2 \ + CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -o "build/fluxctl_"$$os"_$$arch" $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/fluxctl/; \ + };\ for arch in amd64; do \ for os in linux darwin windows; do \ - CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -o "build/fluxctl_"$$os"_$$arch" $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/fluxctl/; \ + do_build "$$os" "$$arch"; \ done; \ - done + done; \ + for arch in arm arm64; do \ + for os in linux; do \ + do_build "$$os" "$$arch"; \ + done; \ + done; clean: go clean @@ -58,33 +74,33 @@ build/.helm-operator.done: build/helm-operator build/kubectl build/helm docker/s build/fluxd: $(FLUXD_DEPS) build/fluxd: cmd/fluxd/*.go - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/fluxd + CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/fluxd build/helm-operator: $(HELM_OPERATOR_DEPS) build/helm-operator: cmd/helm-operator/*.go - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/helm-operator + CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/helm-operator -build/kubectl: cache/linux-amd64/kubectl-$(KUBECTL_VERSION) +build/kubectl: cache/linux-$(ARCH)/kubectl-$(KUBECTL_VERSION) test/bin/kubectl: cache/$(CURRENT_OS_ARCH)/kubectl-$(KUBECTL_VERSION) -build/helm: cache/linux-amd64/helm-$(HELM_VERSION) +build/helm: cache/linux-$(ARCH)/helm-$(HELM_VERSION) test/bin/helm: cache/$(CURRENT_OS_ARCH)/helm-$(HELM_VERSION) build/kubectl test/bin/kubectl build/helm test/bin/helm: mkdir -p build cp $< $@ - if [ `basename $@` = "build" -a $(CURRENT_OS_ARCH) = "linux-amd64" ]; then strip $@; fi + if [ `basename $@` = "build" -a $(CURRENT_OS_ARCH) = "linux-$(ARCH)" ]; then strip $@; fi chmod a+x $@ cache/%/kubectl-$(KUBECTL_VERSION): docker/kubectl.version mkdir -p cache/$* curl -L -o cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz "https://dl.k8s.io/$(KUBECTL_VERSION)/kubernetes-client-$*.tar.gz" - [ $* != "linux-amd64" ] || echo "$(KUBECTL_CHECKSUM) cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz" | shasum -a 256 -c + [ $* != "linux-$(ARCH)" ] || echo "$(KUBECTL_CHECKSUM_$(ARCH)) cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz" | shasum -a 256 -c tar -m --strip-components 3 -C ./cache/$* -xzf cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz kubernetes/client/bin/kubectl mv ./cache/$*/kubectl $@ cache/%/helm-$(HELM_VERSION): docker/helm.version mkdir -p cache/$* curl -L -o cache/$*/helm-$(HELM_VERSION).tar.gz "https://storage.googleapis.com/kubernetes-helm/helm-v$(HELM_VERSION)-$*.tar.gz" - [ $* != "linux-amd64" ] || echo "$(HELM_CHECKSUM) cache/$*/helm-$(HELM_VERSION).tar.gz" | shasum -a 256 -c + [ $* != "linux-$(ARCH)" ] || echo "$(HELM_CHECKSUM_$(ARCH)) cache/$*/helm-$(HELM_VERSION).tar.gz" | shasum -a 256 -c tar -m -C ./cache -xzf cache/$*/helm-$(HELM_VERSION).tar.gz $*/helm mv cache/$*/helm $@ @@ -106,3 +122,4 @@ integration-test: all check-generated: ./bin/helm/update_codegen.sh git diff --exit-code -- integrations/apis intergrations/client + diff --git a/bin/upload-binaries b/bin/upload-binaries index 69e21ab79..1d4a2a7c8 100755 --- a/bin/upload-binaries +++ b/bin/upload-binaries @@ -8,15 +8,26 @@ GITHUB_USER=${GITHUB_USER:-"${CIRCLE_PROJECT_USERNAME}"} GITHUB_REPO=${GITHUB_REPO:-"${CIRCLE_PROJECT_REPONAME}"} GITHUB_TAG=${GITHUB_TAG:-"${CIRCLE_TAG}"} -for arch in amd64; do - for os in linux darwin windows; do - echo "= Uploading fluxctl_${os}_${arch} to GH release ${GITHUB_TAG}" - github-release upload \ - --user ${GITHUB_USER} \ - --repo ${GITHUB_REPO} \ - --tag ${GITHUB_TAG} \ - --name "fluxctl_${os}_${arch}" \ - --file "build/fluxctl_${os}_${arch}" - echo "* Finished pushing fluxctl_${os}_${arch} for ${GITHUB_TAG}" - done +function do_publish() { + os=$1 + arch=$2 + echo "= Uploading fluxctl_${os}_${arch} to GH release ${GITHUB_TAG}" + github-release upload \ + --user ${GITHUB_USER} \ + --repo ${GITHUB_REPO} \ + --tag ${GITHUB_TAG} \ + --name "fluxctl_${os}_${arch}" \ + --file "build/fluxctl_${os}_${arch}" + echo "* Finished pushing fluxctl_${os}_${arch} for ${GITHUB_TAG}" +} + +#amd64 +for os in linux darwin windows; do + do_publish $os amd64 +done + +#arm +for arch in arm arm64; do + do_publish linux $arch done + diff --git a/checkpoint/checkpoint_linux_arm64.go b/checkpoint/checkpoint_linux_arm64.go new file mode 100644 index 000000000..38221f2b7 --- /dev/null +++ b/checkpoint/checkpoint_linux_arm64.go @@ -0,0 +1,22 @@ +package checkpoint + +import ( + "syscall" +) + +func getKernelVersion() string { + var uts syscall.Utsname + syscall.Uname(&uts) + return cstringToString(uts.Release[:]) +} + +func cstringToString(arr []int8) string { + b := make([]byte, 0, len(arr)) + for _, v := range arr { + if v == 0x00 { + break + } + b = append(b, byte(v)) + } + return string(b) +} diff --git a/docker/helm.version b/docker/helm.version index 7c74fa2cd..f4362d25a 100644 --- a/docker/helm.version +++ b/docker/helm.version @@ -3,4 +3,6 @@ # that reliably supports authenticating against chart repos, so that # wins. HELM_VERSION=2.13.0 -HELM_CHECKSUM=15eca6ad225a8279de80c7ced42305e24bc5ac60bb7d96f2d2fa4af86e02c794 +HELM_CHECKSUM_amd64=15eca6ad225a8279de80c7ced42305e24bc5ac60bb7d96f2d2fa4af86e02c794 +HELM_CHECKSUM_arm=adf1242eca171ba21847e621ce9fbdbb3dd2aa35ac8532fb05519b1b49fd4456 +HELM_CHECKSUM_arm64=afb51c43ed83fe8bac62f7e47872019cf1c0d8a1927d69fb963959c6accc77b5 diff --git a/docker/kubectl.version b/docker/kubectl.version index 47d4ecef5..662ad68c9 100644 --- a/docker/kubectl.version +++ b/docker/kubectl.version @@ -1,2 +1,5 @@ KUBECTL_VERSION=v1.11.3 -KUBECTL_CHECKSUM=14a70ac05c00fcfd7d632fc9e7a5fbc6615ce1b370bb1a0e506a24972d461493 +KUBECTL_CHECKSUM_amd64=14a70ac05c00fcfd7d632fc9e7a5fbc6615ce1b370bb1a0e506a24972d461493 +KUBECTL_CHECKSUM_arm=c62835797d58b50f19706d897a9106b219f5868b0a6c7bb62c6284f809c01473 +KUBECTL_CHECKSUM_arm64=a43510f821d349519ecba27b24788a0e41eae31d79bc7af73b6132190b0dcce2 + diff --git a/site/building.md b/site/building.md index 2d03702a5..7bab2dd7a 100644 --- a/site/building.md +++ b/site/building.md @@ -21,6 +21,13 @@ $ make This makes Docker images, and installs binaries to $GOPATH/bin. +Note: The default target architecture is amd64. If you would like to try to build Docker images +and binaries for a different architecture you will have to set ARCH variable, + +```sh +$ make ARCH= +``` + # Test ```sh