|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
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 = ./... |
19 | 18 |
|
20 | 19 | PREFIX ?= $(shell pwd) |
21 | | -BIN_DIR ?= $(shell pwd) |
| 20 | +BIN_DIR ?= $(PREFIX)/bin |
22 | 21 | DOCKER_IMAGE_NAME ?= mongodb-exporter |
23 | 22 | DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) |
24 | 23 |
|
25 | 24 | # Race detector is only supported on amd64. |
26 | 25 | RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race")) |
27 | 26 |
|
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 |
29 | 43 |
|
30 | 44 | style: |
31 | 45 | @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 '^' |
33 | 47 |
|
34 | | -test: |
| 48 | +test: init mongo-db-in-docker |
35 | 49 | @echo ">> running tests" |
36 | | - gocoverutil -coverprofile=coverage.txt test -short -v $(RACE) $(pkgs) |
| 50 | + go test -coverprofile=coverage.txt -short -v $(RACE) $(pkgs) |
37 | 51 |
|
38 | | -testall: |
| 52 | +test-all: init mongo-db-in-docker |
39 | 53 | @echo ">> running all tests" |
40 | | - gocoverutil -coverprofile=coverage.txt test -v $(RACE) $(pkgs) |
| 54 | + go test -coverprofile=coverage.txt -v $(RACE) $(pkgs) |
41 | 55 |
|
42 | 56 | format: |
43 | 57 | @echo ">> formatting code" |
|
47 | 61 | @echo ">> vetting code" |
48 | 62 | @$(GO) vet $(pkgs) |
49 | 63 |
|
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) . |
53 | 85 |
|
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 |
57 | 89 |
|
58 | 90 | docker: |
59 | 91 | @echo ">> building docker image" |
60 | 92 | @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . |
61 | 93 |
|
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 |
67 | 112 |
|
| 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 |
68 | 124 |
|
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