Skip to content

Commit

Permalink
promu for building the binaries
Browse files Browse the repository at this point in the history
Reworked the build process using promu and travis.
  • Loading branch information
kbudde committed Jun 23, 2016
1 parent c2841f3 commit 24d2da6
Show file tree
Hide file tree
Showing 26 changed files with 1,143 additions and 163 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.build/
.tarballs/

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.build
dependencies-stamp
rabbitmq_exporter
rabbitmq_exporter.exe
rabbitmq_exporter.exe
.tarballs/
22 changes: 22 additions & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
go: 1.6.2
verbose: true
repository:
path: github.com/kbudde/rabbitmq_exporter
build:
flags: -a -tags netgo
ldflags: |
-X main.Version={{.Version}}
-X main.Revision={{.Revision}}
-X main.Branch={{.Branch}}
-X main.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
crossbuild:
platforms:
- linux/amd64
- linux/386
- darwin/amd64
- darwin/386
- windows/amd64
- windows/386
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ env:
global:
- PATH=/home/travis/gopath/bin:$PATH
- COMMIT=${TRAVIS_COMMIT::8}
- REPO=kbudde/rabbitmq-exporter
before_install:
- go get github.com/mitchellh/gox
- go get github.com/tcnksm/ghr

- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
- go get github.com/aktau/github-release

install:
- go get -t ./...
Expand All @@ -25,17 +27,15 @@ script:
- go test -v -covermode=count -coverprofile=coverage.out ./...

after_success:
#Build Dockerfile.scratch image
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o rabbitmq_exporter_static .
#Build Docker image
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
- export REPO=kbudde/rabbitmq-exporter
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi`
- docker build -f Dockerfile.scratch -t $REPO:$TAG .
- make docker DOCKER_IMAGE_NAME=$REPO DOCKER_IMAGE_TAG=$TAG
- docker push $REPO

#Build dist releases
- gox -os="linux windows darwin" -output "dist/{{.OS}}_{{.Arch}}_{{.Dir}}"
- ghr --username kbudde --token $GITHUB_TOKEN --replace --prerelease --debug pre-release dist/
- make tarballs
- promu release -v

#Submit coverage
- goveralls -coverprofile=coverage.out -service travis-ci -repotoken $COVERALLS_TOKEN
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
FROM sdurrheimer/alpine-golang-make-onbuild
FROM scratch
MAINTAINER Kris Budde <[email protected]>
EXPOSE 9090

COPY rabbitmq_exporter /

EXPOSE 9090

CMD ["/rabbitmq_exporter"]
8 changes: 0 additions & 8 deletions Dockerfile.scratch

This file was deleted.

File renamed without changes.
67 changes: 60 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,65 @@
VERSION := 0.10.0
TARGET := rabbitmq_exporter
ROOTPKG := github.com/kbudde/$(TARGET)
# Copyright 2016 The Prometheus Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include Makefile.COMMON
GO := go
PROMU := $(GOPATH)/bin/promu
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)

PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= rabbitmq-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))

docker:
cd $(SELFLINK) && CGO_ENABLED=0 GOOS=linux $(GO) build -a -installsuffix cgo -o $(TARGET)_static && docker build -f Dockerfile.scratch -t $(TARGET):scratch .

all: format build test

style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'

test:
@echo ">> running tests"
@$(GO) test -short $(pkgs)

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)

tarballs: promu
@echo ">> building crossbuild"
@$(PROMU) crossbuild
@echo ">> building crossbuild tarballs"
@$(PROMU) crossbuild tarballs

docker: build
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

promu:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) get -v github.com/prometheus/promu

.PHONY: docker
.PHONY: all style format build test vet tarball tarballs docker promu
131 changes: 0 additions & 131 deletions Makefile.COMMON

This file was deleted.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ For each queue the number of:

## Docker

There are two options to build the docker image locally.

1. Build using the sdurrheimer/alpine-golang-make-onbuild images (Go 1.5.3 is used)

docker -t rabbitmq-exporter:onbuild .

2. Build using the scratch image with static binary (go has to be installed locally)
To create a docker image locally it is recommened to use the Makefile.
Promu is used for building the statically linked binary which is added to the scratch image.

make docker
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.12.0
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func main() {
"RABBIT_URL": config.RabbitURL,
"RABBIT_USER": config.RabbitUsername,
"OUTPUT_FORMAT": config.OutputFormat,
"VERSION": Version,
"REVISION": Revision,
"BRANCH": Branch,
"BUILD_DATE": BuildDate,
// "RABBIT_PASSWORD": config.RABBIT_PASSWORD,
}).Info("Starting RabbitMQ exporter")

Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/beorn7/perks/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/github.com/golang/protobuf/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 24d2da6

Please sign in to comment.