forked from linuxfoundation/lfx-v2-auth-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
156 lines (133 loc) · 5.04 KB
/
Makefile
File metadata and controls
156 lines (133 loc) · 5.04 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
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
APP_NAME := lfx-v2-auth-service
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 := ghcr.io/linuxfoundation
DOCKER_IMAGE := $(DOCKER_REGISTRY)/$(APP_NAME)
DOCKER_TAG := $(VERSION)
# Helm variables
HELM_CHART_PATH=./charts/lfx-v2-auth-service
HELM_RELEASE_NAME=lfx-v2-auth-service
HELM_NAMESPACE=lfx
# Go
GO_VERSION := 1.24.5
GOOS := linux
GOARCH := amd64
# Linting
GOLANGCI_LINT_VERSION := v2.2.2
LINT_TIMEOUT := 10m
LINT_TOOL=$(shell go env GOPATH)/bin/golangci-lint
GO_FILES=$(shell find . -name '*.go' -not -path './gen/*' -not -path './vendor/*')
##@ 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: deps
deps: ## Install dependencies
@echo "Installing dependencies..."
go install goa.design/goa/v3/cmd/goa@latest
.PHONY: apigen
apigen: deps ## Generate API code using Goa
goa gen github.com/linuxfoundation/lfx-v2-auth-service/cmd/server/design
.PHONY: setup
setup: ## Setup development environment
@echo "Setting up development environment..."
go mod download
go mod tidy
.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@$(GOLANGCI_LINT_VERSION))
@golangci-lint run ./... && echo "==> Lint OK"
# Format code
.PHONY: fmt
fmt:
@echo "==> Formatting code..."
@go fmt ./...
@gofmt -s -w $(GO_FILES)
# Check license headers (basic validation - full check runs in CI)
.PHONY: license-check
license-check:
@echo "==> Checking license headers (basic validation)..."
@missing_files=$$(find . \( -name "*.go" -o -name "*.html" -o -name "*.txt" \) \
-not -path "./gen/*" \
-not -path "./vendor/*" \
-not -path "./megalinter-reports/*" \
-exec sh -c 'head -10 "$$1" | grep -q "Copyright The Linux Foundation and each contributor to LFX" && head -10 "$$1" | grep -q "SPDX-License-Identifier: MIT" || echo "$$1"' _ {} \;); \
if [ -n "$$missing_files" ]; then \
echo "Files missing required license headers:"; \
echo "$$missing_files"; \
echo "Required headers:"; \
echo " Go files: // Copyright The Linux Foundation and each contributor to LFX."; \
echo " // SPDX-License-Identifier: MIT"; \
echo " HTML files: <!-- Copyright The Linux Foundation and each contributor to LFX. -->"; \
echo " <!-- SPDX-License-Identifier: MIT -->"; \
echo " TXT files: # Copyright The Linux Foundation and each contributor to LFX."; \
echo " # SPDX-License-Identifier: MIT"; \
echo "Note: Full license validation runs in CI"; \
exit 1; \
fi
@echo "==> Basic license header check passed"
# Check formatting and linting without modifying files
check:
@echo "==> Checking code format..."
@if [ -n "$$(gofmt -l $(GO_FILES))" ]; then \
echo "The following files need formatting:"; \
gofmt -l $(GO_FILES); \
exit 1; \
fi
@echo "==> Code format check passed"
@$(MAKE) lint
@$(MAKE) license-check
.PHONY: test
test: ## Run tests
@echo "Running tests..."
go test -v -race -coverprofile=coverage.out ./...
.PHONY: build
build: apigen ## 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/server
.PHONY: run
run: build ## Run the application for local development
@echo "Running application for local development..."
./bin/$(APP_NAME)
##@ 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-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
# Install Helm chart
.PHONY: helm-install
helm-install:
@echo "==> Installing Helm chart..."
helm upgrade --install $(HELM_RELEASE_NAME) $(HELM_CHART_PATH) --namespace $(HELM_NAMESPACE)
@echo "==> Helm chart installed: $(HELM_RELEASE_NAME)"
# Print templates for Helm chart
.PHONY: helm-templates
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
.PHONY: helm-uninstall
helm-uninstall:
@echo "==> Uninstalling Helm chart..."
helm uninstall $(HELM_RELEASE_NAME) --namespace $(HELM_NAMESPACE)
@echo "==> Helm chart uninstalled: $(HELM_RELEASE_NAME)"