From c67efbf46d33b6a9f7d249dacfa393706fe6d559 Mon Sep 17 00:00:00 2001 From: Jussi Nummelin Date: Sun, 16 Feb 2020 11:56:05 +0200 Subject: [PATCH] refactor build to makefile --- .drone.yml | 3 ++- .gitignore | 1 + Makefile | 19 +++++++++++++++++-- hack/build.sh | 19 ------------------- main.go | 8 +++++--- 5 files changed, 25 insertions(+), 25 deletions(-) delete mode 100755 hack/build.sh diff --git a/.drone.yml b/.drone.yml index 6af0615..0f08694 100644 --- a/.drone.yml +++ b/.drone.yml @@ -22,7 +22,8 @@ steps: - name: build image: golang:1.13 commands: - - ./hack/build.sh + - GO111MODULE=off go get github.com/mitchellh/gox + - make build environment: BUILD_ARCHS: "linux/amd64 linux/arm64 linux/arm darwin/amd64 windows/amd64" when: diff --git a/.gitignore b/.gitignore index 65e0b9f..010afca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /cluster.yml /cloudinit.yml +output/ \ No newline at end of file diff --git a/Makefile b/Makefile index 506ac3c..38448dd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,18 @@ -.PHONY: test +.PHONY: test clean test: - CGO_ENABLED=0 go test $(shell go list ./... | grep -v /vendor/|xargs echo) -cover \ No newline at end of file + CGO_ENABLED=0 go test $(shell go list ./... | grep -v /vendor/|xargs echo) -cover + + +BUILD_ARCHS ?= $(shell go env GOOS)/$(shell go env GOARCH) +# User drone tag as the build verion if given in env +VERSION ?= $(or ${DRONE_TAG},latest) + +build: + mkdir -p output + CGO_ENABLED=0 gox -output="output/trieres_{{.OS}}_{{.Arch}}" \ + -osarch="${BUILD_ARCHS}" \ + -ldflags "-s -w -X main.Version=${VERSION}" \ + github.com/jakolehm/trieres/ + +clean: + rm -rf output/* \ No newline at end of file diff --git a/hack/build.sh b/hack/build.sh deleted file mode 100755 index 6ef27e7..0000000 --- a/hack/build.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -eox - -# To easily cross-compile binaries -GO111MODULE=off go get github.com/mitchellh/gox - -VERSION=${DRONE_TAG:-latest} -GIT_COMMIT=$(git rev-list -1 HEAD || echo 'dirrrty') - -CURRENT_ARCH="$(go env GOOS)/$(go env GOARCH)" - -BUILD_ARCHS=${BUILD_ARCHS:-$CURRENT_ARCH} - -mkdir -p output -CGO_ENABLED=0 gox -output="output/trieres_{{.OS}}_{{.Arch}}" \ - -osarch="${BUILD_ARCHS}" \ - -ldflags "-s -w -X github.com/jakolehm/trieres/main.Version=${VERSION}" \ - github.com/jakolehm/trieres/ diff --git a/main.go b/main.go index 7a682fc..79cc35a 100644 --- a/main.go +++ b/main.go @@ -9,8 +9,10 @@ import ( "github.com/urfave/cli/v2" ) -// VERSION gets overridden at build time using -X main.VERSION=$VERSION -var VERSION = "dev" +// Version gets overridden at build time using -X main.Version=$VERSION +var ( + Version = "dev" +) func init() { logrus.SetOutput(os.Stdout) @@ -20,7 +22,7 @@ func init() { func main() { app := &cli.App{ Name: "trieres", - Version: VERSION, + Version: Version, Usage: "k3s cluster lifecycle management tool", Commands: []*cli.Command{ cmd.UpCommand(),