forked from GoogleCloudPlatform/run-gmp-sidecar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
164 lines (130 loc) · 5.21 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
# read PKG_VERSION from VERSION file
include VERSION
# if GOOS is not supplied, set default value based on user's system, will be overridden for OS specific packaging commands
GOOS ?= $(shell go env GOOS)
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) -type f | sort)
GIT_SHA := $(shell git rev-parse --short HEAD)
BUILD_INFO_IMPORT_PATH := github.com/GoogleCloudPlatform/run-gmp-sidecar/collector/internal/version
ENTRYPOINT_BUILD_INFO_IMPORT_PATH := github.com/GoogleCloudPlatform/run-gmp-sidecar/confgenerator
BUILD_X1 := -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA)
BUILD_X2 := -X $(BUILD_INFO_IMPORT_PATH).Version=$(PKG_VERSION)
BUILD_X3 := -X $(ENTRYPOINT_BUILD_INFO_IMPORT_PATH).Version=$(PKG_VERSION)
LD_FLAGS := -ldflags "${BUILD_X1} ${BUILD_X2} ${BUILD_X3}"
TOOLS_DIR := collector/internal/tools
.EXPORT_ALL_VARIABLES:
.DEFAULT_GOAL := presubmit
# --------------------------
# Helper Commands
# --------------------------
.PHONY: update-components-old
update-components-old:
grep -o github.com/open-telemetry/opentelemetry-collector-contrib/[[:lower:]]*/[[:lower:]]* go.mod | xargs -I '{}' go get {}
go mod tidy
cd $(TOOLS_DIR) && go get -u github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen
cd $(TOOLS_DIR) && go mod tidy
OTEL_VER ?= latest
.PHONY: update-components
update-components:
go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all | \
grep "^go.opentelemetry.io" | \
xargs -t -I '{}' go get {}@$(OTEL_VER)
go get -u github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus@latest
go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all | \
grep "^github.com/open-telemetry/opentelemetry-collector-contrib" | \
xargs -t -I '{}' go get {}@$(OTEL_VER)
go mod tidy
cd $(TOOLS_DIR) && go get -u github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen
cd $(TOOLS_DIR) && go mod tidy
# We can bring this target back when https://github.com/open-telemetry/opentelemetry-collector/issues/8063 is resolved.
update-opentelemetry:
$(MAKE) update-components
$(MAKE) install-tools
$(MAKE) GO_BUILD_TAGS=gpu generate
# --------------------------
# Tools
# --------------------------
.PHONY: install-tools
install-tools:
cd $(TOOLS_DIR) && \
go install \
github.com/client9/misspell/cmd/misspell \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/google/addlicense \
github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen
.PHONY: addlicense
addlicense:
addlicense -c "Google LLC" -l apache ./**/*.go
.PHONY: checklicense
checklicense:
@output=`addlicense -check ./**/*.go` && echo checklicense finished successfully || (echo checklicense errors: $$output && exit 1)
.PHONY: lint
lint:
golangci-lint run --allow-parallel-runners --build-tags=$(GO_BUILD_TAGS) --timeout=20m
.PHONY: misspell
misspell:
@output=`misspell -error $(ALL_DOC)` && echo misspell finished successfully || (echo misspell errors:\\n$$output && exit 1)
# --------------------------
# CI
# --------------------------
# Adds license headers to files that are missing it, quiet tests
# so full output is visible at a glance.
.PHONY: precommit
precommit: addlicense lint misspell test
# Checks for the presence of required license headers, runs verbose
# tests for complete information in CI job.
.PHONY: presubmit
presubmit: checklicense lint misspell test_verbose
# --------------------------
# Build and Test
# --------------------------
GO_BUILD_OUT ?= ./bin/rungmpcol
.PHONY: build-collector
build-collector:
CGO_ENABLED=0 go build -tags=$(GO_BUILD_TAGS) -o $(GO_BUILD_OUT) $(LD_FLAGS) -buildvcs=false ./collector/cmd/rungmpcol
OTELCOL_BINARY = google-cloud-run-gmp-sidecar-$(GOOS)
.PHONY: build-collector-full-name
build-collector-full-name:
$(MAKE) GO_BUILD_OUT=./bin/$(OTELCOL_BINARY) build-collector
ENTRYPOINT_BINARY = run-gmp-entrypoint
.PHONY: build-run-gmp-entrypoint
build-run-gmp-entrypoint:
CGO_ENABLED=0 go build -tags=$(GO_BUILD_TAGS) -o ./bin/$(ENTRYPOINT_BINARY) $(LD_FLAGS) -buildvcs=false entrypoint.go
.PHONY: build
build:
$(MAKE) build-collector
$(MAKE) build-run-gmp-entrypoint
.PHONY: test
test:
$(MAKE) build-collector
go test -tags=$(GO_BUILD_TAGS) $(GO_TEST_VERBOSE) -p 1 -race ./...
.PHONY: test_quiet
test_verbose:
$(MAKE) GO_TEST_VERBOSE=-v test
.PHONY: test_update
test_update:
go test ./confgenerator -update
.PHONY: generate
generate:
go generate ./...
# --------------------
# Docker
# --------------------
# set default docker build image name
BUILD_IMAGE_NAME ?= rungmpcol-build
BUILD_IMAGE_REPO ?= gcr.io/stackdriver-test-143416/opentelemetry-operations-collector:test
.PHONY: docker-build-image
docker-build-image:
docker build -t $(BUILD_IMAGE_NAME) .
.PHONY: docker-push-image
docker-push-image:
docker tag $(BUILD_IMAGE_NAME) $(BUILD_IMAGE_REPO)
docker push $(BUILD_IMAGE_REPO)
.PHONY: docker-build-and-push
docker-build-and-push: docker-build-image docker-push-image
# Usage: make TARGET=<target> docker-run
# Example: make TARGET=build-collector docker-run
TARGET ?= build_collector
.PHONY: docker-run
docker-run:
docker run -e PKG_VERSION -v $(CURDIR):/mnt -w /mnt $(BUILD_IMAGE_NAME) /bin/bash -c "make $(TARGET)"