-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
92 lines (78 loc) · 3.11 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
CMDPACKAGE=github.com/quarkslab/kdigger/commands
VERSION=$$(git describe --tags 2>/dev/null || echo dev)
GITCOMMIT=$$(git rev-parse HEAD)
BUILDERARCH=$$(uname -m)
GOLANGCI_VERSION=1.59.0
OUTPUTNAME=kdigger
# -w disable DWARF generation
# -s disable symbol table
# just to save some space in the binary
LDFLAGS="-s -w \
-X $(CMDPACKAGE).VERSION=$(VERSION) \
-X $(CMDPACKAGE).GITCOMMIT=$(GITCOMMIT) \
-X $(CMDPACKAGE).BUILDERARCH=$(BUILDERARCH)"
# if CGO_ENABLED=1, the binary will be dynamically linked, and surprisingly,
# bigger! It seems that it is because of the net package that Go is dynamically
# linking the libraries.
.PHONY: build
build:
CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o $(OUTPUTNAME)
.PHONY: lint
lint:
golangci-lint run
# Releasing stuff
RELEASE_FOLDER=release
RELEASE_LINUX_AMD64=$(OUTPUTNAME)-linux-amd64
RELEASE_LINUX_ARM64=$(OUTPUTNAME)-linux-arm64
RELEASE_DARWIN_AMD64=$(OUTPUTNAME)-darwin-amd64
RELEASE_DARWIN_ARM64=$(OUTPUTNAME)-darwin-arm64
.PHONY: build-all
build-all: lint
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(RELEASE_LINUX_AMD64)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags $(LDFLAGS) -o $(RELEASE_LINUX_ARM64)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(RELEASE_DARWIN_AMD64)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags $(LDFLAGS) -o $(RELEASE_DARWIN_ARM64)
.PHONY: release
release: build-all
mkdir -p $(RELEASE_FOLDER)
# linux amd64
mv $(RELEASE_LINUX_AMD64) $(RELEASE_FOLDER) && \
cd $(RELEASE_FOLDER) && \
sha256sum $(RELEASE_LINUX_AMD64) > $(RELEASE_LINUX_AMD64).sha256 && \
tar cvf - $(RELEASE_LINUX_AMD64) | gzip -9 - > $(RELEASE_LINUX_AMD64).tar.gz
# linux arm64
mv $(RELEASE_LINUX_ARM64) $(RELEASE_FOLDER) && \
cd $(RELEASE_FOLDER) && \
sha256sum $(RELEASE_LINUX_ARM64) > $(RELEASE_LINUX_ARM64).sha256 && \
tar cvf - $(RELEASE_LINUX_ARM64) | gzip -9 - > $(RELEASE_LINUX_ARM64).tar.gz
# darwin adm64
mv $(RELEASE_DARWIN_AMD64) $(RELEASE_FOLDER) && \
cd $(RELEASE_FOLDER) && \
sha256sum $(RELEASE_DARWIN_AMD64) > $(RELEASE_DARWIN_AMD64).sha256 && \
tar cvf - $(RELEASE_DARWIN_AMD64) | gzip -9 - > $(RELEASE_DARWIN_AMD64).tar.gz
# darwin arm64
mv $(RELEASE_DARWIN_ARM64) $(RELEASE_FOLDER) && \
cd $(RELEASE_FOLDER) && \
sha256sum $(RELEASE_DARWIN_ARM64) > $(RELEASE_DARWIN_ARM64).sha256 && \
tar cvf - $(RELEASE_DARWIN_ARM64) | gzip -9 - > $(RELEASE_DARWIN_ARM64).tar.gz
DEV_IMAGE_TAG=mtardy/kdigger-dev
.PHONY: run
run: build
echo "FROM mtardy/koolbox\nCOPY kdigger /usr/local/bin/kdigger" | docker build -t $(DEV_IMAGE_TAG) -f- .
kind load docker-image $(DEV_IMAGE_TAG)
kubectl run kdigger-dev-tmp --rm -i --tty --image $(DEV_IMAGE_TAG) --image-pull-policy Never -- bash
.PHONY: setup-run
setup-run:
arkade get kind
kind create cluster
.PHONY: install-linter
install-linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v$(GOLANGCI_VERSION)
.PHONY: clean-docker
clean-docker:
docker image rm $(DEV_IMAGE_TAG)
.PHONY: clean
clean:
rm kdigger
.PHONY: clean-all
clean-all: clean clean-docker