forked from ranjith-ka/Devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
134 lines (105 loc) · 3.75 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
OS_NAME := $(shell uname -s | tr A-Z a-z)
TIMESTAMP ?= $$(date -u +'%Y%m%d%H%M%S')
PROTOCV := 3.11.4
# strip patch version number
PROTOCVMINOR ?= $(subst $(suffix $(PROTOCV)),,$(PROTOCV))
ifeq ($(findstring mingw64,$(OS_NAME)),mingw64)
PROTOZIP ?= protoc-$(PROTOCV)-win64.zip
PROTOLOC ?= /c/protoc
export PATH := $(PATH):/c/protoc/bin
endif
ifeq ($(findstring linux,$(OS_NAME)),linux)
PROTOZIP ?= protoc-$(PROTOCV)-linux-x86_64.zip
PROTOLOC ?= /usr/local
export PATH := $(PATH):/usr/local/bin
endif
ifeq ($(findstring darwin,$(OS_NAME)),darwin)
PROTOZIP ?= protoc-$(PROTOCV)-osx-x86_64.zip
PROTOLOC ?= $(HOME)/.protobuf
export PATH := $(PATH):$(HOME)/.protobuf/bin
endif
default: build
install: install-protoc
install-protoc:
@echo Installing protoc $(PROTOCV) binaries to $(PROTOLOC)
ifeq ($(findstring mingw64,$(OS_NAME)),mingw64)
@curl -sSLO https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOCV)/$(PROTOZIP)
@mkdir -p /c/protoc
@unzip -o $(PROTOZIP) -d $(PROTOLOC) bin/protoc* > /dev/null
@unzip -o $(PROTOZIP) -d $(PROTOLOC) include/* > /dev/null
@rm -f $(PROTOZIP)
@echo
@echo Please update your PATH to include $(PROTOLOC)/bin
endif
ifeq ($(findstring darwin,$(OS_NAME)),darwin)
@mkdir -p $(HOME)/.protobuf/bin
@cd $(HOME)/.protobuf
@curl -sSLO https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOCV)/$(PROTOZIP)
@unzip -o $(PROTOZIP) -d $(PROTOLOC) bin/protoc > /dev/null
@unzip -o $(PROTOZIP) -d $(PROTOLOC) include/* > /dev/null
@rm -f $(PROTOZIP)
endif
ifeq ($(findstring linux,$(OS_NAME)),linux)
@curl -sSLO https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOCV)/$(PROTOZIP)
@sudo unzip -o $(PROTOZIP) -d $(PROTOLOC) bin/protoc > /dev/null
@sudo unzip -o $(PROTOZIP) -d $(PROTOLOC) include/* > /dev/null
@rm -f $(PROTOZIP)
endif
download:
@echo Download go.mod dependencies
@go mod download
install-tools: download
@echo Installing tools from tools.go
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
build: generate compile
generate:
@echo Generate code
@go generate ./...
compile:
@echo Compile binary
@go build .
run: build
./Docker random
reports:
@mkdir -p reports
bench: reports
@echo Writing benchmark to reports/bench$(TIMESTAMP).txt
@go test -benchmem -run=^$$ <repo> -bench . > reports/bench$(TIMESTAMP).txt
coverage: reports
@go test -race -covermode=atomic -coverprofile=reports/coverage.out ./...
@go tool cover -func=reports/coverage.out
dirty:
ifneq ($(DIRTY),)
@echo modified/untracked files; echo $(DIRTY); exit 1
else
@echo 'clean'
endif
build-image:
@echo Build canary docker image
@docker build --build-arg APP="canary" -t ranjithka/canary:0.0.1 .
@echo Build production docker image
@docker build --build-arg APP="prd" -t ranjithka/prd:0.0.1 .
cluster: kind-cluster
kind-cluster:
@echo Creating Kind environment
@kind create cluster --config kind/config.yaml --name k8s-1.21.1
load-image:
@kind load docker-image ranjithka/canary:0.0.1 --name k8s-1.21.1
@kind load docker-image ranjithka/prd:0.0.1 --name k8s-1.21.1
ingress:
@helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
@echo Installing Ingress Helm Chart
@helm install -f minikube/nginx/values.yaml nginx ingress-nginx/ingress-nginx --version 4.0.13
install-app:
@helm install -f minikube/dev/canary.yaml canary-dev charts/dev
@helm install -f minikube/dev/prd.yaml prd-dev charts/dev
monitoring:
@helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
@helm install prometheus prometheus-community/prometheus
@helm repo add grafana https://grafana.github.io/helm-charts
@helm install grafana grafana/grafana
delete-app:
@helm delete prd-dev canary-dev
delete: delete-kind
delete-kind:
@kind delete cluster --name k8s-1.21.1