-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (116 loc) · 4.84 KB
/
Makefile
File metadata and controls
138 lines (116 loc) · 4.84 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
.PHONY: build build-all clean install test lint fmt vet help docker-build docker-build-multi docker-push
# Variables
BINARIES=infrahub-backup infrahub-taskmanager
BUILD_DIR=$(shell pwd)/bin
SRC_ROOT=./src
VERSION?=
LDFLAGS=-ldflags "-X main.version=$(VERSION) -s -w"
# cockroachdb/swiss (transitive dep of pebble cache) needs this tag for Go 1.26+
GO_TAGS=-tags untested_go_version
CGO_ENABLED=0
# Default target
help: ## Display this help message
@echo "Infrahub Operations Tool - Build System"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'
build: build-watchdog ## Build all CLI binaries for the current platform
@echo "Building Infrahub CLI binaries..."
@mkdir -p $(BUILD_DIR)
@for bin in $(BINARIES); do \
echo " $$bin"; \
CGO_ENABLED=$(CGO_ENABLED) go build $(GO_TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$$bin $(SRC_ROOT)/cmd/$$bin; \
done
@echo "Binaries available in $(BUILD_DIR)"
build-watchdog:
@echo "Building neo4jwatchdog binaries..."
@CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -o $(SRC_ROOT)/internal/app/embedded/neo4jwatchdog/neo4j_watchdog_linux_arm64 ./tools/neo4jwatchdog
@CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o $(SRC_ROOT)/internal/app/embedded/neo4jwatchdog/neo4j_watchdog_linux_amd64 ./tools/neo4jwatchdog
build-all: build-watchdog ## Build for multiple platforms
@echo "Building multi-platform binaries..."
@mkdir -p $(BUILD_DIR)
@for bin in $(BINARIES); do \
for platform in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64; do \
OS=$${platform%/*}; \
ARCH=$${platform#*/}; \
EXT=$$( [ "$$OS" = "windows" ] && echo ".exe" ); \
OUT=$(BUILD_DIR)/$$bin-$$OS-$$ARCH$$EXT; \
echo " $$bin ($$OS/$$ARCH)"; \
CGO_ENABLED=$(CGO_ENABLED) GOOS=$$OS GOARCH=$$ARCH go build $(GO_TAGS) $(LDFLAGS) -o "$$OUT" $(SRC_ROOT)/cmd/$$bin; \
done; \
done
@echo "Built binaries are located in $(BUILD_DIR)"
install: ## Install the binaries to $GOPATH/bin
@echo "Installing Infrahub CLI binaries..."
@for bin in $(BINARIES); do \
echo " $$bin"; \
go install $(GO_TAGS) $(LDFLAGS) $(SRC_ROOT)/cmd/$$bin; \
done
@echo "Binaries installed to $(shell go env GOPATH)/bin/"
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@go clean
test: ## Run tests
@echo "Running tests..."
@go test $(GO_TAGS) -v ./...
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
@go test $(GO_TAGS) -v -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
lint: ## Run golangci-lint
@echo "Running linter..."
@golangci-lint run
fmt: ## Format Go code
@echo "Formatting code..."
@go fmt ./...
vet: ## Run go vet
@echo "Running go vet..."
@go vet $(GO_TAGS) ./...
deps: ## Download dependencies
@echo "Downloading dependencies..."
@go mod download
@go mod tidy
deps-update: ## Update dependencies
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy
run-example: build ## Run example commands
@echo "Running example commands..."
@echo "1. Environment detection:"
@./$(BUILD_DIR)/infrahub-taskmanager environment detect || true
@echo ""
@echo "2. Backup help:"
@./$(BUILD_DIR)/infrahub-backup --help || true
@echo ""
@echo "3. Version information:"
@./$(BUILD_DIR)/infrahub-backup version || true
dev-setup: ## Set up development environment
@echo "Setting up development environment..."
@go mod download
@which golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.2
@echo "Development environment ready!"
DOCKER_REGISTRY?=registry.opsmill.io/opsmill
DOCKER_IMAGE=infrahub-backup
docker-build: ## Build Docker image for current platform
@echo "Building Docker image..."
@docker build --build-arg VERSION=$(VERSION) \
-t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(VERSION) \
-t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):latest .
docker-build-multi: ## Build multi-arch Docker images (amd64 + arm64)
@echo "Building multi-arch Docker images..."
@docker buildx build --platform linux/amd64,linux/arm64 \
--build-arg VERSION=$(VERSION) \
-t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(VERSION) \
-t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):latest .
docker-push: ## Build and push multi-arch images to registry
@echo "Building and pushing multi-arch Docker images..."
@docker buildx build --platform linux/amd64,linux/arm64 \
--build-arg VERSION=$(VERSION) \
-t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(VERSION) \
-t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):latest --push .
release: test lint build-all ## Prepare release
@echo "Preparing release $(VERSION)..."
@echo "All binaries built and tests passed"
.DEFAULT_GOAL := help