forked from kloudsense/cloudera_exporter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile.common
131 lines (102 loc) · 5.09 KB
/
Makefile.common
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
# Copyright 2019 Keedio
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO ?= go
GOFMT ?= $(GO)fmt
GOBUILD ?= $(GO) build
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
GOOPTS ?=
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
GO_VERSION ?= $(shell $(GO) version)
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
GO_BUILD_FLAGS ?=
DOCKER ?= docker
DOCKER_BUILD_FLAGS ?= -t $(IMAGE_COMPLETE_NAME)
DOCKER_BUILD ?= $(DOCKER) build $(DOCKER_BUILD_FLAGS)
DOCKER_RUN_FLAGS ?= --name $(IMAGE_NAME) --add-host cloudera_manager:192.168.4.112 -p 9200:9200 -d
DOCKER_RUN ?= $(DOCKER) run
DOCKER_RM_FLAGS ?= -f
DOCKER_RM ?= $(DOCKER) rm $(DOCKER_RM_FLAGS)
DOCKER_IMAGE_PRUNE ?= $(DOCKER) image prune
DOCKER_BUILD_OUTPUT_FILE = "docker_build_output.log"
BINARY_NAME ?= cloudera_exporter
IMAGE_NAME ?= cloudera_exporter
IMAGE_PROVIDER ?= keedio
IMAGE_VERSION ?= $(shell cat VERSION)
IMAGE_COMPLETE_NAME ?= $(IMAGE_PROVIDER)/$(IMAGE_NAME):$(IMAGE_VERSION)
CONTAINER_NAME ?= cloudera_exporter
DEPLOY_IP ?= localhost
DEPLOY_PORT ?= 9200
DEPLOY_METRICS_PATH ?= /metrics
METRIC_CHECK_UP ?= kbdi_exporter_up
### Docker working Rules
################################################################################
build_docker_image:
@echo "Building Go Inside a Docker Temporal Container"
@$(DOCKER_BUILD) . > $(DOCKER_BUILD_OUTPUT_FILE) || cat $(DOCKER_BUILD_OUTPUT_FILE)
@rm $(DOCKER_BUILD_OUTPUT_FILE)
build_in_docker: build_docker_image clean_docker_none_images
run_container:
@echo "Running in Docker container"
ifeq ($(shell docker ps -a -f name="$(CONTAINER_NAME)$$" --format '{{.Names}}' | tail -1),$(CONTAINER_NAME))
@$(DOCKER_RM) $(CONTAINER_NAME) > /dev/null
endif
@$(DOCKER_RUN) $(DOCKER_RUN_FLAGS) $(IMAGE_COMPLETE_NAME) > /dev/null
run_in_docker: run_container sleep_pre_test test_cloudera_exporter
stop_docker:
@docker stop $(CONTAINER_NAME)
### Local working Rules
################################################################################
build_in_local:
@echo "Building Go in Local"
@$(GOBUILD) -o $(BINARY_NAME) cloudera_exporter.go
run_in_local:
@echo "Running in Local"
./$(BINARY_NAME) --config-file ./config.ini
### Testing Rules
################################################################################
sleep_pre_test:
@sleep 2
test_cloudera_exporter:
@echo "Testing exporter"
ifeq ($(shell curl -s "$(DEPLOY_IP):$(DEPLOY_PORT)$(DEPLOY_METRICS_PATH)" | grep "$(METRIC_CHECK_UP)" | grep -v "^\#" | awk '{ print $$2 }'),1)
@echo "Cloudera Exporter is \033[32mUp\033[0m"
else
@echo "Cloudera Exporter is \033[31mDown\033[0m"
endif
test_exporter: test_cloudera_exporter
@echo "Test Finished"
### Cleanning Rules
################################################################################
clean_docker_none_images:
@echo "y" | $(DOCKER_IMAGE_PRUNE) > /dev/null
clean_docker_container:
@$(DOCKER_RM) $(CONTAINER_NAME) > /dev/null
clean_local_files:
@rm -f $(BINARY_NAME) > /dev/null
clean_env: clean_docker_container clean_docker_none_images clean_local_files
@echo "Environment Cleaned"
### Other Rules
################################################################################
print_help:
@echo "\033[37mHelp Msg:\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake all\033[37m\": Build and Run the Cloudera Exporter in Docker\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake docker_build\033[37m\": Build the Cloudera Exporter in a Docker Image\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake docker_run\033[37m\": Run the Cloudera Exporter in a Docker Container\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake docker\033[37m\": Build and Run the Cloudera Exporter in a Docker Container\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake stop\033[37m\": Stop the Docker Container\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake local_build\033[37m\": Build the Cloudera Exporter in the local system\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake local_run\033[37m\": Run the Cloudera Exporter in the local system\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake local\033[37m\": Build and Run the Cloudera Exporter in the local system\033[0m"
@echo " \033[31m*\033[37m \"\033[33mmake test\033[37m\": Test the status of the Cloudera Exporter\033[0m"