-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (148 loc) · 5.64 KB
/
Copy pathMakefile
File metadata and controls
180 lines (148 loc) · 5.64 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
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
APP_NAME := lfx-access-check
VERSION := $(shell git describe --tags --always)
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GIT_COMMIT := $(shell git rev-parse HEAD)
# Docker
DOCKER_REGISTRY := linuxfoundation
DOCKER_IMAGE := $(DOCKER_REGISTRY)/$(APP_NAME)
DOCKER_TAG := $(VERSION)
# Helm variables
HELM_CHART_PATH=./charts/lfx-v2-access-check
HELM_RELEASE_NAME=lfx-v2-access-check
HELM_NAMESPACE=lfx
HELM_VALUES_FILE=$(HELM_CHART_PATH)/values.local.yaml
# Go
GO_VERSION := 1.24.2
GOOS := linux
GOARCH := amd64
# Linting
GOLANGCI_LINT_VERSION := v2.2.2
LINT_TIMEOUT := 10m
LINT_TOOL=$(shell go env GOPATH)/bin/golangci-lint
##@ Development
.PHONY: setup-dev
setup-dev: ## Setup development tools
@echo "Installing development tools..."
@echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: setup
setup: ## Setup development environment
@echo "Setting up development environment..."
go mod download
go mod tidy
.PHONY: deps
deps: ## Install dependencies
@echo "Installing dependencies..."
go mod download
go mod tidy
.PHONY: apigen
apigen: deps ## Generate API code using Goa
@echo "Generating API code using Goa..."
go install goa.design/goa/v3/cmd/goa@latest
goa gen github.com/linuxfoundation/lfx-v2-access-check/design
.PHONY: lint
lint: ## Run golangci-lint (local Go linting)
@echo "Running golangci-lint..."
@which golangci-lint >/dev/null 2>&1 || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
@golangci-lint run ./... && echo "==> Lint OK"
.PHONY: test
test: ## Run tests
@echo "Running tests..."
go test -v -race -coverprofile=coverage.out ./...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
.PHONY: build
build: ## Build the application for local OS
@echo "Building application for local development..."
go build \
-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.gitCommit=$(GIT_COMMIT)" \
-o bin/$(APP_NAME) ./cmd/lfx-access-check
.PHONY: build-linux
build-linux: ## Build for Linux
@echo "Building for Linux..."
mkdir -p bin
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.gitCommit=$(GIT_COMMIT)" \
-o bin/$(APP_NAME)_unix ./cmd/lfx-access-check
.PHONY: run
run: build ## Run the application for local development
@echo "Running application for local development..."
./bin/$(APP_NAME)
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
go clean
rm -rf bin
rm -f coverage.out coverage.html
.PHONY: fmt
fmt: ## Format code
@echo "Formatting code..."
go fmt ./...
.PHONY: vet
vet: ## Run go vet
@echo "Running go vet..."
go vet ./...
##@ Docker
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKER_IMAGE):latest
.PHONY: docker-push
docker-push: ## Push Docker image to registry
@echo "Pushing Docker image..."
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
docker push $(DOCKER_IMAGE):latest
.PHONY: docker-run
docker-run: ## Run Docker container locally
@echo "Running Docker container..."
docker run \
--name $(APP_NAME) \
-p 8080:8080 \
-e NATS_URL=nats://lfx-platform-nats.lfx.svc.cluster.local:4222 \
$(DOCKER_IMAGE):$(DOCKER_TAG)
##@ Helm/Kubernetes
.PHONY: helm-install
helm-install: ## Install Helm chart
@echo "==> Installing Helm chart..."
helm upgrade --install $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) --namespace $(HELM_NAMESPACE) --create-namespace --set image.tag=$(DOCKER_TAG)
@echo "==> Helm chart installed: $(HELM_RELEASE_NAME)"
.PHONY: helm-install-local
helm-install-local: ## Install Helm chart with local values file
@echo "==> Installing Helm chart with local values..."
helm upgrade --force --install $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) \
--namespace $(HELM_NAMESPACE) --create-namespace \
--values $(HELM_VALUES_FILE)
@echo "==> Helm chart installed: $(HELM_RELEASE_NAME)"
.PHONY: helm-templates
helm-templates: ## Generate Helm templates
@echo "==> Printing templates for Helm chart..."
helm template $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) --namespace $(HELM_NAMESPACE) --set image.tag=$(DOCKER_TAG)
@echo "==> Templates printed for Helm chart: $(HELM_RELEASE_NAME)"
.PHONY: helm-templates-local
helm-templates-local: ## Generate Helm templates with local values file
@echo "==> Rendering Helm templates with local values..."
helm template $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) \
--namespace $(HELM_NAMESPACE) \
--values $(HELM_VALUES_FILE)
@echo "==> Templates printed for Helm chart: $(HELM_RELEASE_NAME)"
.PHONY: helm-uninstall
helm-uninstall: ## Uninstall Helm release
@echo "==> Uninstalling Helm chart..."
helm uninstall $(HELM_RELEASE_NAME) --namespace $(HELM_NAMESPACE)
@echo "==> Helm chart uninstalled: $(HELM_RELEASE_NAME)"
.PHONY: helm-lint
helm-lint: ## Lint Helm chart
@echo "==> Linting Helm chart..."
helm lint $(HELM_CHART_PATH)
@echo "==> Helm chart lint completed"
##@ Help
.PHONY: help
help: ## Show this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)