-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
177 lines (146 loc) · 4.9 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
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/caraml-dev/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 $(shell go env GOPATH)/bin/golangci-lint || \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/v1.58.1/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.1
.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 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: fmt
fmt:
@echo "Formatting code..."
@goimports -w -local github.com/caraml-dev/mlp $(shell find . -type f -name '*.go' -not -path "**/vendor/*")
@gofmt -s -w .
.PHONY: lint-api
lint-api: setup
@echo "Linting code..."
golangci-lint -v run --timeout 3m $(if $(filter true,$(fix)),--fix,) ${API_PATH}/...
# ============================================================
# 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
it-test-api: local-db start-keto start-vault
@echo "> API integration testing locally..."
@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
@make stop-docker
# ============================================================
# 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} main.go
.PHONY: build-api-image
build-api-image: version
@$(eval IMAGE_TAG = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)${BIN_NAME}-api:${VERSION})
@echo "Building docker image: ${IMAGE_TAG}"
docker build . \
--tag ${IMAGE_TAG} \
--file api.Dockerfile
.PHONY: build-image
build-image: version
@$(eval IMAGE_TAG = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)${BIN_NAME}:${VERSION})
@echo "Building docker image: ${IMAGE_TAG}"
docker build . \
--build-arg MLP_API_IMAGE \
--tag ${IMAGE_TAG} \
--file full.Dockerfile
# ============================================================
# Run recipes
# ============================================================
.PHONY: run
run: local-env
@echo "> Running application ..."
@go run api/main.go serve --config config-dev.yaml
.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 ..."
@docker run --rm -v $(shell pwd):/local swaggerapi/swagger-codegen-cli:2.4.14 generate \
-i /local/api/static/swagger.yaml \
-l go \
-o /local/api/client \
-DpackageName=client
$(MAKE) fmt
.PHONY: local-env
local-env: local-db start-keto start-vault
.PHONY: local-db
local-db:
@echo "> Starting up DB ..."
@docker compose up -d postgres
.PHONY: start-keto
start-keto:
@echo "> Starting up keto server ..."
@docker compose up -d keto
.PHONY: start-vault
start-vault:
@echo "> Starting up vault server ..."
@docker compose up -d vault
.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:
$(eval VERSION=$(if $(OVERWRITE_VERSION),$(OVERWRITE_VERSION),v$(shell ./scripts/vertagen/vertagen.sh)))
@echo "version:" $(VERSION)