forked from sustainable-computing-io/kepler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
174 lines (133 loc) · 4.47 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
export BIN_TIMESTAMP ?=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
export TIMESTAMP ?=$(shell echo $(BIN_TIMESTAMP) | tr -d ':' | tr 'T' '-' | tr -d 'Z')
SOURCE_GIT_TAG :=$(shell git describe --tags --always --abbrev=7 --match 'v*')
SRC_ROOT :=$(shell pwd)
OUTPUT_DIR :=_output
CROSS_BUILD_BINDIR :=$(OUTPUT_DIR)/bin
FROM_SOURCE :=false
ARCH :=$(shell uname -m |sed -e "s/x86_64/amd64/" |sed -e "s/aarch64/arm64/")
ifdef IMAGE_REPO
IMAGE_REPO := $(IMAGE_REPO)
else
IMAGE_REPO := quay.io/sustainable_computing_io/kepler
endif
ifdef IMAGE_TAG
IMAGE_TAG := $(IMAGE_TAG)
else
IMAGE_TAG := latest
endif
ifdef CTR_CMD
CTR_CMD := $(CTR_CMD)
else
CTR_CMD :=$(or $(shell which podman 2>/dev/null), $(shell which docker 2>/dev/null))
endif
# restrict included verify-* targets to only process project files
GO_PACKAGES=$(go list ./cmd/... ./pkg/...)
ifeq ($(DEBUG),true)
# throw all the debug info in!
LD_FLAGS =
GC_FLAGS =-gcflags "all=-N -l"
else
# strip everything we can
LD_FLAGS =-w -s
GC_FLAGS =
endif
GO_LD_FLAGS := $(GC_FLAGS) -ldflags "-X $(LD_FLAGS)" $(CFLAGS)
GO_BUILD_TAGS := 'include_gcs include_oss containers_image_openpgp gssapi providerless netgo osusergo'
ifneq ($(shell command -v ldconfig),)
ifneq ($(shell ldconfig -p|grep bcc),)
GO_BUILD_TAGS = 'include_gcs include_oss containers_image_openpgp gssapi providerless netgo osusergo bcc'
endif
endif
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
kepler: build-containerized-cross-build-linux-amd64
.PHONY: kepler
tidy-vendor:
go mod tidy
go mod vendor
_build_local: format
@mkdir -p "$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)"
+@GOOS=$(GOOS) GOARCH=$(GOARCH) go build -tags ${GO_BUILD_TAGS} \
-o $(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)/kepler ./cmd/exporter.go
cross-build-linux-amd64:
+$(MAKE) _build_local GOOS=linux GOARCH=amd64
.PHONY: cross-build-linux-amd64
cross-build-linux-arm64:
+$(MAKE) _build_local GOOS=linux GOARCH=arm64
.PHONY: cross-build-linux-arm64
cross-build: cross-build-linux-amd64 cross-build-linux-arm64
.PHONY: cross-build
_build_containerized: format
@if [ -z '$(CTR_CMD)' ] ; then echo '!! ERROR: containerized builds require podman||docker CLI, none found $$PATH' >&2 && exit 1; fi
echo BIN_TIMESTAMP==$(BIN_TIMESTAMP)
$(CTR_CMD) build -t $(IMAGE_REPO):$(SOURCE_GIT_TAG)-linux-$(ARCH) \
-f "$(SRC_ROOT)"/build/Dockerfile \
--build-arg SOURCE_GIT_TAG=$(SOURCE_GIT_TAG) \
--build-arg BIN_TIMESTAMP=$(BIN_TIMESTAMP) \
--build-arg ARCH=$(ARCH) \
--build-arg MAKE_TARGET="cross-build-linux-$(ARCH)" \
--platform="linux/$(ARCH)" \
.
$(CTR_CMD) tag $(IMAGE_REPO):$(SOURCE_GIT_TAG)-linux-$(ARCH) $(IMAGE_REPO):$(IMAGE_TAG)
.PHONY: _build_containerized
build-containerized-cross-build-linux-amd64:
+$(MAKE) _build_containerized ARCH=amd64
.PHONY: build-containerized-cross-build-linux-amd64
build-containerized-cross-build-linux-arm64:
+$(MAKE) _build_containerized ARCH=arm64
.PHONY: build-containerized-cross-build-linux-arm64
build-containerized-cross-build:
+$(MAKE) build-containerized-cross-build-linux-amd64
+$(MAKE) build-containerized-cross-build-linux-arm64
.PHONY: build-containerized-cross-build
push-image:
$(CTR_CMD) push $(IMAGE_REPO):$(IMAGE_TAG)
.PHONY: push-image
# for testsuite
PWD=$(shell pwd)
ENVTEST_ASSETS_DIR=./test-bin
export PATH := $(PATH):./test-bin
ifndef GOPATH
GOPATH := $(HOME)/go
GOBIN := $(GOPATH)/bin
endif
ginkgo-set: tidy-vendor
mkdir -p $(GOBIN)
mkdir -p ${ENVTEST_ASSETS_DIR}
@test -f $(ENVTEST_ASSETS_DIR)/ginkgo || \
(go install github.com/onsi/ginkgo/[email protected] && \
cp $(GOBIN)/ginkgo $(ENVTEST_ASSETS_DIR)/ginkgo)
test: ginkgo-set tidy-vendor
@go test $(GO_BUILD_FLAGS) ./... --race --bench=. -cover --count=1 --vet=all
test-verbose: ginkgo-set tidy-vendor
@go test $(GO_BUILD_FLAGS) -v ./... --race --bench=. -cover --count=1 --vet=all
format:
gofmt -e -d -s -l -w pkg/ cmd/
golint:
./hack/golint.sh
clean-cross-build:
$(RM) -r '$(CROSS_BUILD_BINDIR)'
$(RM) -rf $(OUTPUT_DIR)/staging
if [ -d '$(OUTPUT_DIR)' ]; then rmdir --ignore-fail-on-non-empty '$(OUTPUT_DIR)'; fi
.PHONY: clean-cross-build
clean: clean-cross-build
.PHONY: clean
build-manifest:
./hack/build-manifest.sh
.PHONY: build-manifest
cluster-clean: build-manifest
./hack/cluster-clean.sh
.PHONY: cluster-clean
cluster-deploy: cluster-clean
./hack/cluster-deploy.sh
.PHONY: cluster-deploy
cluster-sync:
./hack/cluster-sync.sh
.PHONY: cluster-sync
cluster-up:
./hack/cluster-up.sh
.PHONY: cluster-up
cluster-down:
./hack/cluster-down.sh
.PHONY: cluster-down