forked from caraml-dev/mlp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
151 lines (123 loc) · 4.08 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
include .env.development
export
UI_PATH := ui
UI_BUILD_PATH := ${UI_PATH}/build
API_PATH := api
API_ALL_PACKAGES := $(shell cd ${API_PATH} && go list ./... | grep -v github.com/gojek/mlp/client | grep -v mocks)
BIN_NAME := $(if ${APP_NAME},${APP_NAME},mlp)
all: setup init-dep lint test clean build run
# ============================================================
# Initialize dependency recipes
# ============================================================
.PHONY: setup
setup:
@echo "> Setting up tools ..."
@test -x ${GOPATH}/bin/golint || go get -u golang.org/x/lint/golint
.PHONY: init-dep
init-dep: init-dep-ui init-dep-api
.PHONY: init-dep-ui
init-dep-ui:
@echo "> Initializing UI dependencies ..."
@cd ${UI_PATH} && yarn
.PHONY: init-dep-api
init-dep-api:
@echo "> Initializing API dependencies ..."
@cd ${API_PATH} && go mod tidy -v
@cd ${API_PATH} && go get -v ./...
# ============================================================
# Analyze source code recipes
# ============================================================
.PHONY: lint
lint: lint-ui lint-api
.PHONY: lint-ui
lint-ui:
@echo "> Linting the UI source code ..."
@cd ${UI_PATH} && yarn lint
.PHONY: lint-api
lint-api:
@echo "> Analyzing API source code..."
@cd ${API_PATH} && golint ${API_ALL_PACKAGES}
# ============================================================
# Testing recipes
# ============================================================
.PHONY: test
test: test-api
.PHONY: test-api
test-api: init-dep-api
@echo "> API unit testing ..."
@cd ${API_PATH} && go test -v -race -cover -coverprofile cover.out ${API_ALL_PACKAGES}
@cd ${API_PATH} && go tool cover -func cover.out
.PHONY: it-test-api-local
it-test-api-local: local-db start-keto
@echo "> API integration testing locally..."
@cd ${API_PATH} && go test -race -short -cover -coverprofile cover.out -tags integration_local ${API_ALL_PACKAGES}
@cd ${API_PATH} && go tool cover -func cover.out
.PHONY: it-test-api-ci
it-test-api-ci:
@echo "> API integration testing ..."
@cd ${API_PATH} && go test -race -short -cover -coverprofile cover.out -tags integration ${API_ALL_PACKAGES}
@cd ${API_PATH} && go tool cover -func cover.out
# ============================================================
# Building recipes
# ============================================================
.PHONY: build
build: build-ui build-api
.PHONY: build-ui
build-ui: clean-ui
@echo "> Building UI static build ..."
@cd ${UI_PATH} && yarn lib build && yarn app build
.PHONY: build-api
build-api: clean-bin
@echo "> Building API binary ..."
@cd ${API_PATH} && go build -o ../bin/${BIN_NAME} ./cmd/main.go
.PHONY: build-docker
build-docker:
@echo "> Building docker image ..."
@docker build --tag gojektech/mlp:dev .
# ============================================================
# Run recipes
# ============================================================
.PHONY: run
run: build-api local-db
@echo "> Running application ..."
@./bin/${BIN_NAME}
.PHONY: start-ui
start-ui:
@echo "> Starting UI app ..."
@cd ${UI_PATH} && yarn start
# ============================================================
# Utility recipes
# ============================================================
.PHONY: clean
clean: clean-ui clean-bin
.PHONY: clean-ui
clean-ui:
@echo "> Cleaning up existing UI static build ..."
@test ! -e ${UI_BUILD_PATH} || rm -r ${UI_BUILD_PATH}
.PHONY: clean-bin
clean-bin:
@echo "> Cleaning up existing compiled binary ..."
@test ! -e bin || rm -r bin
generate-client:
@echo "> Generating API client ..."
@swagger-codegen generate -i static/swagger.yaml -l go -o client -DpackageName=client
@goimports -l -w client
.PHONY: local-db
local-db:
@echo "> Starting up DB ..."
@docker-compose up -d postgres && docker-compose run migrations
.PHONY: start-keto
start-keto:
@echo "> Starting up keto server ..."
@docker-compose up -d keto
.PHONY: stop-docker
stop-docker:
@echo "> Stopping Docker compose ..."
@docker-compose down
.PHONY: swagger-ui
swagger-ui:
@echo "> Starting up Swagger UI ..."
@docker-compose up -d swagger-ui
.PHONY: version
version:
@./scripts/vertagen/vertagen.sh -f docker