-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (80 loc) · 3.16 KB
/
Copy pathMakefile
File metadata and controls
94 lines (80 loc) · 3.16 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
.DEFAULT_GOAL := help
BINARY_NAME := updo
LAMBDA_BINARY := aws/bootstrap
LAMBDA_ZIP := aws/bootstrap.zip
LAMBDA_SOURCE := lambda/lambda.go
GOOS := linux
GOARCH := arm64
CGO_ENABLED := 0
BUILD_TAGS := lambda.norpc
.PHONY: help doctor build-lambda build clean test lint vet format check install
help: ## Show usage and commands
@printf "updo - Website monitoring tool with multi-region Lambda support\n\n"
@printf "Usage: make <command>\n\n"
@printf "Commands:\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " %-12s %s\n", $$1, $$2}'
@printf "\nExamples:\n"
@printf " make doctor # Check prerequisites\n"
@printf " make build # Build updo binary with embedded Lambda\n"
@printf " make test # Build and test deployment\n"
@printf " make clean # Remove build artifacts\n"
doctor: ## Check required tools and environment
@echo "Checking prerequisites..."
@if ! command -v go >/dev/null 2>&1; then \
echo "Error: Go not found in PATH"; exit 1; \
fi
@echo "OK: Go found ($$(go version))"
@if ! command -v zip >/dev/null 2>&1; then \
echo "Error: zip not found in PATH"; exit 1; \
fi
@echo "OK: zip found"
@if ! go mod verify >/dev/null 2>&1; then \
echo "Error: Go modules not valid - run 'go mod tidy'"; exit 1; \
fi
@echo "OK: Go modules verified"
@if [ ! -f "$(LAMBDA_SOURCE)" ]; then \
echo "Error: Lambda source not found at $(LAMBDA_SOURCE)"; exit 1; \
fi
@echo "OK: Lambda source found"
@echo "All prerequisites satisfied!"
build-lambda: ## Build Lambda binary for embedding
@echo "Building Lambda binary for ARM64..."
@cd lambda && GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build -tags $(BUILD_TAGS) -ldflags="-s -w" -o ../$(LAMBDA_BINARY) $(notdir $(LAMBDA_SOURCE))
@echo "Lambda binary built: $(LAMBDA_BINARY)"
@echo "Creating ZIP archive for embedding..."
@cd aws && zip -q bootstrap.zip bootstrap
@echo "Lambda ZIP created: $(LAMBDA_ZIP)"
build: build-lambda ## Build updo binary with embedded Lambda
@echo "Building $(BINARY_NAME) with embedded Lambda binary..."
@go build -ldflags="-s -w" -o $(BINARY_NAME) .
@echo "Binary built: $(BINARY_NAME)"
install: build ## Install updo binary to GOPATH/bin
@echo "Installing $(BINARY_NAME) to GOPATH/bin..."
@go install .
@echo "$(BINARY_NAME) installed successfully"
test: build ## Build and test deployment with dry-run
@echo "Testing deployment with dry-run..."
@./$(BINARY_NAME) aws deploy --dry-run
@echo "Test completed successfully"
lint: ## Run golangci-lint if available
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "Running golangci-lint..."; \
golangci-lint run; \
else \
echo "Warning: golangci-lint not found, skipping lint check"; \
fi
vet: ## Run go vet
@echo "Running go vet..."
@go vet ./...
format: ## Format code with gofmt
@echo "Formatting code..."
@gofmt -s -w .
@cd lambda && gofmt -s -w .
check: vet lint ## Run all code quality checks
@echo "All checks completed"
clean: ## Remove all build artifacts
@echo "Cleaning build artifacts..."
@rm -f $(BINARY_NAME) $(LAMBDA_BINARY) $(LAMBDA_ZIP)
@echo "Clean completed"