forked from timescale/prometheus-postgresql-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (41 loc) · 1.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
VERSION=$(shell git describe --always | sed 's|v\(.*\)|\1|')
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
OS:=$(shell uname -s | awk '{ print tolower($$1) }')
ARCH=amd64
ORGANIZATION=timescale
ifeq ($(shell uname -m), i386)
ARCH=386
endif
# Packages for running tests
PKGS:= $(shell go list ./... | grep -v /vendor)
SOURCES:=$(shell find . -name '*.go' | grep -v './vendor')
TARGET:=prometheus-postgresql-adapter
.PHONY: all clean build docker-image docker-push test prepare-for-docker-build
all: $(TARGET) version.properties
version.properties:
@echo "version=${VERSION}" > version.properties
.target_os:
@echo $(OS) > .target_os
build: $(TARGET)
$(TARGET): .target_os $(SOURCES)
$(if $(shell command -v dep 2> /dev/null),$(info Found golang/dep),$(error Please install golang/dep))
dep ensure
GOOS=$(OS) GOARCH=${ARCH} CGO_ENABLED=0 go build -a -installsuffix cgo --ldflags '-w' -o $@
prepare-for-docker-build:
$(eval OS=linux)
ifneq ($(shell cat .target_os 2>/dev/null),linux)
rm -f $(TARGET) .target_os
endif
docker-image: prepare-for-docker-build prometheus-postgresql-adapter version.properties
docker build -t $(ORGANIZATION)/$(TARGET):latest .
docker tag $(ORGANIZATION)/$(TARGET):latest $(ORGANIZATION)/$(TARGET):${VERSION}
docker tag $(ORGANIZATION)/$(TARGET):latest $(ORGANIZATION)/$(TARGET):${BRANCH}
docker-push: docker-image
docker push $(ORGANIZATION)/$(TARGET):latest
docker push $(ORGANIZATION)/$(TARGET):${VERSION}
docker push $(ORGANIZATION)/$(TARGET):${BRANCH}
test:
GOCACHE=off go test -v -race $(PKGS) -args -database=false
clean:
go clean
rm -f *~ $(TARGET) version.properties .target_os