-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
117 lines (97 loc) · 3.32 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
ROOT_DIR=$(shell pwd)
SPAWN_DIR=$(ROOT_DIR)/spawn
SPAWN_PROTO_DIR=$(SPAWN_DIR)/protos
SPAWN_PROTO_EXT_DIR=$(SPAWN_PROTO_DIR)/eigr/functions/protocol/actors
GOOGLE_API_DIR=$(SPAWN_PROTO_DIR)/google/api
GOOGLE_PROTOBUF_DIR=$(SPAWN_PROTO_DIR)/google/protobuf
GRPC_DIR=$(SPAWN_PROTO_DIR)/grpc/reflection/v1alpha
EXAMPLES_PROTO_DIR=$(ROOT_DIR)/examples/protos
SPAWN_PROTO_OUT_DIR=$(SPAWN_DIR)
EXAMPLES_PROTO_OUT_DIR=$(ROOT_DIR)/examples
IMAGE_NAME = eigr/spawn-example:latest
DOCKERFILE = Dockerfile
GO_CMD=go
GO_FLAGS=-v
GO_BUILD_FLAGS_DEBUG=-gcflags="all=-N -l"
# Diretório de saída para binários
BIN_DIR=./bin
EXAMPLES_BIN=$(BIN_DIR)/examples/app
EXAMPLES_DIR=./examples
PROTOC=protoc
PROTOC_GEN_GO=$(shell go env GOPATH)/bin/protoc-gen-go
# Auxiliary variables
SPAWN_PROTO_FILES=$(wildcard $(SPAWN_PROTO_EXT_DIR)/*.proto)
EXAMPLES_PROTO_FILES=$(wildcard $(EXAMPLES_PROTO_DIR)/*.proto)
# Check if the Protobuf plugin is installed
$(PROTOC_GEN_GO):
@echo "Instalando protoc-gen-go..."
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# Protobuf code generation for spawn
.PHONY: proto-spawn
proto-spawn: $(PROTOC_GEN_GO)
@echo "Generating Go code from spawn Protobuf files..."
@$(PROTOC) \
--proto_path=$(SPAWN_PROTO_DIR) \
--proto_path=$(GOOGLE_API_DIR) \
--proto_path=$(GOOGLE_PROTOBUF_DIR) \
--proto_path=$(GRPC_DIR) \
--go_out=$(SPAWN_PROTO_OUT_DIR) \
--go_opt=paths=source_relative \
$(SPAWN_PROTO_FILES)
# Protobuf code generation for examples
.PHONY: proto-examples
proto-examples: $(PROTOC_GEN_GO)
@echo "Generating Go code from the examples' Protobuf files..."
@$(PROTOC) \
--proto_path=$(EXAMPLES_PROTO_DIR) \
--proto_path=$(GOOGLE_API_DIR) \
--proto_path=$(GOOGLE_PROTOBUF_DIR) \
--go_out=$(EXAMPLES_PROTO_OUT_DIR) \
--go_opt=paths=source_relative \
$(EXAMPLES_PROTO_FILES)
# Protobuf code generation for the entire project
.PHONY: proto
proto: proto-spawn proto-examples
# Spawn directory setup
.PHONY: setup-spawn
setup-spawn:
@echo "Setting dependencies for the spawn directory..."
@cd spawn && go mod tidy
# Examples directory setup
.PHONY: setup-examples
setup-examples:
@echo "Setting dependencies for the examples directory..."
@cd examples && go mod tidy
# Complete project setup
.PHONY: setup
setup: setup-spawn setup-examples
# Cleaning up files generated at spawn
.PHONY: clean-spawn
clean-spawn:
@echo "Removing files generated by Protobuf on spawn..."
@rm -f $(SPAWN_PROTO_OUT_DIR)/*.pb.go
# Cleaning up files generated in the examples
.PHONY: clean-examples
clean-examples:
@echo "Removing Protobuf generated files in the examples..."
@rm -f $(EXAMPLES_PROTO_OUT_DIR)/*.pb.go
# Cleaning the entire project
.PHONY: clean
clean: clean-spawn clean-examples
# Bbuild for the examples directory in development mode (debug)
build-debug:
@echo "Compiling the examples directory in debug mode..."
$(GO_CMD) build $(GO_FLAGS) $(GO_BUILD_FLAGS_DEBUG) -o $(EXAMPLES_BIN) $(EXAMPLES_DIR)
@echo "Build de debug finalizado em $(EXAMPLES_BIN)"
# Standard task to compile the examples
build: build-debug
# Task to run the generated binary
run:
@echo "Running the example binary..."
$(EXAMPLES_BIN)
# Task to compile the Dockerfile and generate the final image
docker-build:
docker build -t $(IMAGE_NAME) -f $(DOCKERFILE) .
# Task to run the binary inside the container
docker-run:
docker run --rm $(IMAGE_NAME)