From 8a757b2bf5e1cd1054b5b6f28875fcbf5c89cf33 Mon Sep 17 00:00:00 2001 From: Charles JUDITH Date: Mon, 8 Jan 2018 07:58:33 +0100 Subject: [PATCH 1/2] Add promu support to build binary - Modify Makefile for promu - Add VERSION file - Add promu.yml --- .promu.yml | 44 +++++++++++++++++++++++++++++++++++++++++ Makefile | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++---- VERSION | 1 + 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 .promu.yml create mode 100644 VERSION diff --git a/.promu.yml b/.promu.yml new file mode 100644 index 0000000..cab3b4b --- /dev/null +++ b/.promu.yml @@ -0,0 +1,44 @@ +repository: + path: github.com/cloudflare/alertmanager2es +build: + binaries: + - name: alertmanager2es + path: . + flags: -a -tags netgo + ldflags: | + -X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} +tarball: + files: + - LICENSE + - NOTICE +crossbuild: + platforms: + - linux/amd64 + - linux/386 + - darwin/amd64 + - darwin/386 + - windows/amd64 + - windows/386 + - freebsd/amd64 + - freebsd/386 + - openbsd/amd64 + - openbsd/386 + - netbsd/amd64 + - netbsd/386 + - dragonfly/amd64 + - linux/arm + - linux/arm64 + - freebsd/arm + # Temporarily deactivated as golang.org/x/sys does not have syscalls + # implemented for that os/platform combination. + #- openbsd/arm + #- linux/mips64 + #- linux/mips64le + - netbsd/arm + - linux/ppc64 + - linux/ppc64le + diff --git a/Makefile b/Makefile index 08fb0bd..e0fee48 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,57 @@ -.PHONY: build test +GO := GO15VENDOREXPERIMENT=1 go +PROMU := $(GOPATH)/bin/promu +pkgs = $(shell $(GO) list ./... | grep -v -E '/vendor/|/ui') -build: test - go build -ldflags "-X main.revision=$(shell git describe --tags --always --dirty=-dev)" +PREFIX ?= $(shell pwd) +BIN_DIR ?= $(shell pwd) +DOCKER_IMAGE_NAME ?= alertmanager2es +DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) + +ifdef DEBUG + bindata_flags = -debug +endif + + +all: format build test test: - go test $(go list ./... | grep -v /vendor/) + @echo ">> running tests" + @$(GO) test -race -short $(pkgs) + +style: + @echo ">> checking code style" + @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +format: + @echo ">> formatting code" + @$(GO) fmt $(pkgs) + +vet: + @echo ">> vetting code" + @$(GO) vet $(pkgs) + +build: promu + @echo ">> building binaries" + @$(PROMU) build --prefix $(PREFIX) + +tarball: promu + @echo ">> building release tarball" + @$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) + +docker: + @echo ">> building docker image" + @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . + +assets: + @echo ">> writing assets" + -@$(GO) get -u github.com/jteeuwen/go-bindata/... + +promu: + @GOOS=$(shell uname -s | tr A-Z a-z) \ + GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ + $(GO) get -u github.com/prometheus/promu + +proto: + + +.PHONY: all style format build test vet assets tarball docker promu proto diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..4e379d2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.2 From c655dc11092b69f9ea6e0b3f56edec3ae8b2928e Mon Sep 17 00:00:00 2001 From: Charles JUDITH Date: Mon, 8 Jan 2018 16:13:41 +0100 Subject: [PATCH 2/2] Refactoring for promu settings - Remove useless targets in Makefile - Fix grep in .promu.yml - Add .travis.yml --- .promu.yml | 4 +--- .travis.yml | 9 ++++++--- Makefile | 8 +------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.promu.yml b/.promu.yml index cab3b4b..52e8b47 100644 --- a/.promu.yml +++ b/.promu.yml @@ -4,17 +4,16 @@ build: binaries: - name: alertmanager2es path: . - flags: -a -tags netgo ldflags: | -X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}} -X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}} -X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}} -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}} -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} + tarball: files: - LICENSE - - NOTICE crossbuild: platforms: - linux/amd64 @@ -41,4 +40,3 @@ crossbuild: - netbsd/arm - linux/ppc64 - linux/ppc64le - diff --git a/.travis.yml b/.travis.yml index 8868756..255d6dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,13 @@ language: go go: - - 1.7.x - - 1.8.x - - master +- 1.7.x +- 1.8.x +- master matrix: allow_failures: - go: master + +script: +- make style test diff --git a/Makefile b/Makefile index e0fee48..47b833d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ GO := GO15VENDOREXPERIMENT=1 go PROMU := $(GOPATH)/bin/promu -pkgs = $(shell $(GO) list ./... | grep -v -E '/vendor/|/ui') +pkgs = $(shell $(GO) list ./... | grep -v -E '/vendor/') PREFIX ?= $(shell pwd) BIN_DIR ?= $(shell pwd) @@ -42,16 +42,10 @@ docker: @echo ">> building docker image" @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . -assets: - @echo ">> writing assets" - -@$(GO) get -u github.com/jteeuwen/go-bindata/... - promu: @GOOS=$(shell uname -s | tr A-Z a-z) \ GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ $(GO) get -u github.com/prometheus/promu -proto: - .PHONY: all style format build test vet assets tarball docker promu proto