-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (104 loc) · 3.45 KB
/
Makefile
File metadata and controls
135 lines (104 loc) · 3.45 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
# Makefile for Sentinel
.PHONY: build clean test run docker-build docker-run dev deps lint format help proto
# Variables
BINARY_NAME=sentinel
MAIN_PATH=./cmd/sentinel
BUILD_DIR=./build
VERSION?=dev
LDFLAGS=-ldflags="-w -s -X main.version=${VERSION}"
# Default target
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Development
dev: ## Run in development mode with auto-reload
go run $(MAIN_PATH) start
run: build ## Build and run the application
./$(BUILD_DIR)/$(BINARY_NAME)
runtcpserver:
go run ./cmd/tcpserver
rungrpcserver:
go run ./cmd/grpcserver
front:
cd frontend && pnpm dev
# Build targets
build: deps ## Build the application
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
build-linux: deps ## Build for Linux
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux $(MAIN_PATH)
build-all: deps ## Build for all platforms
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
# Dependencies
deps: ## Download dependencies
go mod download
go mod tidy
# Testing
test: ## Run tests
go test -v ./...
test-api:
@echo "Running Sentinel API Integration Tests..."
go run ./cmd/testapi test
test-coverage: ## Run tests with coverage
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Code quality
lint: ## Run linter
golangci-lint run
format: ## Format code
go fmt ./...
goimports -w .
docker-push: ## Build and push Docker image
docker buildx build --platform linux/amd64 --push \
--build-arg VERSION=`git describe --tags --abbrev=0 || echo "0.0.0"` \
--build-arg COMMIT=`git rev-parse --short HEAD` \
--build-arg DATE=`date -u +'%Y-%m-%dT%H:%M:%SZ'` \
-t sxwebdev/sentinel:latest .
docker-run: ## Run Docker container
docker run -d \
--name sentinel \
-p 8080:8080 \
-v $(PWD)/data:/root/data \
-v $(PWD)/config.yaml:/root/config.yaml \
sxwebdev/sentinel:latest
docker-stop: ## Stop Docker container
docker stop sentinel || true
docker rm sentinel || true
deocker-dev:
docker compose -f docker-compose.local.yml up -d
# Docker Compose
up: ## Start with docker-compose
docker-compose up -d
down: ## Stop docker-compose
docker-compose down
logs: ## Show docker-compose logs
docker-compose logs -f
# Installation
install: build ## Install binary to system
sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
# Cleanup
clean: ## Clean build artifacts
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
docker-compose down --volumes --remove-orphans || true
# Database
init-db: ## Initialize database directory
mkdir -p data
# Configuration
init-config: ## Copy example configuration
cp config.yaml.example config.yaml || echo "config.yaml already exists"
cp .env.example .env || echo ".env already exists"
# Release
release: clean build-all test ## Create release build
@echo "Release $(VERSION) built successfully"
@ls -la $(BUILD_DIR)/
genswagger:
rm -rf ./docs/*
swag fmt -d ./internal/web
swag init -o docs/docsv1 --dir ./internal/web -g handlers.go --parseDependency