-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
195 lines (165 loc) · 5.38 KB
/
Makefile
File metadata and controls
195 lines (165 loc) · 5.38 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
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
# Application variables
APP_NAME := lfx-v2-fga-sync
APP_VERSION := latest
# Docker variables
DOCKER_REGISTRY := linuxfoundation
DOCKER_IMAGE := $(DOCKER_REGISTRY)/$(APP_NAME)
DOCKER_TAG := $(APP_VERSION)
# Helm variables
HELM_CHART_PATH=./charts/lfx-v2-fga-sync
HELM_CHART_LOCAL_VALUES_PATH=./charts/lfx-v2-fga-sync/values.local.yaml
HELM_RELEASE_NAME=lfx-v2-fga-sync
HELM_NAMESPACE=lfx
# Go build variables
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOGET := $(GOCMD) get
GOMOD := $(GOCMD) mod
GOFMT := gofmt
GOVET := $(GOCMD) vet
# Build directory
BUILD_DIR := ./bin
# Main package path
MAIN_PATH := .
# Build flags
BUILD_FLAGS := -trimpath -ldflags="-w -s"
# Default target
.DEFAULT_GOAL := help
# Build the application
.PHONY: build
build: deps
@echo "Building $(APP_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(APP_NAME) $(MAIN_PATH)
# Download dependencies
.PHONY: deps
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Run tests
.PHONY: test
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated in coverage.html"
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
# Run go vet
.PHONY: vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
# Run linter (requires golangci-lint to be installed)
.PHONY: lint
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest"; \
fi
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
# Install the binary
.PHONY: install
install: build
@echo "Installing $(APP_NAME)..."
@cp $(BUILD_DIR)/$(APP_NAME) $(GOPATH)/bin/
# Run the application
.PHONY: run
run: build
@echo "Running $(APP_NAME)..."
$(BUILD_DIR)/$(APP_NAME)
# Build Docker image
.PHONY: docker-build
docker-build:
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
# Push Docker image
.PHONY: docker-push
docker-push:
@echo "Pushing Docker image..."
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
# Install Helm chart
helm-install:
@echo "==> Installing Helm chart..."
helm upgrade --force --install $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) --namespace $(HELM_NAMESPACE)
@echo "==> Helm chart installed: $(HELM_RELEASE_NAME)"
# Install Helm chart
helm-install-local:
@echo "==> Installing Helm chart..."
helm upgrade --force --install $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) --namespace $(HELM_NAMESPACE) --values $(HELM_CHART_LOCAL_VALUES_PATH)
@echo "==> Helm chart installed: $(HELM_RELEASE_NAME)"
# Print templates for Helm chart
helm-templates:
@echo "==> Printing templates for Helm chart..."
helm template $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) --namespace $(HELM_NAMESPACE)
@echo "==> Templates printed for Helm chart: $(HELM_RELEASE_NAME)"
# Uninstall Helm chart
helm-uninstall:
@echo "==> Uninstalling Helm chart..."
helm uninstall $(HELM_RELEASE_NAME) --namespace $(HELM_NAMESPACE)
@echo "==> Helm chart uninstalled: $(HELM_RELEASE_NAME)"
# Build for multiple platforms
.PHONY: build-all
build-all: deps
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=linux GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-arm64 $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64 $(MAIN_PATH)
# Development build (with debug symbols)
.PHONY: dev
dev:
@echo "Building $(APP_NAME) with debug symbols..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(APP_NAME) $(MAIN_PATH)
# Run static analysis
.PHONY: check
check: fmt vet lint
# Build everything
.PHONY: all
all: clean deps check test build
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the application"
@echo " build-all - Build for multiple platforms"
@echo " clean - Clean build artifacts"
@echo " deps - Download dependencies"
@echo " dev - Build with debug symbols"
@echo " docker-build - Build Docker image"
@echo " docker-push - Push Docker image"
@echo " helm-install - Install Helm chart"
@echo " helm-install-local - Install Helm chart with local values"
@echo " helm-templates - Print Helm chart templates"
@echo " helm-uninstall - Uninstall Helm chart"
@echo " fmt - Format code"
@echo " help - Show this help message"
@echo " install - Install the binary"
@echo " lint - Run linter"
@echo " run - Run the application"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage"
@echo " vet - Run go vet"
@echo " check - Run fmt, vet, and lint"
@echo " all - Clean, download deps, check, test, and build"