forked from stevemcquaid/custom-metrics-apiserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (60 loc) · 2.08 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
REGISTRY?=stevemcquaid
IMAGE?=custom-metrics-apiserver
TEMP_DIR:=$(shell mktemp -d)
ARCH?=amd64
ALL_ARCH=amd64 arm arm64 ppc64le s390x
ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x
OUT_DIR?=./_output
VENDOR_DOCKERIZED=0
VERSION?=latest
ifeq ($(ARCH),amd64)
BASEIMAGE?=busybox
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armhf/busybox
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=aarch64/busybox
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/busybox
endif
ifeq ($(ARCH),s390x)
BASEIMAGE?=s390x/busybox
endif
.PHONY: all build docker-build push-% push test verify-gofmt gofmt verify
all: build
build: vendor
CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o $(OUT_DIR)/$(ARCH)/sample-adapter github.com/stevemcquaid/custom-metrics-apiserver
docker-build: vendor
cp deploy/Dockerfile $(TEMP_DIR)
cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
docker run -it -v $(TEMP_DIR):/build -v $(shell pwd):/go/src/github.com/$(REGISTRY)/$(IMAGE) -e GOARCH=$(ARCH) golang:1.8 /bin/bash -c "\
CGO_ENABLED=0 go build -a -tags netgo -o /build/sample-adapter github.com/$(REGISTRY)/$(IMAGE)"
docker build -t $(REGISTRY)/$(IMAGE)-$(ARCH):$(VERSION) $(TEMP_DIR)
rm -rf $(TEMP_DIR)
push-%:
$(MAKE) ARCH=$* docker-build
docker push $(REGISTRY)/$(IMAGE)-$*:$(VERSION)
push: ./manifest-tool $(addprefix push-,$(ALL_ARCH))
./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(REGISTRY)/$(IMAGE)-ARCH:$(VERSION) --target $(REGISTRY)/$(IMAGE):$(VERSION)
./manifest-tool:
curl -sSL https://github.com/estesp/manifest-tool/releases/download/v0.5.0/manifest-tool-linux-amd64 > manifest-tool
chmod +x manifest-tool
vendor: glide.lock
ifeq ($(VENDOR_DOCKERIZED),1)
docker run -it -v $(shell pwd):/go/src/github.com/$(REGISTRY)/$(IMAGE) -w /go/src/github.com/$(REGISTRY)/$(IMAGE) golang:1.8 /bin/bash -c "\
curl https://glide.sh/get | sh \
&& glide install -v"
else
glide install -v
endif
test: vendor
CGO_ENABLED=0 go test ./pkg/...
verify-gofmt:
./hack/gofmt-all.sh -v
gofmt:
./hack/gofmt-all.sh
verify: verify-gofmt test
run:
./$(OUT_DIR)/$(ARCH)/sample-adapter