From 479e183c8a288476748d0a76cf52d6e5ca7a314e Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 7 Nov 2017 10:11:23 +0000 Subject: [PATCH 1/3] local-build: build a static + stripped binary by default On Linux enable pie too. Lastly, give the user control over the target name (e.g. to allow them to build with a GOOS+GOARCH suffix). Signed-off-by: Ian Campbell --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bdf988ced..17154ce1e 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,14 @@ test-cross: $(MAKE) -j 3 GOOS=linux tmp_moby_bin.tar tmp_rtf_bin.tar tmp_mt_bin.tar tmp_linuxkit_bin.tar $(MAKE) clean +ifeq ($(GOARCH)-$(GOOS),amd64-linux) +LOCAL_BUILDMODE?=pie +endif +LOCAL_BUILDMODE?=default + +LOCAL_LDFLAGS += -s -w -extldflags \"-static\" -X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION) +LOCAL_TARGET ?= bin/linuxkit + .PHONY: local-check local-build local-test local local-check: $(LINUXKIT_DEPS) @echo gofmt... && o=$$(gofmt -s -l $(filter %.go,$(LINUXKIT_DEPS))) && if [ -n "$$o" ] ; then echo $$o ; exit 1 ; fi @@ -80,7 +88,7 @@ local-check: $(LINUXKIT_DEPS) @echo ineffassign... && ineffassign $(filter %.go,$(LINUXKIT_DEPS)) local-build: $(LINUXKIT_DEPS) | bin - go build -o bin/linuxkit --ldflags "-X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION)" github.com/linuxkit/linuxkit/src/cmd/linuxkit + go build -o $(LOCAL_TARGET) --buildmode $(LOCAL_BUILDMODE) --ldflags "$(LOCAL_LDFLAGS)" github.com/linuxkit/linuxkit/src/cmd/linuxkit local-test: $(LINUXKIT_DEPS) go test $(shell go list github.com/linuxkit/linuxkit/src/cmd/linuxkit/... | grep -v ^github.com/linuxkit/linuxkit/src/cmd/linuxkit/vendor/) From 1cb4d173e4877e1032ef07fd3a502460dc85fa77 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 6 Nov 2017 15:28:27 +0000 Subject: [PATCH 2/3] Add Circle CI runes Advantage over Travis for this usecase is the automatic artifact handling without needing to mess with S3 or similar, making it simple to offer downloads. Signed-off-by: Ian Campbell --- .circleci/config.yml | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..86bdc6cc6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,55 @@ +version: 2 +jobs: + build: + working_directory: /go/src/github.com/linuxkit/linuxkit + docker: + - image: circleci/golang:1.9-stretch + steps: + - checkout + - run: mkdir -p ./bin + - run: + name: Versions + command: | + set -x + go version + cat /etc/os-release + - run: + name: Dependencies + command: | + go get -u github.com/golang/lint/golint + go get -u github.com/gordonklaus/ineffassign + - run: + name: Lint + command: make local-check + - run: + name: Build amd64/linux + environment: + GOOS: linux + GOARCH: amd64 + command: make LOCAL_TARGET=bin/linuxkit-$GOOS-$GOARCH local-build + - run: + name: Build arm64/linux + environment: + GOOS: linux + GOARCH: arm64 + command: make LOCAL_TARGET=bin/linuxkit-$GOOS-$GOARCH local-build + - run: + name: Build amd64/darwin + environment: + GOOS: darwin + GOARCH: amd64 + command: make LOCAL_TARGET=bin/linuxkit-$GOOS-$GOARCH local-build + - run: + name: Build amd64/windows + environment: + GOOS: windows + GOARCH: amd64 + command: make LOCAL_TARGET=bin/linuxkit-$GOOS-$GOARCH local-build + - run: + name: Test + command: make local-test + - run: + name: Checksum + command: cd bin && sha256sum linuxkit-*-* > SHA256SUM + - store_artifacts: + path: ./bin From 1332ab979ea68aab9be7bb5ea45c6fcff82e4904 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 7 Nov 2017 11:48:56 +0000 Subject: [PATCH 3/3] Remove travis.yml Signed-off-by: Ian Campbell --- .travis.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2d8a43b9e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: go - -go: - - 1.9.x - -env: - - TRAVIS_GOOS=linux - - TRAVIS_GOOS=darwin - - TRAVIS_GOOS=windows - -script: -# We want native versions of the tools. - - go get -u github.com/golang/lint/golint - - go get -u github.com/gordonklaus/ineffassign - - export GOOS=$TRAVIS_GOOS -# FIXME: For non-linux GOOS, without running `go build -i`, vet fails with `vet: import failed: can't find import: fmt`... -# Note that `go build -i` requires write permission to GOROOT. (So it is not called in Makefile) - - go build -i github.com/linuxkit/linuxkit/src/cmd/linuxkit - - make local-check - - make local-build - - if [ "$GOOS" = "linux" ]; then make local-test ; fi