-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
92 lines (77 loc) · 2 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
# Variables
APP_SVR_NAME := agentServer
SRC_SVR_FILE := cmd/server/main.go
APP_AGENT_NAME := agent
SRC_AGENT_FILE := cmd/agent/main.go
OUTPUT_DIR := bin
OUTPUT_SVR_FILE := $(OUTPUT_DIR)/$(APP_SVR_NAME)
OUTPUT_AGENT_FILE := $(OUTPUT_DIR)/$(APP_AGENT_NAME)
GO := go
VERSION := v0.0.1
IMAGE_NAME := github-agent-server
# Default target
.PHONY: all
all: lint build
.PHONY: proto
proto:
protoc \
--proto_path=$(PROTO_DIR) \
--go_out=$(OUT_DIR) \
--go-grpc_out=$(OUT_DIR) \
$(PROTO_DIR)/*.proto
# Lint the Go source code
.PHONY: lint
lint:
@echo "Running linter on $(SRC_SVR_FILE)..."
@echo "Running linter on $(SRC_AGENT_FILE)..."
# Build the Go application
.PHONY: build
build:
@echo "Building $(SRC_SVR_FILE)..."
@mkdir -p $(OUTPUT_DIR)
$(GO) build -o $(OUTPUT_SVR_FILE) $(SRC_SVR_FILE)
@echo "Building $(SRC_AGENT_FILE)..."
$(GO) build -o $(OUTPUT_AGENT_FILE) $(SRC_AGENT_FILE)
@echo "Build complete: $(OUTPUT_AGENT_FILE)"
.PHONE: docker
docker:
docker build -t $(IMAGE_NAME):$(VERSION) .
docker save -o $(IMAGE_NAME):$(VERSION).linux-arm64.tar $(IMAGE_NAME):$(VERSION)
# Run the Go application
.PHONY: run
run: build
@echo "Running $(OUTPUT_SVR_FILE)..."
$(OUTPUT_SVR_FILE)
# Run Go tests
.PHONY: test
test:
@echo "Running tests..."
$(GO) test ./...
# Clean the build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf $(OUTPUT_DIR)
@echo "Clean complete."
# Format the code
.PHONY: fmt
fmt:
@echo "Formatting code..."
$(GO) fmt ./...
# Tidy the Go module dependencies
.PHONY: tidy
tidy:
@echo "Tidying Go modules..."
$(GO) mod tidy
# Help message
.PHONY: help
help:
@echo "Usage:"
@echo " make lint Run linter on the source code"
@echo " make build Build the application"
@echo " make run Run the application"
@echo " make test Run all tests"
@echo " make clean Remove build artifacts"
@echo " make fmt Format the Go source code"
@echo " make tidy Tidy up Go modules"
@echo " make help Show this help message"