-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
82 lines (63 loc) · 2.35 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
all: push
BUILDTAGS=
# Use the 0.0.0 tag for testing, it shouldn't clobber any release builds
APP=charts
USERSPACE?=k8s-community
RELEASE?=0.1.12
PROJECT?=github.com/${USERSPACE}/${APP}
HELM_REPO?=https://services.k8s.community/${APP}
GOOS?=linux
REGISTRY?=registry.k8s.community
CHARTS_SERVICE_PORT?=8080
CHARTS_SERVICE_HEALTH_PORT?=8082
NAMESPACE?=dev
PREFIX?=${REGISTRY}/${NAMESPACE}/${APP}
CONTAINER_NAME?=${APP}-${NAMESPACE}
ifeq ($(NAMESPACE), default)
PREFIX=${REGISTRY}/${APP}
CONTAINER_NAME=${APP}
endif
REPO_INFO=$(shell git config --get remote.origin.url)
ifndef COMMIT
COMMIT := git-$(shell git rev-parse --short HEAD)
endif
vendor: clean
go get -u github.com/Masterminds/glide \
&& glide install
utils:
go get -u github.com/golang/lint/golint
build: vendor
CGO_ENABLED=0 GOOS=${GOOS} go build -a -installsuffix cgo \
-ldflags "-s -w -X ${PROJECT}/version.RELEASE=${RELEASE} -X ${PROJECT}/version.COMMIT=${COMMIT} -X ${PROJECT}/version.REPO=${REPO_INFO}" \
-o ${APP}-server
container: build
docker build --pull -t $(PREFIX):$(RELEASE) .
push: container
docker push $(PREFIX):$(RELEASE)
run: container
docker run --name ${CONTAINER_NAME} -p ${CHARTS_SERVICE_PORT}:${CHARTS_SERVICE_PORT} \
-p ${CHARTS_SERVICE_HEALTH_PORT}:${CHARTS_SERVICE_HEALTH_PORT} \
-e "CHARTS_SERVICE_PORT=${CHARTS_SERVICE_PORT}" \
-e "CHARTS_SERVICE_HEALTH_PORT=${CHARTS_SERVICE_HEALTH_PORT}" \
-d $(PREFIX):$(RELEASE)
deploy: push
helm repo add ${USERSPACE} ${HELM_REPO} \
&& helm repo up \
&& helm upgrade ${CONTAINER_NAME} ${USERSPACE}/${APP} --namespace ${NAMESPACE} --set image.tag=${RELEASE} -i --wait
fmt:
@echo "+ $@"
@go list -f '{{if len .TestGoFiles}}"gofmt -s -l {{.Dir}}"{{end}}' $(shell go list ${PROJECT}/... | grep -v vendor) | xargs -L 1 sh -c
lint: utils
@echo "+ $@"
@go list -f '{{if len .TestGoFiles}}"golint {{.Dir}}/..."{{end}}' $(shell go list ${PROJECT}/... | grep -v vendor) | xargs -L 1 sh -c
vet:
@echo "+ $@"
@go vet $(shell go list ${PROJECT}/... | grep -v vendor)
test: vendor utils fmt lint vet
@echo "+ $@"
@go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PROJECT}/... | grep -v vendor)
cover:
@echo "+ $@"
@go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' $(shell go list ${PROJECT}/... | grep -v vendor) | xargs -L 1 sh -c
clean:
rm -f ${APP}-server