-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
235 lines (203 loc) Β· 7.65 KB
/
Makefile
File metadata and controls
235 lines (203 loc) Β· 7.65 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Colog Makefile
# Build and release automation for Docker container log viewer
# Variables
APP_NAME := colog
VERSION := $(shell git describe --tags --always --dirty)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
# Build flags
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.Date=$(DATE)"
# Directories
BUILD_DIR := releases
DIST_DIR := dist
# Platforms
PLATFORMS := \
darwin/amd64 \
darwin/arm64 \
linux/amd64 \
linux/arm64 \
linux/386 \
windows/amd64 \
windows/386
.PHONY: all build clean test deps help install release compress checksums docker docker-mcp sdk-test mcp-test
# Default target
all: clean deps test build
# Help target
help:
@echo "Colog Build System"
@echo ""
@echo "Available targets:"
@echo " build - Build binary for current platform"
@echo " build-all - Build binaries for all platforms"
@echo " clean - Remove build artifacts"
@echo " test - Run tests"
@echo " deps - Download dependencies"
@echo " install - Install binary to GOPATH/bin"
@echo " release - Create GitHub release with all binaries"
@echo " compress - Compress all binaries"
@echo " checksums - Generate checksums for binaries"
@echo " docker - Build Docker image"
@echo " docker-mcp - Build MCP server Docker image"
@echo " sdk-test - Test SDK functionality"
@echo " mcp-test - Test MCP server functionality"
@echo " help - Show this help message"
@echo ""
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
# Download dependencies
deps:
@echo "π¦ Downloading dependencies..."
go mod download
go mod tidy
# Run tests
test:
@echo "π§ͺ Running tests..."
go test -v ./...
# Build for current platform
build: deps
@echo "π¨ Building $(APP_NAME) for current platform..."
go build $(LDFLAGS) -o $(APP_NAME) ./cmd/colog
# Build for all platforms
build-all: clean deps $(BUILD_DIR)
@echo "π¨ Building $(APP_NAME) for all platforms..."
@$(foreach platform,$(PLATFORMS), \
$(call build_platform,$(platform)) \
)
@echo "β
All builds completed"
# Build function for each platform
define build_platform
$(eval GOOS := $(word 1,$(subst /, ,$1)))
$(eval GOARCH := $(word 2,$(subst /, ,$1)))
$(eval EXT := $(if $(filter windows,$(GOOS)),.exe,))
$(eval OUTPUT := $(BUILD_DIR)/$(APP_NAME)-$(GOOS)-$(GOARCH)$(EXT))
@echo "Building $(OUTPUT)..."
@GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(LDFLAGS) -o $(OUTPUT) ./cmd/colog
endef
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Create distribution directory
$(DIST_DIR):
mkdir -p $(DIST_DIR)
# Compress binaries
compress: build-all $(DIST_DIR)
@echo "π¦ Compressing binaries..."
@for binary in $(BUILD_DIR)/*; do \
basename=$$(basename $$binary); \
if [[ $$basename == *".exe" ]]; then \
zip -j $(DIST_DIR)/$$basename.zip $$binary; \
else \
tar -czf $(DIST_DIR)/$$basename.tar.gz -C $(BUILD_DIR) $$basename; \
fi; \
echo "β
Compressed $$basename"; \
done
# Generate checksums
checksums: compress
@echo "π Generating checksums..."
@cd $(DIST_DIR) && sha256sum * > checksums.txt
@echo "β
Checksums generated in $(DIST_DIR)/checksums.txt"
# Clean build artifacts
clean:
@echo "π§Ή Cleaning build artifacts..."
rm -rf $(BUILD_DIR) $(DIST_DIR) $(APP_NAME)
# Install binary
install: build
@echo "π₯ Installing $(APP_NAME) to GOPATH/bin..."
go install $(LDFLAGS) ./cmd/colog
# Test SDK functionality
sdk-test: build
@echo "π§ͺ Testing SDK functionality..."
@echo "Testing SDK help..."
./$(APP_NAME) sdk --help
@echo ""
@echo "Testing SDK list command..."
./$(APP_NAME) sdk list --help
@echo ""
@echo "β
SDK tests passed"
# Test MCP server functionality
mcp-test:
@echo "π§ͺ Testing MCP server functionality..."
@if command -v curl >/dev/null 2>&1; then \
echo "Testing MCP server build..."; \
cd mcp && go build -o mcp-server server.go && echo "β
MCP server builds successfully"; \
echo "Testing MCP server start (quick test)..."; \
cd mcp && timeout 5s ./mcp-server || echo "β
MCP server starts successfully"; \
rm -f mcp/mcp-server; \
else \
echo "β οΈ curl not found, skipping HTTP tests"; \
fi
# Docker build
docker:
@echo "π³ Building Docker image..."
docker build -t $(APP_NAME):$(VERSION) .
docker build -t $(APP_NAME):latest .
@echo "β
Docker image built: $(APP_NAME):$(VERSION)"
# Docker build MCP server
docker-mcp:
@echo "π³ Building MCP Docker image..."
docker build -t $(APP_NAME)-mcp:$(VERSION) -f mcp/Dockerfile .
docker build -t $(APP_NAME)-mcp:latest -f mcp/Dockerfile .
@echo "β
MCP Docker image built: $(APP_NAME)-mcp:$(VERSION)"
# Quick release (build, compress, checksums)
quick-release: build-all compress checksums
@echo "π Quick release ready in $(DIST_DIR)/"
@ls -la $(DIST_DIR)/
# Full GitHub release
release: quick-release
@echo "π Creating GitHub release v$(VERSION)..."
@if command -v gh >/dev/null 2>&1; then \
gh release create v$(VERSION) \
--title "Colog v$(VERSION) - Docker Log Viewer with SDK" \
--notes "$$(cat <<'EOF'\n## π Colog v$(VERSION)\n\n### New in this release:\n- π§ **SDK Mode**: Programmatic access to Docker container logs\n- π€ **LLM Integration**: Export logs in JSON/Markdown for AI analysis\n- π **Batch Operations**: Process multiple containers simultaneously\n- π **Smart Filtering**: Filter containers by name, image, status, labels\n- π» **CLI Commands**: SDK subcommands for automation\n- π **Comprehensive Docs**: Complete SDK documentation and examples\n\n### SDK Usage:\n\`\`\`bash\n# List containers\ncolog sdk list\n\n# Export logs for LLM analysis\ncolog sdk export --format markdown\n\n# Filter and get logs\ncolog sdk filter --image nginx\n\`\`\`\n\n### Downloads:\nChoose the binary for your platform:\n- **macOS**: colog-darwin-amd64.tar.gz (Intel) or colog-darwin-arm64.tar.gz (Apple Silicon)\n- **Linux**: colog-linux-amd64.tar.gz (x64) or colog-linux-arm64.tar.gz (ARM64)\n- **Windows**: colog-windows-amd64.exe.zip\n\n### Installation:\n\`\`\`bash\n# macOS/Linux\ntar -xzf colog-*.tar.gz && sudo mv colog-* /usr/local/bin/colog\n\n# Or via Go\ngo install github.com/berkantay/colog@v$(VERSION)\n\`\`\`\n\nFull documentation: [SDK_README.md](https://github.com/berkantay/colog/blob/main/SDK_README.md)\nEOF\n)" \
$(DIST_DIR)/*; \
echo "β
GitHub release created successfully"; \
else \
echo "β GitHub CLI (gh) not found. Please install it or create the release manually."; \
echo "Upload these files to GitHub releases:"; \
ls -la $(DIST_DIR)/; \
fi
# Development targets
dev-build:
@echo "π οΈ Building development version..."
go build -race $(LDFLAGS) -o $(APP_NAME)-dev ./cmd/colog
dev-run: dev-build
@echo "π Running development version..."
./$(APP_NAME)-dev
# Lint code
lint:
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "π Linting code..."; \
golangci-lint run; \
else \
echo "β οΈ golangci-lint not found, using go vet"; \
go vet ./...; \
fi
# Format code
fmt:
@echo "π
Formatting code..."
go fmt ./...
# Update version and create tag
version:
@if [ -z "$(V)" ]; then \
echo "β Please specify version: make version V=1.3.0"; \
exit 1; \
fi
@echo "π·οΈ Creating version $(V)..."
git tag v$(V)
git push origin v$(V)
@echo "β
Version v$(V) created and pushed"
# Show build info
info:
@echo "Build Information:"
@echo " App Name: $(APP_NAME)"
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT)"
@echo " Date: $(DATE)"
@echo " Platforms: $(words $(PLATFORMS)) platforms"
@echo ""
@go version
# Benchmark
benchmark:
@echo "π Running benchmarks..."
go test -bench=. -benchmem ./...
.PHONY: dev-build dev-run lint fmt version info benchmark quick-release