-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (97 loc) · 3.65 KB
/
Makefile
File metadata and controls
117 lines (97 loc) · 3.65 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
# Makefile for GoSQLGuard Docker build and release
# Automatically increments RC version with each release
# Extract version from pkg/version/version.go
VERSION := $(shell grep 'Version.*=' pkg/version/version.go | sed 's/.*= "\(.*\)".*/\1/')
# Read current RC number or set to 1 if file doesn't exist
RC_NUMBER := $(shell if [ -f .rc-version ]; then cat .rc-version; else echo 1; fi)
# Increment for next build
NEXT_RC := $(shell echo $$(($(RC_NUMBER) + 1)))
# Image name
IMAGE := supporttools/gosqlguard
# Full image tag
TAG := $(VERSION)-rc$(RC_NUMBER)
# Git commit for build args
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Build date for build args
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go build variables
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
LDFLAGS := -X github.com/supporttools/GoSQLGuard/pkg/version.Version=$(VERSION) \
-X github.com/supporttools/GoSQLGuard/pkg/version.GitCommit=$(GIT_COMMIT) \
-X github.com/supporttools/GoSQLGuard/pkg/version.BuildDate=$(BUILD_DATE)
.PHONY: help build build-go build-recovery push release clean increment-rc test templ templ-watch
# Default target
help:
@echo "GoSQLGuard Build System"
@echo "-----------------------"
@echo "Available targets:"
@echo " build-go - Build GoSQLGuard binary"
@echo " build-recovery - Build metadata recovery tool"
@echo " build - Build Docker image $(IMAGE):$(TAG)"
@echo " push - Push Docker image to registry"
@echo " release - Build and push Docker image"
@echo " test - Run tests"
@echo " clean - Remove build artifacts"
@echo " increment-rc - Increment RC number without building"
@echo " templ - Generate Templ templates"
@echo " templ-watch - Watch and regenerate templates on changes"
@echo ""
@echo "Current version: $(VERSION)"
@echo "Current RC: $(RC_NUMBER)"
@echo "Next RC will be: $(NEXT_RC)"
# Generate Templ templates
templ:
@echo "Generating Templ templates..."
@$(shell go env GOPATH)/bin/templ generate
@echo "Templates generated"
# Watch and regenerate Templ templates on changes
templ-watch:
@echo "Watching Templ templates for changes..."
@$(shell go env GOPATH)/bin/templ generate --watch
# Build GoSQLGuard binary
build-go: templ
@echo "Building GoSQLGuard binary..."
go build -ldflags "$(LDFLAGS)" -o gosqlguard main.go
@echo "Binary built: gosqlguard"
# Build metadata recovery tool
build-recovery:
@echo "Building metadata recovery tool..."
go build -ldflags "$(LDFLAGS)" -o metadata-recovery cmd/metadata-recovery/main.go
@echo "Binary built: metadata-recovery"
# Run tests
test:
@echo "Running tests..."
go test ./...
# Build the Docker image
build: build-go build-recovery
@echo "Building $(IMAGE):$(TAG)..."
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE):$(TAG) \
-t $(IMAGE):latest \
.
@echo "Build complete: $(IMAGE):$(TAG)"
# Push the Docker image to registry
push:
@echo "Pushing $(IMAGE):$(TAG) to registry..."
docker push $(IMAGE):$(TAG)
docker push $(IMAGE):latest
@echo "Push complete"
# Build and push in one step
release: build push
@echo "Release complete: $(IMAGE):$(TAG)"
@echo "Incrementing RC number for next build..."
@echo $(NEXT_RC) > .rc-version
@echo "Next build will use RC=$(NEXT_RC)"
# Just increment the RC number without building
increment-rc:
@echo "Incrementing RC number from $(RC_NUMBER) to $(NEXT_RC)"
@echo $(NEXT_RC) > .rc-version
# Clean temporary files and build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -f gosqlguard metadata-recovery
@echo "Done"