generated from pieceowater-dev/lotof.sample.gtw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (71 loc) · 1.99 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
APP_NAME = lotof.hub.gtw
BUILD_DIR = bin
MAIN_FILE = cmd/server/main.go
PROTOC = protoc
PROTOC_GEN_GO = $(GOPATH)/bin/protoc-gen-go
PROTOC_GEN_GRPC_GO = $(GOPATH)/bin/protoc-gen-go-grpc
PROTOC_PKG = github.com/pieceowater-dev/lotof.hub.proto
PROTOC_PKG_PATH = $(shell go list -m -f '{{.Dir}}' $(PROTOC_PKG))
PROTOC_DIR = protos
PROTOC_OUT_DIR = ./internal/core/grpc/generated
GQLGEN = go run github.com/99designs/gqlgen
DOCKER_COMPOSE = docker-compose
.PHONY: all clean build run update grpc-gen grpc-clean grpc-update gql-gen gql-clean compose-up compose-down
# Setup the environment
setup: grpc-update
@echo "Setup completed!"; \
go mod tidy
# Default build target
all: build grpc-gen gql-gen
# Update dependencies
update:
go mod tidy
# Build the project
build:
@mkdir -p $(BUILD_DIR)
go build -o $(BUILD_DIR)/$(APP_NAME) $(MAIN_FILE)
# Run the application
run: build
./$(BUILD_DIR)/$(APP_NAME)
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR) gql-clean grpc-clean
# gRPC code generation
grpc-gen:
@echo "Generating gRPC code from proto files..."
mkdir -p $(PROTOC_OUT_DIR)
find $(PROTOC_PKG_PATH)/$(PROTOC_DIR) -name "*.proto" | xargs $(PROTOC) \
-I $(PROTOC_PKG_PATH)/$(PROTOC_DIR) \
--go_out=$(PROTOC_OUT_DIR) \
--go-grpc_out=$(PROTOC_OUT_DIR)
@echo "gRPC code generation completed!"
# Clean gRPC generated files
grpc-clean:
rm -rf $(PROTOC_OUT_DIR)
# Update gRPC dependencies
grpc-update:
go get -u $(PROTOC_PKG)@latest
# GQLGEN generation
gql-gen:
$(GQLGEN) generate
git add -A
# Clean GQLGEN generated files
gql-clean:
rm -rf internal/core/graph
# Docker build target
build-docker:
docker build -t $(APP_NAME) .
# Build Docker image and run the container
build-and-run-docker: build-docker
docker stop $(APP_NAME)
docker rm $(APP_NAME)
docker run -d -p 8080:8080 \
--network lotofsamplesvc_pieceonetwork \
--name $(APP_NAME) \
$(APP_NAME)
# Start Docker Compose services
compose-up:
$(DOCKER_COMPOSE) up -d
# Stop Docker Compose services
compose-down:
$(DOCKER_COMPOSE) down