forked from kube-reporting/metering-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
344 lines (263 loc) · 12.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
SHELL := /bin/bash
ROOT_DIR:= $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
include build/check_defined.mk
# Package
GO_PKG := github.com/operator-framework/operator-metering
REPORTING_OPERATOR_PKG := $(GO_PKG)/cmd/reporting-operator
DOCKER_BUILD_ARGS ?=
DOCKER_BUILD_CMD = docker build $(DOCKER_BUILD_ARGS)
USE_IMAGEBUILDER ?= false
ifeq ($(USE_IMAGEBUILDER), true)
DOCKER_BUILD_CMD = imagebuilder
endif
GO_BUILD_ARGS := -ldflags '-extldflags "-static"'
GOOS = "linux"
CGO_ENABLED = 0
REPORTING_OPERATOR_BIN_OUT = bin/reporting-operator
REPORTING_OPERATOR_BIN_OUT_LOCAL = bin/reporting-operator-local
DOCKER_COMMON_NAMES := \
reporting-operator \
metering-operator \
hadoop \
hive \
presto \
metering-e2e
DOCKER_BUILD_NAMES = $(DOCKER_COMMON_NAMES)
DOCKER_TAG_NAMES = $(DOCKER_COMMON_NAMES)
DOCKER_PUSH_NAMES = $(DOCKER_COMMON_NAMES)
REBUILD_HELM_OPERATOR ?= true
METERING_OPERATOR_DEPENDENCIES = images/metering-operator/Dockerfile
ifeq ($(REBUILD_HELM_OPERATOR), true)
METERING_OPERATOR_DEPENDENCIES += helm-operator-docker-build
DOCKER_BUILD_NAMES += helm-operator
DOCKER_TAG_NAMES += helm-operator
DOCKER_PUSH_NAMES += helm-operator
endif
# We append this here so it comes after the helm-operator
DOCKER_BASE_URL := quay.io/coreos
BUILDER_OPERATOR_IMAGE := $(DOCKER_BASE_URL)/metering-builder
METERING_OPERATOR_IMAGE := $(DOCKER_BASE_URL)/metering-helm-operator
REPORTING_OPERATOR_IMAGE := $(DOCKER_BASE_URL)/metering-reporting-operator
HELM_OPERATOR_IMAGE := $(DOCKER_BASE_URL)/helm-operator
HADOOP_IMAGE := $(DOCKER_BASE_URL)/metering-hadoop
HIVE_IMAGE := $(DOCKER_BASE_URL)/metering-hive
PRESTO_IMAGE := $(DOCKER_BASE_URL)/metering-presto
METERING_E2E_IMAGE := $(DOCKER_BASE_URL)/metering-e2e
GIT_SHA := $(shell git rev-parse HEAD)
GIT_TAG := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
RELEASE_TAG := $(shell hack/print-version.sh)
PULL_TAG_IMAGE_SOURCE ?= false
USE_LATEST_TAG ?= false
USE_RELEASE_TAG = true
PUSH_RELEASE_TAG = false
DOCKER_BUILD_CONTEXT = $(dir $(DOCKERFILE))
IMAGE_TAG = $(GIT_SHA)
TAG_IMAGE_SOURCE = $(IMAGE_NAME):$(GIT_SHA)
# Hive Git repository for Thrift definitions
HIVE_REPO := "git://git.apache.org/hive.git"
HIVE_SHA := "1fe8db618a7bbc09e041844021a2711c89355995"
CHECK_GO_FILES = true
REPORTING_OPERATOR_GO_FILES =
ifeq ($(CHECK_GO_FILES), true)
JQ_DEP_SCRIPT = '.Deps[] | select(. | contains("$(GO_PKG)"))'
REPORTING_OPERATOR_GO_FILES = $(shell go list -json $(REPORTING_OPERATOR_PKG) | jq $(JQ_DEP_SCRIPT) -r | xargs -I{} find $(GOPATH)/src/$(REPORTING_OPERATOR_PKG) $(GOPATH)/src/{} -type f -name '*.go' | sort | uniq)
endif
CODEGEN_SOURCE_GO_FILES := $(shell $(ROOT_DIR)/hack/codegen_source_files.sh)
CODEGEN_OUTPUT_GO_FILES := $(shell $(ROOT_DIR)/hack/codegen_output_files.sh)
# TODO: Add tests
all: fmt test docker-build-all
# Usage:
# make docker-build DOCKERFILE= IMAGE_NAME=
docker-build:
$(DOCKER_BUILD_CMD) -t $(IMAGE_NAME):$(GIT_SHA) -f $(DOCKERFILE) $(DOCKER_BUILD_CONTEXT)
ifdef BRANCH_TAG
$(MAKE) docker-tag IMAGE_NAME=$(IMAGE_NAME) IMAGE_TAG=$(BRANCH_TAG)
endif
ifdef DEPLOY_TAG
$(MAKE) docker-tag IMAGE_NAME=$(IMAGE_NAME) IMAGE_TAG=$(DEPLOY_TAG)
endif
ifneq ($(GIT_TAG),)
$(MAKE) docker-tag IMAGE_NAME=$(IMAGE_NAME) IMAGE_TAG=$(GIT_TAG)
endif
ifeq ($(USE_RELEASE_TAG), true)
$(MAKE) docker-tag IMAGE_NAME=$(IMAGE_NAME) IMAGE_TAG=$(RELEASE_TAG)
endif
ifeq ($(USE_LATEST_TAG), true)
$(MAKE) docker-tag IMAGE_NAME=$(IMAGE_NAME) IMAGE_TAG=latest
endif
# Usage:
# make docker-tag SOURCE_IMAGE=$(IMAGE_NAME):$(GIT_SHA) IMAGE_NAME= IMAGE_TAG=
docker-tag:
ifeq ($(PULL_TAG_IMAGE_SOURCE), true)
$(MAKE) docker-pull IMAGE=$(TAG_IMAGE_SOURCE)
endif
docker tag $(TAG_IMAGE_SOURCE) $(IMAGE_NAME):$(IMAGE_TAG)
# Usage:
# make docker-pull IMAGE=
docker-pull:
docker pull $(IMAGE)
# Usage:
# make docker-push IMAGE_NAME= IMAGE_TAG=
docker-push:
docker push $(IMAGE_NAME):$(IMAGE_TAG)
ifeq ($(PUSH_RELEASE_TAG), true)
docker push $(IMAGE_NAME):$(RELEASE_TAG)
endif
ifeq ($(USE_LATEST_TAG), true)
docker push $(IMAGE_NAME):latest
endif
ifneq ($(GIT_TAG),)
docker push $(IMAGE_NAME):$(GIT_TAG)
endif
ifdef BRANCH_TAG
docker push $(IMAGE_NAME):$(BRANCH_TAG)
endif
ifdef DEPLOY_TAG
docker push $(IMAGE_NAME):$(DEPLOY_TAG)
endif
# These generate new make targets like metering-operator-docker-build
# which can be invoked.
DOCKER_BUILD_TARGETS := $(addsuffix -docker-build, $(DOCKER_BUILD_NAMES))
DOCKER_PUSH_TARGETS := $(addsuffix -docker-push, $(DOCKER_PUSH_NAMES))
DOCKER_TAG_TARGETS := $(addsuffix -docker-tag, $(DOCKER_TAG_NAMES))
DOCKER_PULL_TARGETS := $(addsuffix -docker-pull, $(DOCKER_PUSH_NAMES))
# The steps below run for each value of $(DOCKER_TARGETS) effectively, generating multiple Make targets.
# To make it easier to follow, each step will include an example after the evaluation.
# The example will be using the metering-operator targets as it's example.
#
# The pattern/string manipulation below does the following (starting from the inner most expression):
# 1) strips -docker-push, -docker-tag, or -docker-pull from the target name ($@) giving us the non suffixed value from $(TARGETS)
# ex: metering-operator-docker-build -> metering-operator
# 2) Replaces - with _
# ex: metering-operator -> metering_helm_operator
# 3) Uppercases letters
# ex: metering_helm_operator -> METERING_HELM_OPERATOR
# 4) Appends _IMAGE
# ex: METERING_HELM_OPERATOR -> METERING_OPERATOR_IMAGE
# That gives us the value for the docker-build, docker-tag, or docker-push IMAGE_NAME variable.
$(DOCKER_PUSH_TARGETS)::
$(MAKE) docker-push IMAGE_NAME=$($(addsuffix _IMAGE, $(shell echo $(subst -,_,$(subst -docker-push,,$@)) | tr a-z A-Z)))
$(DOCKER_TAG_TARGETS)::
$(MAKE) docker-tag IMAGE_NAME=$($(addsuffix _IMAGE, $(shell echo $(subst -,_,$(subst -docker-tag,,$@)) | tr a-z A-Z)))
$(DOCKER_PULL_TARGETS)::
$(MAKE) docker-pull IMAGE_NAME=$($(addsuffix _IMAGE, $(shell echo $(subst -,_,$(subst -docker-pull,,$@)) | tr a-z A-Z)))
docker-build-all: $(DOCKER_BUILD_TARGETS)
docker-push-all: $(DOCKER_PUSH_TARGETS)
docker-tag-all: $(DOCKER_TAG_TARGETS)
docker-pull-all: $(DOCKER_PULL_TARGETS)
metering-builder-docker-build: images/builder/Dockerfile
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(BUILDER_OPERATOR_IMAGE) DOCKER_BUILD_CONTEXT=$(ROOT_DIR) USE_LATEST_TAG=true
reporting-operator-docker-build: images/reporting-operator/Dockerfile
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(REPORTING_OPERATOR_IMAGE) DOCKER_BUILD_CONTEXT=$(ROOT_DIR)
metering-e2e-docker-build: images/metering-e2e/Dockerfile
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(METERING_E2E_IMAGE) DOCKER_BUILD_CONTEXT=$(ROOT_DIR)
metering-operator-docker-build: $(METERING_OPERATOR_DEPENDENCIES)
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(METERING_OPERATOR_IMAGE) DOCKER_BUILD_CONTEXT=$(ROOT_DIR)
helm-operator-docker-build: images/helm-operator/Dockerfile $(find -type f images/helm-operator)
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(HELM_OPERATOR_IMAGE) USE_LATEST_TAG=true
presto-docker-build: images/presto/Dockerfile
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(PRESTO_IMAGE)
hadoop-docker-build: images/hadoop/Dockerfile
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(HADOOP_IMAGE) USE_LATEST_TAG=true
hive-docker-build: images/hive/Dockerfile hadoop-docker-build
$(MAKE) docker-build DOCKERFILE=$< IMAGE_NAME=$(HIVE_IMAGE)
# Update dependencies
vendor: Gopkg.toml
dep ensure -v
test:
go test ./pkg/...
test-docker:
docker run -i $(METERING_E2E_IMAGE):$(IMAGE_TAG) bash -c 'make test'
# Runs gofmt on all files in project except vendored source and Hive Thrift definitions
fmt:
find . -name '*.go' -not -path "./vendor/*" -not -path "./pkg/hive/hive_thrift/*" | xargs gofmt -w
# validates no unstaged changes exist
ci-validate: verify-codegen all-charts metering-manifests fmt
@echo Checking for unstaged changes
git diff --stat HEAD --ignore-submodules --exit-code
ci-validate-docker:
docker run -i $(METERING_E2E_IMAGE):$(IMAGE_TAG) bash -c 'make ci-validate'
reporting-operator-bin: $(REPORTING_OPERATOR_BIN_OUT)
reporting-operator-local: $(REPORTING_OPERATOR_GO_FILES)
$(MAKE) build-reporting-operator REPORTING_OPERATOR_BIN_OUT=$(REPORTING_OPERATOR_BIN_OUT_LOCAL) GOOS=$(shell go env GOOS)
.PHONY: run-reporting-operator-local
run-reporting-operator-local:
$(MAKE) reporting-operator-local
./hack/run-local-with-port-forward.sh $(REPORTING_OPERATOR_ARGS)
$(REPORTING_OPERATOR_BIN_OUT): $(REPORTING_OPERATOR_GO_FILES)
$(MAKE) build-reporting-operator
build-reporting-operator:
@:$(call check_defined, REPORTING_OPERATOR_BIN_OUT, Path to output binary location)
$(MAKE) update-codegen
mkdir -p $(dir $(REPORTING_OPERATOR_BIN_OUT))
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) go build $(GO_BUILD_ARGS) -o $(REPORTING_OPERATOR_BIN_OUT) $(REPORTING_OPERATOR_PKG)
bin/metering-override-values.yaml: ./hack/render-metering-chart-override-values.sh
@mkdir -p bin
./hack/render-metering-chart-override-values.sh $(RELEASE_TAG) > $@
CHART_DEPS := bin/tectonic-metering-0.1.0.tgz \
bin/openshift-metering-0.1.0.tgz \
bin/operator-metering-0.1.0.tgz
all-charts: $(CHART_DEPS)
tectonic-metering-chart: bin/tectonic-metering-0.1.0.tgz
openshift-metering-chart: bin/openshift-metering-0.1.0.tgz
operator-metering-chart: bin/operator-metering-0.1.0.tgz
bin/tectonic-metering-0.1.0.tgz: $(shell find charts -type f)
@echo "Packaging tectonic-metering chart dependencies"
@mkdir -p bin && mkdir -p charts/tectonic-metering/charts && hack/yamltojson < charts/tectonic-metering/requirements.yaml | jq '.dependencies[].repository' -r | sed 's|file://||' | xargs -I {} helm package --save=false -d charts/tectonic-metering/charts charts/tectonic-metering/{}
helm package --save=false -d bin charts/tectonic-metering
bin/openshift-metering-0.1.0.tgz: $(shell find charts -type f)
@echo "Packaging openshift-metering chart dependencies"
@mkdir -p bin && mkdir -p charts/openshift-metering/charts && hack/yamltojson < charts/openshift-metering/requirements.yaml | jq '.dependencies[].repository' -r | sed 's|file://||' | xargs -I {} helm package --save=false -d charts/openshift-metering/charts charts/openshift-metering/{}
helm package --save=false -d bin charts/openshift-metering
bin/operator-metering-0.1.0.tgz: $(shell find charts -type f)
@echo "Packaging operator-metering chart dependencies"
@mkdir -p bin && mkdir -p charts/operator-metering/charts && hack/yamltojson < charts/operator-metering/requirements.yaml | jq '.dependencies[].repository' -r | sed 's|file://||' | xargs -I {} helm package --save=false -d charts/operator-metering/charts charts/operator-metering/{}
helm package --save=false -d bin charts/operator-metering
metering-manifests:
./hack/create-metering-manifests.sh $(RELEASE_TAG)
.PHONY: \
test vendor fmt regenerate-hive-thrift thrift-gen \
update-codegen verify-codegen \
$(DOCKER_BUILD_TARGETS) $(DOCKER_PUSH_TARGETS) \
$(DOCKER_TAG_TARGETS) $(DOCKER_PULL_TARGETS) \
docker-build docker-tag docker-push \
docker-build-all docker-tag-all docker-push-all \
metering-test-docker \
metering-e2e-docker-build metering-builder-docker-build \
build-reporting-operator reporting-operator-bin reporting-operator-local \
operator-metering-chart tectonic-metering-chart openshift-metering chart \
bin/metering-override-values.yaml \
metering-manifests bill-of-materials.json \
install-kube-prometheus-helm
update-codegen: $(CODEGEN_OUTPUT_GO_FILES)
./hack/update-codegen.sh
$(CODEGEN_OUTPUT_GO_FILES): $(CODEGEN_SOURCE_GO_FILES)
verify-codegen:
./hack/verify-codegen.sh
# The results of these targets get vendored, but the targets exist for
# regenerating if needed.
regenerate-hive-thrift: pkg/hive/hive_thrift
# Download Hive git repo.
out/thrift.git:
mkdir -p out
git clone --single-branch --bare ${HIVE_REPO} $@
# Retrieve Hive thrift definition from git repo.
thrift/TCLIService.thrift: out/thrift.git
mkdir -p $(dir $@)
git -C $< show ${HIVE_SHA}:service-rpc/if/$(notdir $@) > $@
# Generate source from Hive thrift defintions and remove executable packages.
pkg/hive/hive_thrift: thrift/TCLIService.thrift thrift-gen
thrift-gen:
thrift -gen go:package_prefix=${GO_PKG}/pkg/hive,package=hive_thrift -out pkg/hive thrift/TCLIService.thrift
for i in `go list -f '{{if eq .Name "main"}}{{ .Dir }}{{end}}' ./pkg/hive/hive_thrift/...`; do rm -rf $$i; done
bill-of-materials.json: bill-of-materials.override.json
license-bill-of-materials --override-file $(ROOT_DIR)/bill-of-materials.override.json ./... > $(ROOT_DIR)/bill-of-materials.json
kube-prometheus-helm-install:
@echo "KUBECONFIG: $(KUBECONFIG)"
helm ls
helm version
helm repo add coreos https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/
helm upgrade --install --namespace monitoring prometheus-operator coreos/prometheus-operator --wait
# set https to false on kubelets for GKE and set the fullnameOverride for the
# Prometheus resource so our service has a consistent name.
helm upgrade --install --namespace monitoring kube-prometheus coreos/kube-prometheus --set 'prometheus.fullnameOverride=prometheus-k8s,exporter-kubelets.https=false' --wait