github.com/GoogleCloudPlatform/opentelemetry-operations-collector@v0.0.3-0.20230814143943-2c2416e3c759/Makefile (about) 1 # read PKG_VERSION from VERSION file 2 include VERSION 3 4 # if GOOS is not supplied, set default value based on user's system, will be overridden for OS specific packaging commands 5 GOOS ?= $(shell go env GOOS) 6 ifeq ($(GOOS),windows) 7 EXTENSION := .exe 8 endif 9 10 # if ARCH is not supplied, set default value based on user's system 11 ARCH ?= $(shell if [ `getconf LONG_BIT` -eq "64" ]; then echo "x86_64"; else echo "x86"; fi) 12 13 # set GOARCH based on ARCH 14 ifeq ($(ARCH),x86_64) 15 GOARCH := amd64 16 else ifeq ($(ARCH),x86) 17 GOARCH := 386 18 else 19 $(error "ARCH must be set to one of: x86, x86_64") 20 endif 21 22 ALL_SRC := $(shell find . -name '*.go' -type f | sort) 23 ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) -type f | sort) 24 GIT_SHA := $(shell git rev-parse --short HEAD) 25 26 BUILD_INFO_IMPORT_PATH := github.com/GoogleCloudPlatform/opentelemetry-operations-collector/internal/version 27 BUILD_X1 := -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) 28 BUILD_X2 := -X $(BUILD_INFO_IMPORT_PATH).Version=$(PKG_VERSION) 29 ifdef JMX_HASH 30 JMX_RECEIVER_IMPORT_PATH := github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver 31 BUILD_X_JMX := -X $(JMX_RECEIVER_IMPORT_PATH).MetricsGathererHash=$(JMX_HASH) 32 LD_FLAGS := -ldflags "${BUILD_X1} ${BUILD_X2} ${BUILD_X_JMX}" 33 else 34 LD_FLAGS := -ldflags "${BUILD_X1} ${BUILD_X2}" 35 endif 36 37 TOOLS_DIR := internal/tools 38 39 .EXPORT_ALL_VARIABLES: 40 41 .DEFAULT_GOAL := presubmit 42 43 # -------------------------- 44 # Helper Commands 45 # -------------------------- 46 47 .PHONY: update-components-old 48 update-components-old: 49 grep -o github.com/open-telemetry/opentelemetry-collector-contrib/[[:lower:]]*/[[:lower:]]* go.mod | xargs -I '{}' go get {} 50 go mod tidy 51 cd $(TOOLS_DIR) && go get -u github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen 52 cd $(TOOLS_DIR) && go mod tidy 53 54 OTEL_VER ?= latest 55 .PHONY: update-components 56 update-components: 57 go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all | \ 58 grep "^go.opentelemetry.io" | \ 59 grep -v "go.opentelemetry.io/collector/featuregate" | \ 60 grep -v "go.opentelemetry.io/collector/pdata" | \ 61 xargs -t -I '{}' go get {}@$(OTEL_VER) 62 go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all | \ 63 grep "^github.com/open-telemetry/opentelemetry-collector-contrib" | \ 64 xargs -t -I '{}' go get {}@$(OTEL_VER) 65 go mod tidy 66 cd $(TOOLS_DIR) && go get -u github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen@$(OTEL_VER) 67 cd $(TOOLS_DIR) && go mod tidy 68 69 # We can bring this target back when https://github.com/open-telemetry/opentelemetry-collector/issues/8063 is resolved. 70 update-opentelemetry: 71 $(MAKE) update-components 72 $(MAKE) install-tools 73 $(MAKE) GO_BUILD_TAGS=gpu generate 74 75 # -------------------------- 76 # Tools 77 # -------------------------- 78 79 .PHONY: install-tools 80 install-tools: 81 cd $(TOOLS_DIR) && \ 82 go install \ 83 github.com/client9/misspell/cmd/misspell \ 84 github.com/golangci/golangci-lint/cmd/golangci-lint \ 85 github.com/google/addlicense \ 86 github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen \ 87 github.com/google/googet/goopack 88 89 .PHONY: addlicense 90 addlicense: 91 addlicense -c "Google LLC" -l apache $(ALL_SRC) 92 93 .PHONY: checklicense 94 checklicense: 95 @output=`addlicense -check $(ALL_SRC)` && echo checklicense finished successfully || (echo checklicense errors: $$output && exit 1) 96 97 .PHONY: lint 98 lint: 99 golangci-lint run --allow-parallel-runners --build-tags=$(GO_BUILD_TAGS) --timeout=20m 100 101 .PHONY: misspell 102 misspell: 103 @output=`misspell -error $(ALL_DOC)` && echo misspell finished successfully || (echo misspell errors:\\n$$output && exit 1) 104 105 # -------------------------- 106 # CI 107 # -------------------------- 108 109 # Adds license headers to files that are missing it, quiet tests 110 # so full output is visible at a glance. 111 .PHONY: precommit 112 precommit: addlicense lint misspell test 113 114 # Checks for the presence of required license headers, runs verbose 115 # tests for complete information in CI job. 116 .PHONY: presubmit 117 presubmit: checklicense lint misspell test_verbose 118 119 # -------------------------- 120 # Build and Test 121 # -------------------------- 122 123 GO_BUILD_OUT ?= ./bin/otelopscol 124 .PHONY: build 125 build: 126 go build -tags=$(GO_BUILD_TAGS) -o $(GO_BUILD_OUT) $(LD_FLAGS) -buildvcs=false ./cmd/otelopscol 127 128 OTELCOL_BINARY = google-cloud-metrics-agent_$(GOOS)_$(GOARCH)$(EXTENSION) 129 .PHONY: build_full_name 130 build_full_name: 131 $(MAKE) GO_BUILD_OUT=./bin/$(OTELCOL_BINARY) build 132 133 .PHONY: test 134 test: 135 go test -tags=$(GO_BUILD_TAGS) $(GO_TEST_VERBOSE) -race ./... 136 137 .PHONY: test_quiet 138 test_verbose: 139 $(MAKE) GO_TEST_VERBOSE=-v test 140 141 .PHONY: generate 142 generate: 143 go generate ./... 144 145 # -------------------- 146 # Docker 147 # -------------------- 148 149 # set default docker build image name 150 BUILD_IMAGE_NAME ?= otelopscol-build 151 BUILD_IMAGE_REPO ?= gcr.io/stackdriver-test-143416/opentelemetry-operations-collector:test 152 153 .PHONY: docker-build-image 154 docker-build-image: 155 docker build -t $(BUILD_IMAGE_NAME) .build 156 157 .PHONY: docker-push-image 158 docker-push-image: 159 docker tag $(BUILD_IMAGE_NAME) $(BUILD_IMAGE_REPO) 160 docker push $(BUILD_IMAGE_REPO) 161 162 .PHONY: docker-build-and-push 163 docker-build-and-push: docker-build-image docker-push-image 164 165 # Usage: make TARGET=<target> docker-run 166 # Example: make TARGET=build-goo docker-run 167 .PHONY: docker-run 168 docker-run: 169 ifndef TARGET 170 $(error "TARGET is undefined") 171 endif 172 docker run -e PKG_VERSION -e ARCH -v $(CURDIR):/mnt -w /mnt $(BUILD_IMAGE_NAME) /bin/bash -c "make $(TARGET)" 173 174 # -------------------- 175 # (DEPRECATED) Packaging 176 # -------------------- 177 # 178 # These targets are kept here due to their use in internal Google build jobs. 179 # These packaging formats are not maintained and likely contain issues. Do 180 # not use directly. 181 182 # googet (Windows) 183 .PHONY: build-goo 184 build-goo: 185 make GOOS=windows build_full_name package-goo 186 187 .PHONY: package-goo 188 package-goo: export GOOS=windows 189 package-goo: SHELL:=/bin/bash 190 package-goo: 191 mkdir -p dist 192 # goopack doesn't support variable replacement or command line args so just use envsubst 193 goopack -output_dir ./dist <(envsubst < ./.build/googet/google-cloud-metrics-agent.goospec) 194 chmod -R a+rwx ./dist/ 195 196 # tarball 197 .PHONY: clean-dist 198 clean-dist: 199 rm -rf dist/