Files
BACKBEAT/Makefile
2025-10-17 08:56:25 +11:00

168 lines
5.3 KiB
Makefile

# BACKBEAT prototype Makefile
# Provides development and deployment workflows for the BACKBEAT system
# Variables
PROJECT_NAME = backbeat
DOCKER_REGISTRY = registry.home.deepblack.cloud
VERSION ?= v1.0.6
CLUSTER_NAME ?= chorus-dev
# Go build variables
GOOS ?= linux
GOARCH ?= amd64
CGO_ENABLED ?= 0
# Build flags
LDFLAGS = -w -s -X main.version=$(VERSION)
BUILD_FLAGS = -a -installsuffix cgo -ldflags "$(LDFLAGS)"
.PHONY: all build test clean docker docker-push run-dev stop-dev logs fmt vet deps help
# Default target
all: build
# Help target
help:
@echo "BACKBEAT prototype Makefile"
@echo ""
@echo "Available targets:"
@echo " build - Build all Go binaries"
@echo " test - Run all tests"
@echo " clean - Clean build artifacts"
@echo " docker - Build all Docker images"
@echo " docker-push - Push Docker images to registry"
@echo " run-dev - Start development environment with docker-compose"
@echo " stop-dev - Stop development environment"
@echo " logs - Show logs from development environment"
@echo " fmt - Format Go code"
@echo " vet - Run Go vet"
@echo " deps - Download Go dependencies"
@echo ""
@echo "Environment variables:"
@echo " VERSION - Version tag for builds (default: v1.0.0)"
@echo " CLUSTER_NAME - Cluster name for development (default: chorus-dev)"
# Build all binaries
build:
@echo "Building BACKBEAT binaries..."
@mkdir -p bin/
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -o bin/pulse ./cmd/pulse
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -o bin/reverb ./cmd/reverb
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -o bin/agent-sim ./cmd/agent-sim
@echo "✓ Binaries built in bin/"
# Run tests
test:
@echo "Running tests..."
go test -v -race -cover ./...
@echo "✓ Tests completed"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf bin/
docker system prune -f --volumes
@echo "✓ Clean completed"
# Format Go code
fmt:
@echo "Formatting Go code..."
go fmt ./...
@echo "✓ Code formatted"
# Run Go vet
vet:
@echo "Running Go vet..."
go vet ./...
@echo "✓ Vet completed"
# Download dependencies
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
@echo "✓ Dependencies updated"
# Build Docker images
docker:
@echo "Building Docker images..."
docker build -t $(PROJECT_NAME)-pulse:$(VERSION) --target pulse .
docker build -t $(PROJECT_NAME)-reverb:$(VERSION) --target reverb .
docker build -t $(PROJECT_NAME)-agent-sim:$(VERSION) --target agent-sim .
@echo "✓ Docker images built"
# Tag and push Docker images to registry
docker-push: docker
@echo "Pushing Docker images to $(DOCKER_REGISTRY)..."
docker tag $(PROJECT_NAME)-pulse:$(VERSION) $(DOCKER_REGISTRY)/$(PROJECT_NAME)-pulse:$(VERSION)
docker tag $(PROJECT_NAME)-reverb:$(VERSION) $(DOCKER_REGISTRY)/$(PROJECT_NAME)-reverb:$(VERSION)
docker tag $(PROJECT_NAME)-agent-sim:$(VERSION) $(DOCKER_REGISTRY)/$(PROJECT_NAME)-agent-sim:$(VERSION)
docker push $(DOCKER_REGISTRY)/$(PROJECT_NAME)-pulse:$(VERSION)
docker push $(DOCKER_REGISTRY)/$(PROJECT_NAME)-reverb:$(VERSION)
docker push $(DOCKER_REGISTRY)/$(PROJECT_NAME)-agent-sim:$(VERSION)
@echo "✓ Docker images pushed"
# Start development environment
run-dev:
@echo "Starting BACKBEAT development environment..."
docker-compose up -d --build
@echo "✓ Development environment started"
@echo ""
@echo "Services available at:"
@echo " - Pulse node 1: http://localhost:8080"
@echo " - Pulse node 2: http://localhost:8081"
@echo " - Reverb service: http://localhost:8082"
@echo " - NATS server: http://localhost:8222"
@echo " - Prometheus: http://localhost:9090"
@echo " - Grafana: http://localhost:3000 (admin/admin)"
# Stop development environment
stop-dev:
@echo "Stopping BACKBEAT development environment..."
docker-compose down
@echo "✓ Development environment stopped"
# Show logs from development environment
logs:
docker-compose logs -f
# Show status of development environment
status:
@echo "BACKBEAT development environment status:"
@echo ""
docker-compose ps
@echo ""
@echo "Health checks:"
@curl -s http://localhost:8080/health | jq '.' 2>/dev/null || echo "Pulse-1: Not responding"
@curl -s http://localhost:8081/health | jq '.' 2>/dev/null || echo "Pulse-2: Not responding"
@curl -s http://localhost:8082/health | jq '.' 2>/dev/null || echo "Reverb: Not responding"
# Quick development cycle
dev: clean fmt vet test build
@echo "✓ Development cycle completed"
# Production build
production: clean test
@echo "Building for production..."
@$(MAKE) build GOOS=linux GOARCH=amd64
@$(MAKE) docker VERSION=$(VERSION)
@echo "✓ Production build completed"
# Install development tools
install-tools:
@echo "Installing development tools..."
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
@echo "✓ Development tools installed"
# Run static analysis
lint:
@echo "Running static analysis..."
@command -v staticcheck >/dev/null 2>&1 || { echo "staticcheck not installed. Run 'make install-tools' first."; exit 1; }
staticcheck ./...
@echo "✓ Static analysis completed"
# Full CI pipeline
ci: deps fmt vet lint test build
@echo "✓ CI pipeline completed"