-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
128 lines (103 loc) · 2.87 KB
/
Makefile
File metadata and controls
128 lines (103 loc) · 2.87 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
117
118
119
120
121
122
123
124
125
126
127
128
GO111MODULES :=on
APP :=summer
REGISTRY? :=gcr.io/images
COMMIT_SHA :=$(shell git rev-parse --short HEAD)
CMD_DIR :=cmd
BIN_DIR :=bin
REGISTRY :=sekulicd/summer_repo
ENV :=dev
TAG :=latest
GRPC_CLIENT_DIR :=summer-cli
GRPC_SERVER_DIR :=summer-server
#### CONTINUOUS INTEGRATION ###
#ci: clean vet build test cov
ci: clean vet build test cov
#cd
cd: docker-login docker-build docker-tag docker-push
.PHONY: clean
## clean: cleans the binary
clean:
@echo "Cleaning..."
@go clean
.PHONY: vet
## vet: code analysis
vet:
@echo "Vet..."
@go vet ./...
.PHONY: build
## build: build the application
build:
@echo "Building..."
CGO_ENABLED=0 GOOS=linux go build -o ${BIN_DIR}/${GRPC_CLIENT_DIR} $(CMD_DIR)/${GRPC_CLIENT_DIR}/main.go
CGO_ENABLED=0 GOOS=linux go build -o ${BIN_DIR}/${GRPC_SERVER_DIR} $(CMD_DIR)/${GRPC_SERVER_DIR}/main.go
.PHONY: test
## test: runs go test with default values
test:
@echo "Testing..."
go test -v -count=1 -race ./...
.PHONY: cov
## cov: generates coverage report
cov:
@echo "Coverage..."
go test -cover ./...
#### CONTINUOUS DELIVERY/DEPLOYMENT ###
.PHONY: docker-login
## docker-build: builds the summer docker image to registry
docker-login:
docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD}
.PHONY: docker-build
## docker-build: builds the summer docker image to registry
docker-build:
docker build -t ${APP} .
.PHONY: docker-tag
## docker-tag: run the summer docker container
docker-tag:
docker tag ${APP} ${REGISTRY}/${TAG}
.PHONY: docker-push
## docker-push: pushes the summer docker image to registry
docker-push: check-environment docker-tag
docker push ${REGISTRY}:${TAG}
#### LOCAL DEV
.PHONY: build-local
## build: build the application
build-local:
@echo "Building..."
go build -o ${BIN_DIR}/${GRPC_CLIENT_DIR} $(CMD_DIR)/${GRPC_CLIENT_DIR}/main.go
go build -o ${BIN_DIR}/${GRPC_SERVER_DIR} $(CMD_DIR)/${GRPC_SERVER_DIR}/main.go
.PHONY: install
## install-local: install CLI
install:
@echo "Installing..."
go install ./${CMD_DIR}/${GRPC_CLIENT_DIR}
.PHONY: run-server
## run: runs go run main.go
run-server:
go run -race $(CMD_DIR)/${GRPC_SERVER_DIR}/main.go
.PHONY: setup
## setup: setup go modules
setup:
@go mod init \
&& go mod tidy \
&& go mod vendor
.PHONY: download
## setup: download go modules
download:
@go mod download
.PHONY: grpc-gen
## grpc-gen: generate pb.gp
grpc-gen:
@protoc --go_out=plugins=grpc:. ./pkg/grpc-schema/summer.proto
# helper rule for deployment
check-environment:
ifndef ENV
$(error ENV not set, allowed values - `staging` or `production`)
endif
.PHONY: docker-run
## docker-run: run the summer docker container
docker-run: docker-build
docker run -p8080:3000 -d ${APP}
.PHONY: help
## help: Prints this help message
help:
@echo "Usage: \n"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'