-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
154 lines (123 loc) · 3.82 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright 2017 Kubernetes Community Authors. All rights reserved.
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
APP=codegen
PROJECT=github.com/k8s-community/${APP}
REGISTRY?=registry.k8s.community
CA_DIR?=certs
# Use the 0.0.0 tag for testing, it shouldn't clobber any release builds
RELEASE?=0.0.3
GOOS?=linux
GOARCH?=amd64
CODEGEN_LOCAL_HOST?=0.0.0.0
CODEGEN_LOCAL_PORT?=8080
CODEGEN_LOG_LEVEL?=0
# Namespace: dev, prod, release, app, username ...
NAMESPACE?=k8s-community
# Infrastructure: dev, stable, test ...
INFRASTRUCTURE?=community
KUBE_CONTEXT?=${INFRASTRUCTURE}
VALUES?=values-${INFRASTRUCTURE}
CONTAINER_IMAGE?=${REGISTRY}/${NAMESPACE}/${APP}
CONTAINER_NAME?=${APP}-${NAMESPACE}
REPO_INFO=$(shell git config --get remote.origin.url)
ifndef COMMIT
COMMIT := git-$(shell git rev-parse --short HEAD)
endif
BUILDTAGS=
.PHONY: all
all: build
.PHONY: vendor
vendor: clean bootstrap
dep ensure
.PHONY: build
build: vendor test certs
@echo "+ $@"
@CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -a -installsuffix cgo \
-ldflags "-s -w -X ${PROJECT}/pkg/version.RELEASE=${RELEASE} -X ${PROJECT}/pkg/version.COMMIT=${COMMIT} -X ${PROJECT}/pkg/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 ${CODEGEN_LOCAL_PORT}:${CODEGEN_LOCAL_PORT} \
-e "CODEGEN_LOCAL_HOST=${CODEGEN_LOCAL_HOST}" \
-e "CODEGEN_LOCAL_PORT=${CODEGEN_LOCAL_PORT}" \
-e "CODEGEN_LOG_LEVEL=${CODEGEN_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
GO_LIST_FILES=$(shell go list ${PROJECT}/... | grep -v vendor)
.PHONY: fmt
fmt:
@echo "+ $@"
@go list -f '{{if len .TestGoFiles}}"gofmt -s -l {{.Dir}}"{{end}}' ${GO_LIST_FILES} | xargs -L 1 sh -c
.PHONY: lint
lint: bootstrap
@echo "+ $@"
@go list -f '{{if len .TestGoFiles}}"golint -min_confidence=0.85 {{.Dir}}/..."{{end}}' ${GO_LIST_FILES} | xargs -L 1 sh -c
.PHONY: vet
vet:
@echo "+ $@"
@go vet ${GO_LIST_FILES}
.PHONY: test
test: vendor fmt lint vet
@echo "+ $@"
@go test -v -race -cover -tags "$(BUILDTAGS) cgo" ${GO_LIST_FILES}
.PHONY: cover
cover:
@echo "+ $@"
@> coverage.txt
@go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}} && cat {{.Dir}}/.coverprofile >> coverage.txt"{{end}}' ${GO_LIST_FILES} | xargs -L 1 sh -c
.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