forked from chop-dbhi/prometheus-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
57 lines (45 loc) · 1.59 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
57
PROG_NAME := "prometheus-sql"
IMAGE_NAME := "dbhi/prometheus-sql"
CMD_PATH := "."
GIT_SHA := $(shell git log -1 --pretty=format:"%h" .)
GIT_TAG := $(shell git describe --tags --exact-match . 2>/dev/null)
GIT_BRANCH := $(shell git symbolic-ref -q --short HEAD)
GIT_VERSION := $(shell git log -1 --pretty=format:"%h (%ci)" .)
build:
go build -ldflags "-X \"main.buildVersion=$(GIT_VERSION)\"" \
-o $(GOPATH)/bin/$(PROG_NAME) $(CMD_PATH)
dist-build:
mkdir -p dist
gox -output="./dist/{{.OS}}-{{.Arch}}/$(PROG_NAME)" \
-ldflags "-X \"main.buildVersion=$(GIT_VERSION)\"" \
-os "windows linux darwin" \
-arch "amd64" $(CMD_PATH) > /dev/null
dist-pkg:
cd dist && tar -czvf $(PROG_NAME)-darwin-amd64.tar.gz darwin-amd64/*
cd dist && tar -czvf $(PROG_NAME)-linux-amd64.tar.gz linux-amd64/*
cd dist && zip $(PROG_NAME)-windows-amd64.zip windows-amd64/*
dist: dist-build dist-pkg
docker:
docker build -t ${IMAGE_NAME}:${GIT_SHA} .
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:${GIT_BRANCH}
if [ -n "${GIT_TAG}" ] ; then \
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:${GIT_TAG} ; \
fi;
if [ "${GIT_BRANCH}" == "master" ]; then \
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:latest ; \
fi;
docker-push:
docker push ${IMAGE_NAME}:${GIT_SHA}
docker push ${IMAGE_NAME}:${GIT_BRANCH}
if [ -n "${GIT_TAG}" ]; then \
docker push ${IMAGE_NAME}:${GIT_TAG} ; \
fi;
if [ "${GIT_BRANCH}" == "master" ]; then \
docker push ${IMAGE_NAME}:latest ; \
fi;
prepareDeps:
go get -d
gox:
go get github.com/mitchellh/gox
prepare: gox prepareDeps
.PHONY: prepare prepareDeps build dist-build dist