-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (104 loc) · 4.21 KB
/
Makefile
File metadata and controls
141 lines (104 loc) · 4.21 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
129
130
131
132
133
134
135
136
137
138
139
SHELL := /bin/bash
########################
# Docker configuration #
########################
# Default config args
ENV?=.env
# Default Docker args
DOCKER_HUB?=protomicro
DOCKER_TAG?=make
DOCKER_APP_NAME=microshop
# Config imports
-include $(ENV)
ifndef DOCKER_APP_NAME
$(error DOCKER_APP_NAME is not set)
endif
DOCKER_IMAGE=$(DOCKER_HUB)/$(DOCKER_APP_NAME)
.PHONY: help
help: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/##//'
.DEFAULT_GOAL := up
APP = microshop
SERVER_BIN = ./cmd/${APP}/${APP}
# Docker run
build: ## Build the container
docker build -t $(DOCKER_IMAGE) .
build-nc: ## Bulid the container without cache
docker build --no-cache -t $(DOCKER_IMAGE) .
start:
go run ./cmd/microshop/main.go start
wire: ## Run the container
wire ./internal/app/injector ./internal/app/test/mock/model ./internal/app/test/mock/service
run: ## Run the container
docker run \
-d \
--env-file $(ENV) \
-p $(PORT):$(PORT) \
--name="$(DOCKER_APP_NAME)" \
$(DOCKER_IMAGE)
stop: ## Stop the container and remove
docker stop $(DOCKER_APP_NAME) || true && docker rm $(DOCKER_APP_NAME) || true
up: build stop run ## Build the container and run it
# Docker tagging
tag-release: tag-latest tag-version ## Generate release tags
tag-latest: check-build-existence ## Generate the latest tag
@echo 'Tagging `latest`'
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):latest
tag-version: check-build-existence ## Generate a `{DOCKER_TAG}` tag
@echo 'Tagging `${DOCKER_TAG}`'
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG)
# Docker publishing
publish-release: build publish-latest publish-version ## Publish the release tags
publish-latest: tag-latest ## Publish the latest tag
@echo 'Publishing `latest` to `$(DOCKER_IMAGE)`'
docker push $(DOCKER_IMAGE):latest
publish-version: tag-version ## Publish the `{DOCKER_TAG}` tag
@echo 'Publishing `$(DOCKER_TAG)` to `$(DOCKER_IMAGE)`'
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
check-build-existence: ## Check docker existence
if [ "$(shell docker images -q $(DOCKER_IMAGE) 2> /dev/null)" == "" ]; then\
make build;\
fi
########
# gRPC #
########
API_PROTO_FILES ?= $(shell find $(PWD)/api -type f -path '*.proto')
PKG_PROTO_FILES ?= $(shell find $(PWD)/pkg -type f -path '*.proto')
OTR_PROTO_FILES ?= $(shell find $(PWD) -type f -path '*.proto' | grep -v "vendor\|pkg\|api")
PROTO_PB_FILES ?= $(shell find $(PWD) -type f -path '*.pb.go' | grep -v "vendor")
PROTOC_INJECTOR := ${GOPATH}/bin/protoc-go-inject-tag
PROTOC := ${GOPATH}/bin/protoc
PROTO_PATH = $(PWD)
GENSERVICEPROTO=sh -c '$(PROTOC) \
-I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway \
-I ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate \
-I ${PROTO_PATH} \
--proto_path=$$0 \
--grpc-gateway_out=logtostderr=true:$$1 \
--go_out=$$1 \
--go-grpc_out=require_unimplemented_servers=false:$$1 \
--validate_out=lang=go:$$1 \
--openapiv2_out $$0 --openapiv2_opt logtostderr=true $$2'
GENPROTO=sh -c '$(PROTOC) \
-I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway \
-I ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate \
-I ${PROTO_PATH} \
--proto_path=$$0 \
--grpc-gateway_out=paths=source_relative,logtostderr=true:$$1 \
--go_out=paths=source_relative:$$1 \
--go-grpc_out=paths=source_relative,require_unimplemented_servers=false:$$1 \
--validate_out=paths=source_relative,lang=go:$$1 \
--openapiv2_out $$1 --openapiv2_opt logtostderr=true $$2'
protos: # generate protobuf files
for file in $(shell find ${PKG_PROTO_FILES} -type f -path '*.proto'); \
do $(GENPROTO) ${PROTO_PATH} ${PROTO_PATH} "$${file}"; done
for file in $(shell find $(API_PROTO_FILES) -type f -path '*.proto'); \
do $(GENSERVICEPROTO) ${PROTO_PATH} $(PROTO_PATH)/internal/app "$${file}"; done
#${GENPROTO} ${PROTO_PATH} ${PROTO_PATH} ${OTR_PROTO_FILES}
#$(GENPROTO) ${PROTO_PATH} $(PROTO_PATH)/api $(API_PROTO_FILES)
#${GENPROTO} ${PROTO_PATH} ${PROTO_PATH} ${PKG_PROTO_FILES}
#$(PROTOC_INJECTOR) -input="${PROTO_PB_FILES}" -verbose=false
faker: # add faker tag to proto files
$(PROTOC_INJECTOR) -input="${PROTO_PB_FILES}" -verbose=false