-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
96 lines (78 loc) · 3.68 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
# Makefile for CM-Beetle in Cloud-Barista.
MODULE_NAME := cm-beetle
PROJECT_NAME := github.com/cloud-barista/$(MODULE_NAME)
PKG_LIST := $(shell go list $(PROJECT_NAME)/... 2>&1)
GOPROXY_OPTION := GOPROXY=direct # default: GOPROXY=https://proxy.golang.org,direct
GO := $(GOPROXY_OPTION) go
GOPATH := $(shell go env GOPATH)
SWAG := ~/go/bin/swag
.PHONY: all dependency lint update swag swagger build arm prod run stop clean help
all: swag build ## Default target: build the project
dependency: ## Get dependencies
@echo "Checking dependencies..."
@$(GO) mod tidy
@echo "Checked!"
lint: dependency ## Lint the files
@echo "Running linter..."
@if [ ! -f "$(GOPATH)/bin/golangci-lint" ] && [ ! -f "$(shell go env GOROOT)/bin/golangci-lint" ]; then \
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.2; \
fi
@golangci-lint run -E contextcheck -D unused
@echo "Linter finished!"
update: ## Update all module dependencies
@echo "Updating dependencies..."
@cd cmd/$(MODULE_NAME) && $(GO) get -u
@echo "Checking dependencies..."
@$(GO) mod tidy
@echo "Updated!"
swag swagger: ## Generate Swagger API documentation
@echo "Generating Swagger API documentation..."
@ln -sf cmd/$(MODULE_NAME)/main.go ./main.go
@$(SWAG) i --parseDependency --generalInfo ./main.go --dir ./ --output ./api
@rm ./main.go
@echo "Generated Swagger API documentation!"
# build: lint swag ## Build the binary file for amd64
build: ## Build the binary file for amd64
@echo "Building the binary for amd64..."
@cd cmd/$(MODULE_NAME) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o $(MODULE_NAME) main.go
@echo "Build finished!"
# arm: lint swag ## Build the binary file for ARM
arm: ## Build the binary file for ARM
@echo "Building the binary for ARM..."
@cd cmd/$(MODULE_NAME) && CGO_ENABLED=0 GOOS=linux GOARCH=arm $(GO) build -o $(MODULE_NAME)-arm main.go
@echo "Build finished!"
# prod: lint swag ## Build the binary file for production
prod: ## Build the binary file for production
@echo "Building the binary for amd64 production..."
# Note - Using cgo write normal Go code that imports a pseudo-package "C". I may not need on cross-compiling.
# Note - You can find possible platforms by 'go tool dist list' for GOOS and GOARCH
# Note - Using the -ldflags parameter can help set variable values at compile time.
# Note - Using the -s and -w linker flags can strip the debugging information.
@cd cmd/$(MODULE_NAME) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -ldflags '-s -w' -tags $(MODULE_NAME) -v -o $(MODULE_NAME) main.go
@echo "Build finished!"
run: build ## Run the built binary
@echo "Running the binary..."
@source conf/setup.env; \
cd cmd/$(MODULE_NAME) && \
(./$(MODULE_NAME) || { echo "Trying with sudo..."; sudo ./$(MODULE_NAME); })
stop: ## Stop the built binary
@echo "Stopping the binary..."
@sudo killall $(MODULE_NAME) 2>/dev/null || true
@echo "Stopped!"
clean: ## Remove previous build
@echo "Cleaning build..."
@rm -f coverage.out
@rm -f api/docs.go api/swagger.*
@cd cmd/$(MODULE_NAME) && $(GO) clean
@echo "Cleaned!"
compose: swag ## Build and up services by docker compose
@echo "Building and starting services by docker compose..."
@cd deployments/docker-compose && DOCKER_BUILDKIT=1 docker compose up --build
compose-up: ## Up services by docker compose
@echo "Starting services by docker compose..."
@cd deployments/docker-compose && docker compose up
compose-down: ## Down services by docker compose
@echo "Removing services by docker compose..."
@cd deployments/docker-compose && docker compose down
help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'