forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
317 lines (281 loc) · 10.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
## Build, test, and generate code for various parts of Grafana Agent.
##
## At least Go 1.18, git, and a moderately recent version of Docker is required
## to be able to use the Makefile. This list isn't exhaustive and there are other
## dependencies for the generate-* targets. If you do not have the full list of
## build dependencies, you may set USE_CONTAINER=1 to proxy build commands to a
## build container.
##
## Other environment variables can be used to tweak behaviors of targets.
## See the bottom of this help section for the full list of supported
## environment variables.
##
## Usage:
## make <target>
##
## Targets for running tests:
##
## test Run tests
## lint Lint code
##
## Targets for building binaries:
##
## binaries Compiles all binaries.
## agent Compiles cmd/agent to $(AGENT_BINARY)
## agentctl Compiles cmd/agentctl to $(AGENTCTL_BINARY)
## operator Compiles cmd/agent-operator to $(OPERATOR_BINARY)
## crow Compiles tools/crow to $(CROW_BINARY)
## smoke Compiles tools/smoke to $(SMOKE_BINARY)
##
## Targets for building Docker images:
##
## images Builds all Docker images.
## agent-image Builds agent Docker image.
## agentctl-image Builds agentctl Docker image.
## operator-image Builds operator Docker image.
## crow-image Builds crow Docker image.
## smoke-image Builds smoke test Docker image.
##
## Targets for packaging:
##
## dist Produce release assets for everything.
## dist-agent-binaries Produce release-ready agent binaries.
## dist-agentctl-binaries Produce release-ready agentctl binaries.
## dist-packages Produce release-ready DEB and RPM packages.
## dist-agent-installer Produce a Windows installer for Grafana Agent.
##
## Targets for generating assets:
##
## generate Generate everything.
## generate-crds Generate Grafana Agent Operator CRDs ands its documentation.
## generate-manifests Generate production/kubernetes YAML manifests.
## generate-dashboards Generate dashboards in example/docker-compose after
## changing Jsonnet.
## generate-protos Generate protobuf files.
## generate-ui Generate the UI assets.
##
## Other targets:
##
## build-container-cache Create a cache for the build container to speed up
## subsequent proxied builds
## drone Sign Drone CI config (maintainers only)
## clean Clean caches and built binaries
## help Displays this message
## info Print Makefile-specific environment variables
##
## Environment variables:
##
## USE_CONTAINER Set to 1 to enable proxying commands to build container
## AGENT_IMAGE Image name:tag built by `make agent-image`
## AGENTCTL_IMAGE Image name:tag built by `make agentctl-image`
## OPERATOR_IMAGE Image name:tag built by `make operator-image`
## CROW_IMAGE Image name:tag built by `make crow-image`
## SMOKE_IMAGE Image name:tag built by `make smoke-image`
## BUILD_IMAGE Image name:tag used by USE_CONTAINER=1
## AGENT_BINARY Output path of `make agent` (default build/agent)
## AGENTCTL_BINARY Output path of `make agentctl` (default build/agentctl)
## OPERATOR_BINARY Output path of `make operator` (default build/agent-operator)
## CROW_BINARY Output path of `make crow` (default build/agent-crow)
## SMOKE_BINARY Output path of `make smoke` (default build/agent-smoke)
## GOOS Override OS to build binaries for
## GOARCH Override target architecture to build binaries for
## GOARM Override ARM version (6 or 7) when GOARCH=arm
## CGO_ENABLED Set to 0 to disable Cgo for builds
## RELEASE_BUILD Set to 1 to build release binaries
## VERSION Version to inject into built binaries.
## GO_TAGS Extra tags to use when building.
## DOCKER_PLATFORM Overrides platform to build Docker images for (defaults to host platform).
include tools/make/*.mk
AGENT_IMAGE ?= grafana/agent:latest
AGENTCTL_IMAGE ?= grafana/agentctl:latest
OPERATOR_IMAGE ?= grafana/agent-operator:latest
CROW_IMAGE ?= us.gcr.io/kubernetes-dev/grafana/agent-crow:latest
SMOKE_IMAGE ?= us.gcr.io/kubernetes-dev/grafana/agent-smoke:latest
AGENT_BINARY ?= build/agent
AGENTCTL_BINARY ?= build/agentctl
OPERATOR_BINARY ?= build/agent-operator
CROW_BINARY ?= build/agent-crow
SMOKE_BINARY ?= build/agent-smoke
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOARM ?= $(shell go env GOARM)
CGO_ENABLED ?= 1
RELEASE_BUILD ?= 0
# List of all environment variables which will propagate to the build
# container. USE_CONTAINER must _not_ be included to avoid infinite recursion.
PROPAGATE_VARS := \
AGENT_IMAGE AGENTCTL_IMAGE OPERATOR_IMAGE CROW_IMAGE SMOKE_IMAGE \
BUILD_IMAGE GOOS GOARCH GOARM CGO_ENABLED RELEASE_BUILD \
AGENT_BINARY AGENTCTL_BINARY OPERATOR_BINARY CROW_BINARY SMOKE_BINARY \
VERSION GO_TAGS
#
# Constants for targets
#
GO_ENV := GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=$(CGO_ENABLED)
VERSION ?= $(shell ./tools/image-tag)
GIT_REVISION := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VPREFIX := github.com/grafana/agent/pkg/build
GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) \
-X $(VPREFIX).Version=$(VERSION) \
-X $(VPREFIX).Revision=$(GIT_REVISION) \
-X $(VPREFIX).BuildUser=$(shell whoami)@$(shell hostname) \
-X $(VPREFIX).BuildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
DEFAULT_FLAGS := $(GO_FLAGS)
DEBUG_GO_FLAGS := -ldflags "$(GO_LDFLAGS)" -tags "netgo $(GO_TAGS)"
RELEASE_GO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags "netgo $(GO_TAGS)"
ifeq ($(RELEASE_BUILD),1)
GO_FLAGS := $(DEFAULT_FLAGS) $(RELEASE_GO_FLAGS)
else
GO_FLAGS := $(DEFAULT_FLAGS) $(DEBUG_GO_FLAGS)
endif
#
# Targets for running tests
#
# These targets currently don't support proxying to a build container due to
# difficulties with testing ./pkg/util/k8s and testing packages.
#
.PHONY: lint
lint:
golangci-lint run -v --timeout=10m
.PHONY: test
# We have to run test twice: once for all packages with -race and then once
# more without -race for packages that have known race detection issues.
test:
$(GO_ENV) go test $(GO_FLAGS) -race ./...
$(GO_ENV) go test $(GO_FLAGS) ./pkg/integrations/node_exporter ./pkg/logs ./pkg/operator ./pkg/util/k8s
test-packages:
docker pull $(BUILD_IMAGE)
go test -tags=packaging ./packaging
#
# Targets for building binaries
#
.PHONY: binaries agent agentctl operator crow smoke
binaries: agent agentctl operator crow smoke
agent:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(AGENT_BINARY) ./cmd/agent
endif
agentctl:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(AGENTCTL_BINARY) ./cmd/agentctl
endif
operator:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(OPERATOR_BINARY) ./cmd/agent-operator
endif
crow:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(CROW_BINARY) ./tools/crow
endif
smoke:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(SMOKE_BINARY) ./tools/smoke
endif
#
# Targets for building Docker images
#
DOCKER_FLAGS := --build-arg RELEASE_BUILD=$(RELEASE_BUILD) --build-arg VERSION=$(VERSION)
ifneq ($(DOCKER_PLATFORM),)
DOCKER_FLAGS += --platform=$(DOCKER_PLATFORM)
endif
.PHONY: images agent-image agentctl-image operator-image crow-image smoke-image
images: agent-image agentctl-image operator-image crow-image smoke-image
agent-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(AGENT_IMAGE) -f cmd/agent/Dockerfile .
agentctl-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(AGENTCTL_IMAGE) -f cmd/agentctl/Dockerfile .
operator-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(OPERATOR_IMAGE) -f cmd/agent-operator/Dockerfile .
crow-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(CROW_IMAGE) -f tools/crow/Dockerfile .
smoke-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(SMOKE_IMAGE) -f tools/smoke/Dockerfile .
#
# Targets for generating assets
#
.PHONY: generate generate-crds generate-manifests generate-dashboards generate-protos generate-ui
generate: generate-crds generate-manifests generate-dashboards generate-protos generate-ui
generate-crds:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
bash ./tools/generate-crds.bash
gen-crd-api-reference-docs -config tools/gen-crd-docs/config.json -api-dir "github.com/grafana/agent/pkg/operator/apis/monitoring/" -out-file docs/sources/operator/api.md -template-dir tools/gen-crd-docs/template
endif
generate-manifests:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
cd production/kubernetes/build && bash build.sh
endif
generate-dashboards:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
cd example/docker-compose && jb install && \
cd grafana/dashboards && jsonnet template.jsonnet -J ../../vendor -m .
endif
generate-protos:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
go generate ./pkg/agentproto/
endif
generate-ui:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
cd ./web/ui && yarn && yarn run build
endif
#
# Other targets
#
# build-container-cache and clean-build-container-cache are defined in
# Makefile.build-container.
# Drone signs the yaml, you will need to specify DRONE_TOKEN, which can be
# found by logging into your profile in Drone.
#
# This will only work for maintainers.
.PHONY: drone
drone:
drone lint .drone/drone.yml --trusted
drone --server https://drone.grafana.net sign --save grafana/agent .drone/drone.yml
.PHONY: clean
clean: clean-dist clean-build-container-cache
rm -rf ./build/*
.PHONY: info
info:
@printf "USE_CONTAINER = $(USE_CONTAINER)\n"
@printf "AGENT_IMAGE = $(AGENT_IMAGE)\n"
@printf "AGENTCTL_IMAGE = $(AGENTCTL_IMAGE)\n"
@printf "OPERATOR_IMAGE = $(OPERATOR_IMAGE)\n"
@printf "CROW_IMAGE = $(CROW_IMAGE)\n"
@printf "SMOKE_IMAGE = $(SMOKE_IMAGE)\n"
@printf "BUILD_IMAGE = $(BUILD_IMAGE)\n"
@printf "AGENT_BINARY = $(AGENT_BINARY)\n"
@printf "AGENTCTL_BINARY = $(AGENTCTL_BINARY)\n"
@printf "OPERATOR_BINARY = $(OPERATOR_BINARY)\n"
@printf "CROW_BINARY = $(CROW_BINARY)\n"
@printf "SMOKE_BINARY = $(SMOKE_BINARY)\n"
@printf "GOOS = $(GOOS)\n"
@printf "GOARCH = $(GOARCH)\n"
@printf "GOARM = $(GOARM)\n"
@printf "CGO_ENABLED = $(CGO_ENABLED)\n"
@printf "RELEASE_BUILD = $(RELEASE_BUILD)\n"
@printf "VERSION = $(VERSION)\n"
@printf "GO_TAGS = $(GO_TAGS)\n"
# awk magic to print out the comment block at the top of this file.
.PHONY: help
help:
@awk 'BEGIN {FS="## "} /^##\s*(.*)/ { print $$2 }' $(MAKEFILE_LIST)