Agent Package (internal/agent/): - Agent struct with all collectors and memory-efficient pooling - Run loop with configurable collection interval - Graceful shutdown with context cancellation - Auto-reconnection callback for re-registration gRPC Client (internal/agent/client.go): - mTLS support with CA, agent cert, and key - Bidirectional streaming for metrics - Heartbeat fallback when streaming fails - Exponential backoff with jitter for reconnection - Concurrent reconnection handling with mutex Protocol Buffers (proto/tyto.proto): - AgentService with Stream, Register, Heartbeat RPCs - MetricsReport with summary fields for aggregation - ConfigUpdate and Command messages for server control - RegisterStatus enum for registration workflow CLI Integration (cmd/tyto/main.go): - Full agent subcommand with flag parsing - Support for --id, --server, --interval, --ca-cert, etc. - Environment variable overrides (TYTO_AGENT_*) - Signal handling for graceful shutdown Build System (Makefile): - Cross-compilation for linux/amd64, arm64, armv7 - Stripped binaries with version info - Proto generation target - Test and coverage targets Config Updates: - DefaultConfig() and LoadFromPath() functions - Agent config properly parsed from YAML 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
150 lines
4.1 KiB
Makefile
150 lines
4.1 KiB
Makefile
# Tyto Backend Makefile
|
|
# Supports cross-compilation for multiple architectures
|
|
|
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
|
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
LDFLAGS := -ldflags="-s -w -X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
|
|
|
|
# Output directories
|
|
BUILD_DIR := build
|
|
PROTO_DIR := proto
|
|
|
|
# Default target
|
|
.PHONY: all
|
|
all: build
|
|
|
|
# Build for current platform
|
|
.PHONY: build
|
|
build:
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto ./cmd/tyto
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/server ./cmd/server
|
|
|
|
# Build server binary only
|
|
.PHONY: server
|
|
server:
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/server ./cmd/server
|
|
|
|
# Build tyto CLI (includes agent)
|
|
.PHONY: tyto
|
|
tyto:
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto ./cmd/tyto
|
|
|
|
# Build lightweight agent for Linux amd64
|
|
.PHONY: agent-linux-amd64
|
|
agent-linux-amd64:
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-agent-linux-amd64 ./cmd/tyto
|
|
|
|
# Build lightweight agent for Linux arm64
|
|
.PHONY: agent-linux-arm64
|
|
agent-linux-arm64:
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-agent-linux-arm64 ./cmd/tyto
|
|
|
|
# Build lightweight agent for Linux arm (32-bit, e.g., Raspberry Pi)
|
|
.PHONY: agent-linux-arm
|
|
agent-linux-arm:
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-agent-linux-armv7 ./cmd/tyto
|
|
|
|
# Build all agent variants
|
|
.PHONY: agents
|
|
agents: agent-linux-amd64 agent-linux-arm64 agent-linux-arm
|
|
|
|
# Build all binaries for all platforms
|
|
.PHONY: release
|
|
release: clean
|
|
@mkdir -p $(BUILD_DIR)
|
|
# Linux amd64
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-linux-amd64 ./cmd/tyto
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-server-linux-amd64 ./cmd/server
|
|
# Linux arm64
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-linux-arm64 ./cmd/tyto
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-server-linux-arm64 ./cmd/server
|
|
# Linux arm (32-bit)
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 \
|
|
go build $(LDFLAGS) -o $(BUILD_DIR)/tyto-linux-armv7 ./cmd/tyto
|
|
|
|
# Generate protobuf code
|
|
.PHONY: proto
|
|
proto:
|
|
protoc --go_out=. --go-grpc_out=. $(PROTO_DIR)/tyto.proto
|
|
|
|
# Run tests
|
|
.PHONY: test
|
|
test:
|
|
go test -v -race ./...
|
|
|
|
# Run tests with coverage
|
|
.PHONY: test-coverage
|
|
test-coverage:
|
|
go test -v -race -coverprofile=coverage.out ./...
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
|
|
# Lint code
|
|
.PHONY: lint
|
|
lint:
|
|
golangci-lint run ./...
|
|
|
|
# Format code
|
|
.PHONY: fmt
|
|
fmt:
|
|
go fmt ./...
|
|
goimports -w .
|
|
|
|
# Clean build artifacts
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|
|
rm -f coverage.out coverage.html
|
|
|
|
# Install dependencies
|
|
.PHONY: deps
|
|
deps:
|
|
go mod download
|
|
go mod tidy
|
|
|
|
# Show binary sizes
|
|
.PHONY: sizes
|
|
sizes: agents
|
|
@echo "Binary sizes:"
|
|
@ls -lh $(BUILD_DIR)/tyto-agent-* 2>/dev/null | awk '{print $$5, $$9}'
|
|
|
|
# Docker build
|
|
.PHONY: docker
|
|
docker:
|
|
docker build -t tyto-backend:latest .
|
|
|
|
# Help
|
|
.PHONY: help
|
|
help:
|
|
@echo "Tyto Backend Makefile"
|
|
@echo ""
|
|
@echo "Usage: make [target]"
|
|
@echo ""
|
|
@echo "Targets:"
|
|
@echo " build Build for current platform"
|
|
@echo " server Build server binary only"
|
|
@echo " tyto Build tyto CLI (includes agent)"
|
|
@echo " agents Build agent for all Linux architectures"
|
|
@echo " release Build all binaries for all platforms"
|
|
@echo " proto Generate protobuf code"
|
|
@echo " test Run tests"
|
|
@echo " test-coverage Run tests with coverage report"
|
|
@echo " lint Run linter"
|
|
@echo " fmt Format code"
|
|
@echo " clean Remove build artifacts"
|
|
@echo " deps Download and tidy dependencies"
|
|
@echo " sizes Show agent binary sizes"
|
|
@echo " docker Build Docker image"
|
|
@echo " help Show this help"
|
|
@echo ""
|
|
@echo "Agent targets:"
|
|
@echo " agent-linux-amd64 Build agent for Linux x86_64"
|
|
@echo " agent-linux-arm64 Build agent for Linux ARM64 (aarch64)"
|
|
@echo " agent-linux-arm Build agent for Linux ARM32 (armv7)"
|