Skip to content

Commit d30a544

Browse files
Anton KucherovAlekSi
authored andcommitted
PMM-3513 Make releases with GoReleaser (#132)
1 parent 1e86da2 commit d30a544

File tree

18 files changed

+1100
-102
lines changed

18 files changed

+1100
-102
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ coverage.txt
77
coverage_temp.txt
88
/.history
99
/.idea
10+
11+
# ignore built binaries
12+
/bin

.goreleaser.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This is an goreleaser.yaml file which builds mongodb_exporter releases.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
# You can run it locally or with your CI, but you should use `make community-release` or `make snapshot`
4+
# instead of using `goreleaser` directly as some init steps should be done before it runs.
5+
dist: bin
6+
builds:
7+
- binary: mongodb_exporter
8+
env:
9+
- CGO_ENABLED=0
10+
goos:
11+
- linux
12+
- darwin
13+
goarch:
14+
- amd64
15+
flags:
16+
- -v
17+
# We don't use internal `GoReleaser` variables because of consistency with `Makefile` and
18+
# because we can't change it behaviour.
19+
ldflags: |
20+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/percona/pmm/version.ProjectName={{.Env.BIN_NAME}}
21+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/percona/pmm/version.Version={{.Env.APP_VERSION}}
22+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/percona/pmm/version.PMMVersion={{.Env.PMM_RELEASE_VERSION}}
23+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/percona/pmm/version.Timestamp={{.Env.PMM_RELEASE_TIMESTAMP}}
24+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/percona/pmm/version.FullCommit={{.Env.PMM_RELEASE_FULLCOMMIT}}
25+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/percona/pmm/version.Branch={{.Env.PMM_RELEASE_BRANCH}}
26+
-X {{.Env.GO_PACKAGE}}/vendor/github.com/prometheus/common/version.BuildUser={{.Env.USER}}@{{.Env.TRAVIS_APP_HOST}}
27+
archive:
28+
name_template: "{{ .ProjectName }}-{{ .Env.APP_VERSION }}.{{ .Os }}-{{ .Arch }}"
29+
checksum:
30+
name_template: '{{ .ProjectName }}-{{ .Env.APP_VERSION }}-checksums.txt'
31+
snapshot:
32+
name_template: "{{ .ShortCommit }}"
33+
changelog:
34+
skip: true
35+
release:
36+
github:
37+
owner: percona
38+
name: mongodb_exporter
39+
draft: true
40+
prerelease: auto

.promu.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.travis.yml

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ dist: trusty
22
sudo: required
33
language: go
44

5+
stages:
6+
- build
7+
- test
8+
- deploy
9+
510
go:
611
- 1.11.x
712
- 1.12.x
@@ -11,47 +16,39 @@ matrix:
1116
- go: master
1217

1318
env:
14-
# https://www.mongodb.com/support-policy
15-
- MONGODB_IMAGE=mongo:3.4
16-
- MONGODB_IMAGE=mongo:3.6
17-
- MONGODB_IMAGE=mongo:4.0
18-
19-
# https://www.percona.com/services/policies/percona-software-platform-lifecycle#mongodb
20-
- MONGODB_IMAGE=percona/percona-server-mongodb:3.4
21-
- MONGODB_IMAGE=percona/percona-server-mongodb:3.6
22-
- MONGODB_IMAGE=percona/percona-server-mongodb:4.0
19+
global:
20+
- TMPDIR=/tmp
21+
matrix:
22+
# https://www.mongodb.com/support-policy
23+
- MONGODB_IMAGE=mongo:3.4
24+
- MONGODB_IMAGE=mongo:3.6
25+
- MONGODB_IMAGE=mongo:4.0
26+
27+
# https://www.percona.com/services/policies/percona-software-platform-lifecycle#mongodb
28+
- MONGODB_IMAGE=percona/percona-server-mongodb:3.4
29+
- MONGODB_IMAGE=percona/percona-server-mongodb:3.6
30+
- MONGODB_IMAGE=percona/percona-server-mongodb:4.0
2331

2432
services:
2533
- docker
2634

27-
before_script:
28-
# Start docker containers.
29-
- docker-compose up -d
30-
# Wait for MongoDB to become available.
31-
- |
32-
until docker-compose exec mongo mongo --quiet --eval 'db.runCommand("ping").ok' > /dev/null; do
33-
>&2 echo "MongoDB is unavailable - sleeping"
34-
sleep 1
35-
done
36-
>&2 echo "MongoDB is up"
37-
# Display logs for debug purposes.
38-
- docker-compose logs
39-
# Display versions.
40-
- docker --version
41-
- docker-compose --version
42-
- docker-compose exec mongo mongo --version
43-
44-
script:
45-
# ensure that vendor/ is in sync with code and Gopkg.*
46-
- curl https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -L -o ~/dep && chmod +x ~/dep
47-
- rm -fr vendor/
48-
- ~/dep ensure -v
49-
- git diff --exit-code
50-
51-
- make format build testall
52-
53-
after_success:
54-
- bash <(curl -s https://codecov.io/bash) -X fix
35+
script: make test-all
36+
37+
jobs:
38+
include:
39+
- stage: build
40+
script:
41+
- make check-vendor-synced style build
42+
43+
- stage: deploy
44+
script: skip
45+
deploy:
46+
provider: script
47+
script: make community-release
48+
on:
49+
tags: true
50+
51+
after_success: bash <(curl -s https://codecov.io/bash) -X fix
5552

5653
notifications:
5754
slack:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This is a **BREAKING CHANGE**. The labels of these metrics are now prefixed with
1515
### Added
1616
- Fine grained error handling for index usage and collection stats (#128), thx [@akira-kurogane](https://github.com/akira-kurogane)
1717
- Introduce a docker go build that creates a mongodb_exporter binary within a container (#112), thx [@mminks](https://github.com/mminks)
18+
- Ability to make releases and snapshots with [GoReleaser](https://goreleaser.com/)
1819

1920
## [0.6.3] - 2019-02-13
2021
### Added

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ WORKDIR /go/src/github.com/percona/mongodb_exporter
66

77
COPY . .
88

9-
RUN make init build
9+
RUN make build
1010

1111
FROM quay.io/prometheus/busybox:latest
1212

1313
LABEL maintainer="Alexey Palazhchenko <[email protected]>"
1414

15-
COPY --from=0 /go/src/github.com/percona/mongodb_exporter/mongodb_exporter /bin/mongodb_exporter
15+
COPY --from=0 /go/src/github.com/percona/mongodb_exporter/bin/mongodb_exporter /bin/mongodb_exporter
1616

1717
EXPOSE 9216
1818

Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
go-tests = true
33
non-go = true
44
unused-packages = true
5+
6+
[[constraint]]
7+
name = "github.com/percona/pmm"
8+
branch = "PMM-2.0"

Makefile

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,46 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
GO := go
16-
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
17-
PROMU := $(FIRST_GOPATH)/bin/promu -v
18-
pkgs = ./...
15+
GO := go
16+
GOPATH := $(shell $(GO) env GOPATH)
17+
pkgs = ./...
1918

2019
PREFIX ?= $(shell pwd)
21-
BIN_DIR ?= $(shell pwd)
20+
BIN_DIR ?= $(PREFIX)/bin
2221
DOCKER_IMAGE_NAME ?= mongodb-exporter
2322
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
2423

2524
# Race detector is only supported on amd64.
2625
RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))
2726

28-
all: format build test
27+
export BIN_NAME := mongodb_exporter
28+
export TRAVIS_APP_HOST ?= $(shell hostname)
29+
export TRAVIS_BRANCH ?= $(shell git describe --all --contains --dirty HEAD)
30+
export TRAVIS_TAG ?= $(shell git describe --tags --abbrev=0)
31+
export GO_PACKAGE := github.com/percona/mongodb_exporter
32+
export APP_VERSION := $(shell echo $(TRAVIS_TAG) | sed -e 's/v//g')
33+
export APP_REVISION := $(shell git rev-parse HEAD)
34+
export BUILD_TIME := $(shell date '+%Y%m%d-%H:%M:%S')
35+
36+
# We sets default pmm version to empty as we want to build community release by default
37+
export PMM_RELEASE_VERSION ?=
38+
export PMM_RELEASE_TIMESTAMP = $(shell date '+%s')
39+
export PMM_RELEASE_FULLCOMMIT = $(APP_REVISION)
40+
export PMM_RELEASE_BRANCH = $(TRAVIS_BRANCH)
41+
42+
all: clean format build test
2943

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

34-
test:
48+
test: init mongo-db-in-docker
3549
@echo ">> running tests"
36-
gocoverutil -coverprofile=coverage.txt test -short -v $(RACE) $(pkgs)
50+
go test -coverprofile=coverage.txt -short -v $(RACE) $(pkgs)
3751

38-
testall:
52+
test-all: init mongo-db-in-docker
3953
@echo ">> running all tests"
40-
gocoverutil -coverprofile=coverage.txt test -v $(RACE) $(pkgs)
54+
go test -coverprofile=coverage.txt -v $(RACE) $(pkgs)
4155

4256
format:
4357
@echo ">> formatting code"
@@ -47,23 +61,65 @@ vet:
4761
@echo ">> vetting code"
4862
@$(GO) vet $(pkgs)
4963

50-
build: init
51-
@echo ">> building binaries"
52-
@$(PROMU) build --prefix $(PREFIX)
64+
# It's just alias to build binary
65+
build: release
66+
67+
snapshot: $(GOPATH)/bin/goreleaser
68+
@echo ">> building snapshot"
69+
goreleaser --snapshot --skip-sign --skip-validate --skip-publish --rm-dist
70+
71+
# We use this target name to build binary across all PMM components
72+
release:
73+
@echo ">> building binary"
74+
@CGO_ENABLED=0 $(GO) build -v \
75+
-ldflags '\
76+
-X '$(GO_PACKAGE)/vendor/github.com/percona/pmm/version.ProjectName=$(BIN_NAME)' \
77+
-X '$(GO_PACKAGE)/vendor/github.com/percona/pmm/version.Version=$(APP_VERSION)' \
78+
-X '$(GO_PACKAGE)/vendor/github.com/percona/pmm/version.PMMVersion=$(PMM_RELEASE_VERSION)' \
79+
-X '$(GO_PACKAGE)/vendor/github.com/percona/pmm/version.Timestamp=$(PMM_RELEASE_TIMESTAMP)' \
80+
-X '$(GO_PACKAGE)/vendor/github.com/percona/pmm/version.FullCommit=$(PMM_RELEASE_FULLCOMMIT)' \
81+
-X '$(GO_PACKAGE)/vendor/github.com/percona/pmm/version.Branch=$(PMM_RELEASE_BRANCH)' \
82+
-X '$(GO_PACKAGE)/vendor/github.com/prometheus/common/version.BuildUser=$(USER)@$(TRAVIS_APP_HOST)' \
83+
'\
84+
-o $(BIN_DIR)/$(BIN_NAME) .
5385

54-
tarball: init
55-
@echo ">> building release tarball"
56-
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
86+
community-release: $(GOPATH)/bin/goreleaser
87+
@echo ">> building release"
88+
goreleaser release --rm-dist --skip-validate
5789

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

62-
init:
63-
$(GO) get -u github.com/AlekSi/gocoverutil
64-
GOOS=$(shell uname -s | tr A-Z a-z) \
65-
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(subst aarch64,arm64,$(shell uname -m)))) \
66-
$(GO) get -u github.com/prometheus/promu
94+
$(GOPATH)/bin/dep:
95+
curl -s https://raw.githubusercontent.com/golang/dep/v0.5.0/install.sh | sh
96+
97+
$(GOPATH)/bin/goreleaser:
98+
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | BINDIR=$(GOPATH)/bin sh
99+
100+
init: $(GOPATH)/bin/dep $(GOPATH)/bin/goreleaser
101+
102+
# Ensure that vendor/ is in sync with code and Gopkg.*
103+
check-vendor-synced: init
104+
rm -fr vendor/
105+
dep ensure -v
106+
git diff --exit-code
107+
108+
clean:
109+
@echo ">> removing build artifacts"
110+
@rm -f $(PREFIX)/coverage.txt
111+
@rm -Rf $(PREFIX)/bin
67112

113+
mongo-db-in-docker:
114+
# Start docker containers.
115+
docker-compose up -d
116+
# Wait for MongoDB to become available.
117+
./scripts/wait-for-mongo.sh
118+
# Display logs for debug purposes.
119+
docker-compose logs
120+
# Display versions.
121+
docker --version
122+
docker-compose --version
123+
docker-compose exec mongo mongo --version
68124

69-
.PHONY: all style format build test vet tarball docker init
125+
.PHONY: init all style format build release test vet release docker clean check-vendor-synced mongo-db-in-docker

0 commit comments

Comments
 (0)