-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (91 loc) · 2.76 KB
/
Makefile
File metadata and controls
116 lines (91 loc) · 2.76 KB
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
all: push
BUILDTAGS=
APP?=user-manager
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.6.1
GOOS?=linux
GOARCH?=amd64
USERMAN_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: vendor
vendor: clean bootstrap
# todo!
# dep ensure
.PHONY: build
build: vendor
@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}
.PHONY: container
container: build certs
@echo "+ $@"
@docker build --pull -t $(CONTAINER_IMAGE):$(RELEASE) .
.PHONY: push
push: container
@echo "+ $@"
@docker push $(CONTAINER_IMAGE):$(RELEASE)
.PHONY: certs
certs:
ifeq ("$(wildcard $(CA_DIR)/ca-certificates.crt)","")
@echo "+ $@"
@docker run --name ${CONTAINER_NAME}-certs -d alpine:latest sh -c "apk --update upgrade && apk add ca-certificates && update-ca-certificates"
@docker wait ${CONTAINER_NAME}-certs
@docker cp ${CONTAINER_NAME}-certs:/etc/ssl/certs/ca-certificates.crt ${CA_DIR}
@docker rm -f ${CONTAINER_NAME}-certs
endif
.PHONY: container
run: container
@echo "+ $@"
@docker run --name ${CONTAINER_NAME} -p ${GITHUBINT_LOCAL_PORT}:${GITHUBINT_LOCAL_PORT} \
-e "GITHUBINT_LOCAL_PORT=${GITHUBINT_LOCAL_PORT}" \
-d $(CONTAINER_IMAGE):$(RELEASE)
@sleep 1
@docker logs ${CONTAINER_NAME}
.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 "+ $@"
@go fmt ./...
.PHONY: lint
lint: bootstrap
@echo "+ $@"
.PHONY: vet
vet:
@echo "+ $@"
@go vet $(shell go list ${PROJECT}/... | grep -v vendor)
.PHONY: test
test: vendor fmt lint vet
@echo "+ $@"
@go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PROJECT}/... | grep -v vendor)
.PHONY: cover
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
.PHONY: clean
clean:
rm -f ${APP}
HAS_DEP := $(shell command -v dep;)
.PHONY: bootstrap
bootstrap:
ifndef HAS_DEP
go get -u github.com/golang/dep/cmd/dep
endif