-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (56 loc) · 2.74 KB
/
Copy pathMakefile
File metadata and controls
67 lines (56 loc) · 2.74 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
BINARY_NAME := herald
BUILD_DIR := ./cmd/herald
GO := go
LDFLAGS := -s -w
VERSION := $(shell [ -n "$$HERALD_VERSION" ] && echo "$$HERALD_VERSION" || (git describe --tags --exact-match 2>/dev/null || git describe --always --dirty || echo "dev"))
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_FLAGS := -X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)
all: build
build:
$(GO) build -mod=mod -ldflags "$(BUILD_FLAGS)" -o $(BINARY_NAME) $(BUILD_DIR)
build-release:
$(GO) build -mod=mod -ldflags "$(LDFLAGS) $(BUILD_FLAGS)" -o $(BINARY_NAME) $(BUILD_DIR)
build-all:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -mod=mod -ldflags "$(LDFLAGS) $(BUILD_FLAGS)" -o $(BINARY_NAME)_x86_64 $(BUILD_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -mod=mod -ldflags "$(LDFLAGS) $(BUILD_FLAGS)" -o $(BINARY_NAME)_aarch64 $(BUILD_DIR)
clean:
rm -f $(BINARY_NAME) $(BINARY_NAME)_x86_64 $(BINARY_NAME)_aarch64
clean-vendor:
rm -rf vendor
install:
mkdir -p /usr/local/bin
cp $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
release: clean build-all
@echo "Binaries built with version: $(VERSION) and ready for release: $(BINARY_NAME)_x86_64, $(BINARY_NAME)_aarch64"
check-release:
@if git describe --tags --exact-match >/dev/null 2>&1; then \
if git diff-index --quiet HEAD --; then \
GIT_TAG=$$(git describe --tags --exact-match); \
if grep -q "version = \"$$GIT_TAG\"" flake.nix; then \
echo "Repository is clean and tagged. Tag $$GIT_TAG matches version in flake.nix. Ready for release."; \
else \
FLAKE_VERSION=$$(grep -o 'version = "[^"]*"' flake.nix | cut -d'"' -f2); \
echo "Error: Git tag ($$GIT_TAG) does not match version in flake.nix ($$FLAKE_VERSION)"; \
exit 1; \
fi; \
else \
echo "Repository is tagged but has uncommitted changes. Please commit or stash changes before release."; \
exit 1; \
fi; \
else \
echo "Repository is not tagged. Please create a tag before release."; \
exit 1; \
fi
container-build:
docker build --build-arg HERALD_VERSION=$(VERSION) -t nfrastack/$(BINARY_NAME):$(VERSION) -f container/Containerfile .
docker tag nfrastack/$(BINARY_NAME):$(VERSION) nfrastack/$(BINARY_NAME):latest
help:
@echo "make build Build the binary"
@echo "make build-release Build the binary with version information"
@echo "make build-all Build binaries for x86_64 and aarch64"
@echo "make clean Clean up build artifacts"
@echo "make install Install the binary locally"
@echo "make release Build and prepare for release"
@echo "make check-release Verify if the repository is tagged and clean"
@echo "make container-build Build the Container image with HERALD_VERSION as build-arg and tag"
@echo "make help Show this message"