forked from cloudprober/cloudprober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (71 loc) · 3.2 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
SHELL := /bin/bash
VERSION ?= $(shell git describe --tags --exclude tip)
BUILD_DATE ?= $(shell date +%s)
DIRTY = $(shell git diff --shortstat 2> /dev/null | wc -l | xargs) # xargs strips whitespace.
GIT_TAG := $(shell git describe --exact-match --exclude tip --tags HEAD 2>/dev/null || /bin/true)
GIT_COMMIT = $(strip $(shell git rev-parse --short HEAD))
GOBIN ?= ${GOPATH}/bin
BINARY ?= cloudprober
DOCKER_IMAGE ?= cloudprober/cloudprober
SOURCES := $(shell find . -name '*.go')
LDFLAGS ?= "-s -w -X main.version=$(VERSION) -X main.buildTimestamp=$(BUILD_DATE) -X main.dirty=$(DIRTY) -extldflags -static"
BINARY_SOURCE ?= "./cmd/cloudprober/."
LINUX_PLATFORMS := linux-amd64 linux-arm64 linux-armv7
BINARIES := $(addprefix cloudprober-, $(LINUX_PLATFORMS) macos-amd64 macos-arm64 windows-amd64)
ifeq "$(GIT_TAG)" ""
DOCKER_TAGS := -t $(DOCKER_IMAGE):master -t $(DOCKER_IMAGE):main
DOCKER_FIPS_TAGS := -t $(DOCKER_IMAGE):master-fips -t $(DOCKER_IMAGE):main-fips
else
DOCKER_TAGS := -t $(DOCKER_IMAGE):$(GIT_TAG) -t $(DOCKER_IMAGE):latest
DOCKER_FIPS_TAGS := -t $(DOCKER_IMAGE):$(GIT_TAG)-fips -t $(DOCKER_IMAGE):latest-fips
endif
define make-binary-target
$1: $(SOURCES)
GOOS=$(subst macos,darwin,$(word 2,$(subst -, ,$1))) ; \
GOARCH=$(subst armv7,arm,$(word 3,$(subst -, ,$1))) ; \
GOARM=$(subst armv7,7,$(filter armv7,$(word 3,$(subst -, ,$1)))) ; \
CGO_ENABLED=0 GOOS=$$$${GOOS} GOARCH=$$$${GOARCH} GOARM=$$$${GOARM} go build -o $1 -ldflags $(LDFLAGS) $(BINARY_SOURCE)
endef
test:
go test -v -race -covermode=atomic ./...
$(foreach bin,$(BINARIES),$(eval $(call make-binary-target,$(bin))))
$(BINARY): $(SOURCES)
CGO_ENABLED=0 go build -o $@ -ldflags $(LDFLAGS) $(BINARY_SOURCE)
docker_multiarch: $(addprefix cloudprober-, $(LINUX_PLATFORMS)) Dockerfile
docker buildx build --push \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=$(VERSION) \
--build-arg VCS_REF=$(GIT_COMMIT) \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
$(DOCKER_TAGS) .
docker_multiarch_fips: Dockerfile.fips
docker buildx build --push \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=$(VERSION) \
--build-arg VCS_REF=$(GIT_COMMIT) \
--platform linux/amd64,linux/arm64 \
$(DOCKER_FIPS_TAGS) -f Dockerfile.fips .
dist: $(BINARIES)
for bin in $(BINARIES) ; do \
bindir=$${bin/amd64/x86_64}; \
bindir=cloudprober-$(VERSION)-$${bindir/cloudprober-/}; \
mkdir -p $${bindir}; cp $${bin} $${bindir}/cloudprober; \
chmod a+rx $${bindir}/cloudprober; \
[[ "$${bin}" == *"windows"* ]] && mv $${bindir}/cloudprober{,.exe}; \
zip -r $${bindir}.zip $${bindir}/; rm -rf $${bindir}; \
done
PYVERSION := $(subst v,,$(VERSION))
PYVERSION := $(word 1,$(subst -, ,$(PYVERSION)))-$(word 2,$(subst -, ,$(PYVERSION)))
PYVERSION := $(patsubst %-,%,$(PYVERSION))
py_serverutils:
cp README.md probes/external/serverutils/py/README.md && \
cd probes/external/serverutils/py && \
sed -i "s/version = \"[^\"]*\"/version = \"$(PYVERSION)\"/" pyproject.toml && \
python3 -m pip install build --user && \
python3 -m build && \
git checkout pyproject.toml && \
rm README.md
install:
GOBIN=$(GOBIN) CGO_ENABLED=0 go install -ldflags $(LDFLAGS) $(BINARY_SOURCE)
clean:
rm -f cloudprober cloudprober-*