Browse Source

Fixup arm and arm64 builds; Refactor Makefile;

Oleksii S. Malakhov 1 month ago
parent
commit
22fb8b62f8
6 changed files with 84 additions and 22 deletions
  1. 26
    9
      Makefile
  2. 22
    11
      bin/upload-binaries
  3. 22
    0
      checkpoint/checkpoint_linux_arm64.go
  4. 3
    1
      docker/helm.version
  5. 4
    1
      docker/kubectl.version
  6. 7
    0
      site/building.md

+ 26
- 9
Makefile View File

@@ -8,6 +8,12 @@ TEST_FLAGS?=
8 8
 include docker/kubectl.version
9 9
 include docker/helm.version
10 10
 
11
+# NB default target architecture is amd64. If you would like to try the
12
+# other one -- pass an ARCH variable, e.g.,
13
+#  `make ARCH=arm64`
14
+ifeq ($(ARCH),)
15
+	ARCH=amd64
16
+endif
11 17
 CURRENT_OS_ARCH=$(shell echo `go env GOOS`-`go env GOARCH`)
12 18
 
13 19
 # 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')
27 33
 all: $(GOPATH)/bin/fluxctl $(GOPATH)/bin/fluxd $(GOPATH)/bin/helm-operator build/.flux.done build/.helm-operator.done
28 34
 
29 35
 release-bins:
36
+	function do_build() { \
37
+		os=$$1 \
38
+		arch=$$2 \
39
+		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/; \
40
+	};\
30 41
 	for arch in amd64; do \
31 42
 		for os in linux darwin windows; do \
32
-			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/; \
43
+			do_build "$$os" "$$arch"; \
33 44
 		done; \
34
-	done
45
+	done; \
46
+	for arch in arm arm64; do \
47
+		for os in linux; do \
48
+			do_build "$$os" "$$arch"; \
49
+		done; \
50
+	done;
35 51
 
36 52
 clean:
37 53
 	go clean
@@ -58,33 +74,33 @@ build/.helm-operator.done: build/helm-operator build/kubectl build/helm docker/s
58 74
 
59 75
 build/fluxd: $(FLUXD_DEPS)
60 76
 build/fluxd: cmd/fluxd/*.go
61
-	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/fluxd
77
+	CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/fluxd
62 78
 
63 79
 build/helm-operator: $(HELM_OPERATOR_DEPS)
64 80
 build/helm-operator: cmd/helm-operator/*.go
65
-	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/helm-operator
81
+	CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/helm-operator
66 82
 
67
-build/kubectl: cache/linux-amd64/kubectl-$(KUBECTL_VERSION)
83
+build/kubectl: cache/linux-$(ARCH)/kubectl-$(KUBECTL_VERSION)
68 84
 test/bin/kubectl: cache/$(CURRENT_OS_ARCH)/kubectl-$(KUBECTL_VERSION)
69
-build/helm: cache/linux-amd64/helm-$(HELM_VERSION)
85
+build/helm: cache/linux-$(ARCH)/helm-$(HELM_VERSION)
70 86
 test/bin/helm: cache/$(CURRENT_OS_ARCH)/helm-$(HELM_VERSION)
71 87
 build/kubectl test/bin/kubectl build/helm test/bin/helm:
72 88
 	mkdir -p build
73 89
 	cp $< $@
74
-	if [ `basename $@` = "build" -a $(CURRENT_OS_ARCH) = "linux-amd64" ]; then strip $@; fi
90
+	if [ `basename $@` = "build" -a $(CURRENT_OS_ARCH) = "linux-$(ARCH)" ]; then strip $@; fi
75 91
 	chmod a+x $@
76 92
 
77 93
 cache/%/kubectl-$(KUBECTL_VERSION): docker/kubectl.version
78 94
 	mkdir -p cache/$*
79 95
 	curl -L -o cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz "https://dl.k8s.io/$(KUBECTL_VERSION)/kubernetes-client-$*.tar.gz"
80
-	[ $* != "linux-amd64" ] || echo "$(KUBECTL_CHECKSUM)  cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz" | shasum -a 256 -c
96
+	[ $* != "linux-$(ARCH)" ] || echo "$(KUBECTL_CHECKSUM_$(ARCH))  cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz" | shasum -a 256 -c
81 97
 	tar -m --strip-components 3 -C ./cache/$* -xzf cache/$*/kubectl-$(KUBECTL_VERSION).tar.gz kubernetes/client/bin/kubectl
82 98
 	mv ./cache/$*/kubectl $@
83 99
 
84 100
 cache/%/helm-$(HELM_VERSION): docker/helm.version
85 101
 	mkdir -p cache/$*
86 102
 	curl -L -o cache/$*/helm-$(HELM_VERSION).tar.gz "https://storage.googleapis.com/kubernetes-helm/helm-v$(HELM_VERSION)-$*.tar.gz"
87
-	[ $* != "linux-amd64" ] || echo "$(HELM_CHECKSUM)  cache/$*/helm-$(HELM_VERSION).tar.gz" | shasum -a 256 -c
103
+	[ $* != "linux-$(ARCH)" ] || echo "$(HELM_CHECKSUM_$(ARCH))  cache/$*/helm-$(HELM_VERSION).tar.gz" | shasum -a 256 -c
88 104
 	tar -m -C ./cache -xzf cache/$*/helm-$(HELM_VERSION).tar.gz $*/helm
