Skip to content

Commit

Permalink
Add make dist command to build version binary releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Ferencz-Szabo committed Nov 29, 2019
1 parent 6ad1d92 commit d175812
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
28 changes: 28 additions & 0 deletions dist.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d175812

Please sign in to comment.