From d17581237f13df0b3608ac88782d4b508f53037d Mon Sep 17 00:00:00 2001 From: Andras Ferencz-Szabo Date: Mon, 9 Sep 2019 11:49:16 +0100 Subject: [PATCH] Add make dist command to build version binary releases --- Makefile | 21 ++++++++++++++++++--- README.md | 7 +++++++ dist.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100755 dist.sh diff --git a/Makefile b/Makefile index a5098d3..de678a4 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,49 @@ -.PHONY: all clean test build - DOCKER_REPOSITORY ?= monzo DOCKER_TAG ?= latest DOCKER_IMAGE ?= $(DOCKER_REPOSITORY)/kontrast:$(DOCKER_TAG) +ALL_GOARCH = amd64 +ALL_GOOS = linux darwin + +.PHONY: clean clean: - rm -f bin/ + rm -rf bin/ +.PHONY: build build: mkdir -p bin/ dep ensure -v go build -o bin/kontrast ./cmd/kontrast +.PHONY: kontrastd kontrastd: mkdir -p bin/ dep ensure -v go build -o bin/kontrastd ./cmd/kontrastd +.PHONY: build-in-docker build-in-docker: dep ensure -vendor-only -v CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/kontrastd ./cmd/kontrastd +.PHONY: build-linux build-linux: mkdir -p bin/ dep ensure -v GOOS=linux go build -o bin/kontrast ./cmd/kontrast +.PHONY: dist +dist: + $(eval export ALL_GOARCH) + $(eval export ALL_GOOS) + mkdir -p bin/ + NAME=kontrast ./dist.sh + +.PHONY: docker docker: docker build . -t $(DOCKER_IMAGE) +.PHONY: docker-push docker-push: docker docker push $(DOCKER_IMAGE) diff --git a/README.md b/README.md index d5019d0..14fc759 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,13 @@ Note: this takes a while [1] `kontrast my-manifest.yaml` +## Release process + +1. Create a new semver version tag on master in "v0.1.2" format +2. Push the tag +3. Run `make clean dist` to build the binary releases +4. Create a new release on Github and upload all files from `bin/` + --- ###### [1] Why does it take so long to build/install? Why is the binary 150MB? diff --git a/dist.sh b/dist.sh new file mode 100755 index 0000000..54419fe --- /dev/null +++ b/dist.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -eo pipefail + +VERSION="" +if [ -z "${VERSION}" ]; then + VERSION=$(git tag | sort -r --version-sort | head -n1) +fi + +if [ -z "${VERSION}" ]; then + echo "VERSION can not be empty" +fi + +VERSION=${VERSION/v/} + +echo "Building version ${VERSION}" + +mkdir -p bin + +for arch in ${ALL_GOARCH}; do + for platform in ${ALL_GOOS}; do + file="bin/${NAME}-${VERSION}.${platform}.${arch}" + echo "Building ${file}" + CGO_ENABLED=0 GOOS=${platform} GOARCH=${arch} go build -ldflags="-s -w" -o ${file} ./cmd/${NAME} + done +done + +cd bin && shasum -a 256 ${NAME}-${VERSION}.* > ${NAME}-${VERSION}.sha256sums