89 105
 	mv cache/$*/helm $@
90 106
 
@@ -106,3 +122,4 @@ integration-test: all
106 122
 check-generated:
107 123
 	./bin/helm/update_codegen.sh
108 124
 	git diff --exit-code -- integrations/apis intergrations/client
125
+

+ 22
- 11
bin/upload-binaries View File

@@ -8,15 +8,26 @@ GITHUB_USER=${GITHUB_USER:-"${CIRCLE_PROJECT_USERNAME}"}
8 8
 GITHUB_REPO=${GITHUB_REPO:-"${CIRCLE_PROJECT_REPONAME}"}
9 9
 GITHUB_TAG=${GITHUB_TAG:-"${CIRCLE_TAG}"}
10 10
 
11
-for arch in amd64; do
12
-	for os in linux darwin windows; do
13
-		echo "= Uploading fluxctl_${os}_${arch} to GH release ${GITHUB_TAG}"
14
-		github-release upload \
15
-			--user ${GITHUB_USER} \
16
-			--repo ${GITHUB_REPO} \
17
-			--tag ${GITHUB_TAG} \
18
-			--name "fluxctl_${os}_${arch}" \
19
-			--file "build/fluxctl_${os}_${arch}"
20
-		echo "* Finished pushing fluxctl_${os}_${arch} for ${GITHUB_TAG}"
21
-	done
11
+function do_publish() {
12
+	os=$1
13
+	arch=$2
14
+	echo "= Uploading fluxctl_${os}_${arch} to GH release ${GITHUB_TAG}"
15
+	github-release upload \
16
+		--user ${GITHUB_USER} \
17
+		--repo ${GITHUB_REPO} \
18
+		--tag ${GITHUB_TAG} \
19
+		--name "fluxctl_${os}_${arch}" \
20
+		--file "build/fluxctl_${os}_${arch}"
21
+	echo "* Finished pushing fluxctl_${os}_${arch} for ${GITHUB_TAG}"
22
+}
23
+
24
+#amd64
25
+for os in linux darwin windows; do
26
+	do_publish $os amd64
27
+done
28
+
29
+#arm
30
+for arch in arm arm64; do
31
+	do_publish linux $arch
22 32
 done
33
+

+ 22
- 0
checkpoint/checkpoint_linux_arm64.go View File

@@ -0,0 +1,22 @@
1
+package checkpoint
2
+
3
+import (
4
+	"syscall"
5
+)
6
+
7
+func getKernelVersion() string {
8
+	var uts syscall.Utsname
9
+	syscall.Uname(&uts)
10
+	return cstringToString(uts.Release[:])
11
+}
12
+
13
+func cstringToString(arr []int8) string {
14
+	b := make([]byte, 0, len(arr))
15
+	for _, v := range arr {
16
+		if v == 0x00 {
17
+			break
18
+		}
19
+		b = append(b, byte(v))
20
+	}
21
+	return string(b)
22
+}

+ 3
- 1
docker/helm.version View File

@@ -3,4 +3,6 @@
3 3
 # that reliably supports authenticating against chart repos, so that
4 4
 # wins.
5 5
 HELM_VERSION=2.13.0
6
-HELM_CHECKSUM=15eca6ad225a8279de80c7ced42305e24bc5ac60bb7d96f2d2fa4af86e02c794
6
+HELM_CHECKSUM_amd64=15eca6ad225a8279de80c7ced42305e24bc5ac60bb7d96f2d2fa4af86e02c794
7
+HELM_CHECKSUM_arm=adf1242eca171ba21847e621ce9fbdbb3dd2aa35ac8532fb05519b1b49fd4456
8
+HELM_CHECKSUM_arm64=afb51c43ed83fe8bac62f7e47872019cf1c0d8a1927d69fb963959c6accc77b5

+ 4
- 1
docker/kubectl.version View File

@@ -1,2 +1,5 @@
1 1
 KUBECTL_VERSION=v1.11.3
2
-KUBECTL_CHECKSUM=14a70ac05c00fcfd7d632fc9e7a5fbc6615ce1b370bb1a0e506a24972d461493
2
+KUBECTL_CHECKSUM_amd64=14a70ac05c00fcfd7d632fc9e7a5fbc6615ce1b370bb1a0e506a24972d461493
3
+KUBECTL_CHECKSUM_arm=c62835797d58b50f19706d897a9106b219f5868b0a6c7bb62c6284f809c01473
4
+KUBECTL_CHECKSUM_arm64=a43510f821d349519ecba27b24788a0e41eae31d79bc7af73b6132190b0dcce2
5
+

+ 7
- 0
site/building.md View File

@@ -21,6 +21,13 @@ $ make
21 21
 
22 22
 This makes Docker images, and installs binaries to $GOPATH/bin.
23 23
 
24
+Note: The default target architecture is amd64. If you would like to try to build Docker images
25
+and binaries for a different architecture you will have to set ARCH variable,
26
+
27
+```sh
28
+$ make ARCH=<target_arch>
29
+```
30
+
24 31
 # Test
25 32
 
26 33
 ```sh

Loading…
Cancel
Save