-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
181 lines (141 loc) · 4.98 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
###################### //S/M Makefile ######################
#
# This Makefile is used to manage the command-line template
# All possible tools have to reside under their respective folders in cmd/
# and are being autodetected.
# 'make full' would then process them all while 'make toolname' would only
# handle the specified one(s).
# Edit this file with care, as it is also being used by our CI/CD Pipeline
# For usage information check README.md
#
# Parts of this makefile are based upon github.com/kolide/kit
#
NAME := devhub
REPO := playnet-public
GIT_HOST := github.com
REGISTRY := quay.io
IMAGE := playnet/devhub
PATH := $(GOPATH)/bin:$(PATH)
VERSION := $(shell git describe --tags --always --dirty)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
REVISION := $(shell git rev-parse HEAD)
REVSHORT := $(shell git rev-parse --short HEAD)
USER := $(shell whoami)
STAGING ?= true
V ?= 0
NAMESPACE ?= $(NAME)-dev
DOCKER_CACHE ?= --no-cache
DOCKER_TAGS_FRONTEND := -t $(REGISTRY)/$(IMAGE)-frontend:$(VERSION) -t $(REGISTRY)/$(IMAGE)-frontend:latest
DOCKER_TAGS_BACKEND := -t $(REGISTRY)/$(IMAGE)-backend:$(VERSION) -t $(REGISTRY)/$(IMAGE)-backend:latest
-include .env
include helpers/make_version
.PHONY: build
### MAIN STEPS ###
all: test install run
# install required tools and dependencies
deps:
go get -u github.com/golang/dep/cmd/dep
go get -u github.com/golang/lint/golint
go get -u github.com/haya14busa/goverage
go get -u github.com/kisielk/errcheck
go get -u github.com/maxbrunsfeld/counterfeiter
go get -u github.com/onsi/ginkgo/ginkgo
go get -u github.com/onsi/gomega
go get -u github.com/schrej/godacov
go get -u golang.org/x/tools/cmd/goimports
updateDebugger:
wget -O files/go-cloud-debug https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug
chmod 0755 files/go-cloud-debug
# test entire repo
gotest:
@go test -cover -race $(shell go list ./... | grep -v /vendor/)
test:
@go get github.com/onsi/ginkgo/ginkgo
@ginkgo -r -race
# install passed in tool project
install:
GOBIN=$(GOPATH)/bin go install cmd/$(NAME)/*.go
# run tool
run:
$(NAME)
# format entire repo (excluding vendor)
format:
@go get golang.org/x/tools/cmd/goimports
@find . -type f -name '*.go' -not -path './vendor/*' -exec gofmt -w "{}" +
@find . -type f -name '*.go' -not -path './vendor/*' -exec goimports -w "{}" +
build: buildfrontend buildbackend
# build binary for docker image
buildgo: .pre-build
CGO_ENABLED=0 GOOS=linux go build -a -o app -ldflags ${KIT_VERSION} -gcflags='-N -l' ./cmd/$(NAME)
# build ui
buildui: .pre-build
npm run --prefix ui build --env=prod
buildfrontend: buildui
@docker build $(DOCKER_CACHE) --rm=true $(DOCKER_TAGS_FRONTEND) \
-f Dockerfile.frontend .
# build docker image
buildbackend:
gcloud debug source gen-repo-info-file --output-directory files
@docker build $(DOCKER_CACHE) --rm=true $(DOCKER_TAGS_BACKEND) \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_HOST=$(GIT_HOST) \
--build-arg REPO=$(REPO) \
--build-arg NAME=$(NAME) \
--build-arg COMMAND='buildgo' \
-f Dockerfile.backend .
# run specified tool from code
dev: generate
@go run -ldflags $(KIT_VERSION) cmd/$(NAME)/*.go \
-debug
# build the docker image
docker: build
# upload the docker image
upload: upload-frontend upload-backend
upload-frontend:
docker push $(REGISTRY)/$(IMAGE)-frontend
upload-backend:
docker push $(REGISTRY)/$(IMAGE)-backend
# clean build results and delete all images
clean:
rm -rf build
docker rmi -f $(shell docker images -q --filter=reference=$(REGISTRY)/$(IMAGE)*)
version:
@echo $(VERSION)
# create build dir
.pre-build:
@mkdir -p build
# helper to build new image and kick existing pod
update-deployment: docker upload clean restart-deployment
# delete existing pod to force imagePull (if latest)
restart-deployment:
kubectl delete po -n $(NAMESPACE) -lapp=$(NAME)
# helper to build new image and kick existing pod
update-backend: buildbackend upload-backend clean restart-backend
# delete existing pod to force imagePull (if latest)
restart-backend:
kubectl delete po -n $(NAMESPACE) -lapp=$(NAME) -lcomponent=api
# helper to build new image and kick existing pod
update-frontend: buildfrontend upload-frontend clean restart-frontend
# delete existing pod to force imagePull (if latest)
restart-frontend:
kubectl delete po -n $(NAMESPACE) -lapp=$(NAME) -lcomponent=frontend
# go quality checks
check: format lint vet
# vet entire repo (excluding vendor)
vet:
@go vet $(shell go list ./... | grep -v /vendor/)
# lint entire repo (excluding vendor)
lint:
@go get github.com/golang/lint/golint
@golint -min_confidence 1 $(shell go list ./... | grep -v /vendor/)
# errcheck entire repo (excluding vendor)
errcheck:
@go get github.com/kisielk/errcheck
@errcheck -ignore '(Close|Write)' $(shell go list ./... | grep -v /vendor/)
cover:
@go get github.com/haya14busa/goverage
@go get github.com/schrej/godacov
goverage -v -coverprofile=coverage.out $(shell go list ./... | grep -v /vendor/)
generate:
@go get github.com/maxbrunsfeld/counterfeiter
@go generate ./...