-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
76 lines (61 loc) · 1.99 KB
/
Makefile
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
# This Makefile is used for dev purposes
# Variables
REPO := ghcr.io/bnema/gordon
TAG := dev
DIST_DIR := ./dist
ENGINE := podman
# Version information
VERSION := $(shell git describe --tags --always --dirty)
COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p')
# Build flags
LDFLAGS := -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(BUILD_DATE)
# Architectures
ARCHS := amd64 arm64
# Phony targets
.PHONY: all build build-push clean
# Default target
all: build
# Build binaries
build:
@echo "Building Go binaries..."
@mkdir -p $(DIST_DIR)
@rm -f $(DIST_DIR)/*
@echo "Building with version $(VERSION), commit $(COMMIT), date $(BUILD_DATE)"
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-amd64 ./main.go
@CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-arm64 ./main.go
@echo "Go binaries built successfully"
# Build and push Docker images
build-push: build
@echo "Cleaning up dangling images..."
@$(ENGINE) image prune -f
@echo "Building and pushing Docker images..."
@for arch in $(ARCHS); do \
cp $(DIST_DIR)/gordon-linux-$$arch gordon; \
$(ENGINE) build -t $(REPO):$(TAG)-$$arch .; \
rm gordon; \
$(ENGINE) push $(REPO):$(TAG)-$$arch; \
done
@echo "Removing existing manifest..."
@$(ENGINE) manifest rm $(REPO):$(TAG) || true
@echo "Creating multi-arch manifest..."
@$(ENGINE) manifest create $(REPO):$(TAG) \
$(REPO):$(TAG)-amd64 \
$(REPO):$(TAG)-arm64
@echo "Annotating arm64 image..."
@$(ENGINE) manifest annotate $(REPO):$(TAG) \
$(REPO):$(TAG)-arm64 --arch arm64 --variant v8
@echo "Inspecting manifest..."
@$(ENGINE) manifest inspect $(REPO):$(TAG)
@echo "Pushing multi-arch manifest..."
@$(ENGINE) manifest push --all $(REPO):$(TAG)
@echo "Script completed successfully."
# Clean up
clean:
@echo "Cleaning up..."
@rm -rf $(DIST_DIR)
@$(ENGINE) system prune -f
@echo "Cleanup completed."