-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
135 lines (108 loc) · 3 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
all: push
BUILDTAGS=
APP?=github-integration
PROJECT?=github.com/k8s-community/${APP}
REGISTRY?=docker.io/k8sc
CA_DIR?=certs
# Use the 0.0.0 tag for testing, it shouldn't clobber any release builds
RELEASE?=0.9.7
GOOS?=linux
GOARCH?=amd64
GITHUBINT_LOCAL_PORT?=8080
NAMESPACE?=k8s-community
INFRASTRUCTURE?=stable
KUBE_CONTEXT?=${INFRASTRUCTURE}
VALUES?=values-${INFRASTRUCTURE}
CONTAINER_NAME?=${NAMESPACE}-${APP}
CONTAINER_IMAGE?=${REGISTRY}/${CONTAINER_NAME}
REPO_INFO=$(shell git config --get remote.origin.url)
ifndef COMMIT
COMMIT := git-$(shell git rev-parse --short HEAD)
endif
.PHONY: all
all: build
.PHONY: build
build: clean test certs
@echo "+ $@"
@CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} 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 bin/${GOOS}-${GOARCH}/${APP} ${PROJECT}/cmd
docker build --pull -t $(CONTAINER_IMAGE):$(RELEASE) .
.PHONY: certs
certs:
ifeq ("$(wildcard $(CA_DIR)/ca-certificates.crt)","")
@echo "+ $@"
@docker run --name ${CONTAINER_NAME}-certs -d alpine:edge sh -c "apk --update upgrade && apk add ca-certificates && update-ca-certificates"
@docker wait ${CONTAINER_NAME}-certs
@mkdir -p ${CA_DIR}
@docker cp ${CONTAINER_NAME}-certs:/etc/ssl/certs/ca-certificates.crt ${CA_DIR}
@docker rm -f ${CONTAINER_NAME}-certs
endif
.PHONY: push
push: build
@echo "+ $@"
@docker push $(CONTAINER_IMAGE):$(RELEASE)
.PHONY: run
run: build
@echo "+ $@"
@docker run --name ${CONTAINER_NAME} -p ${K8SAPP_LOCAL_PORT}:${K8SAPP_LOCAL_PORT} \
-e "K8SAPP_LOCAL_HOST=${K8SAPP_LOCAL_HOST}" \
-e "K8SAPP_LOCAL_PORT=${K8SAPP_LOCAL_PORT}" \
-e "K8SAPP_LOG_LEVEL=${K8SAPP_LOG_LEVEL}" \
-d $(CONTAINER_IMAGE):$(RELEASE)
@sleep 1
@docker logs ${CONTAINER_NAME}
HAS_RUNNED := $(shell docker ps | grep ${CONTAINER_NAME})
HAS_EXITED := $(shell docker ps -a | grep ${CONTAINER_NAME})
.PHONY: logs
logs:
@echo "+ $@"
@docker logs ${CONTAINER_NAME}
.PHONY: stop
stop:
ifdef HAS_RUNNED
@echo "+ $@"
@docker stop ${CONTAINER_NAME}
endif
.PHONY: start
start: stop
@echo "+ $@"
@docker start ${CONTAINER_NAME}
.PHONY: rm
rm:
ifdef HAS_EXITED
@echo "+ $@"
@docker rm ${CONTAINER_NAME}
endif
.PHONY: deploy
deploy: push
helm upgrade ${CONTAINER_NAME} -f charts/${VALUES}.yaml charts \
--kube-context ${KUBE_CONTEXT} --namespace ${NAMESPACE} --version=${RELEASE} -i --wait \
--set image.registry=${REGISTRY} --set image.name=${CONTAINER_NAME} --set image.tag=${RELEASE}
.PHONY: fmt
fmt:
@echo "+ $@"
.PHONY: lint
lint: bootstrap
@echo "+ $@"
.PHONY: vet
vet:
@echo "+ $@"
@go vet ./...
.PHONY: test
test: clean fmt
@echo "+ $@"
@go test -v -race -tags "$(BUILDTAGS) cgo" ./...
.PHONY: clean
clean: stop rm
@rm -f bin/${GOOS}-${GOARCH}/${APP}
HAS_DEP := $(shell command -v dep;)
HAS_LINT := $(shell command -v golint;)
.PHONY: bootstrap
bootstrap:
ifndef HAS_DEP
go get -u github.com/golang/dep/cmd/dep
endif
ifndef HAS_LINT
go get -u github.com/golang/lint/golint
endif