-
Notifications
You must be signed in to change notification settings - Fork 166
/
Makefile
129 lines (101 loc) · 4.75 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
SHELL=/bin/bash -o pipefail
GO ?= go
DOCKER ?= docker
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
GIT_COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2> /dev/null),${COMMIT_NO}-dirty,${COMMIT_NO})
GIT_TAG ?= $(shell git describe 2> /dev/null)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
GIT_ORG ?= iovisor
DOCKER_BUILD_PROGRESS ?= auto
IMAGE_NAME_INITCONTAINER ?= quay.io/$(GIT_ORG)/kubectl-trace-init
IMAGE_NAME_TRACERUNNER ?= quay.io/$(GIT_ORG)/kubectl-trace-runner
IMAGE_TRACERUNNER_BRANCH := $(IMAGE_NAME_TRACERUNNER):$(GIT_BRANCH_CLEAN)
IMAGE_TRACERUNNER_COMMIT := $(IMAGE_NAME_TRACERUNNER):$(GIT_COMMIT)
IMAGE_TRACERUNNER_TAG := $(IMAGE_NAME_TRACERUNNER):$(GIT_TAG)
IMAGE_TRACERUNNER_LATEST := $(IMAGE_NAME_TRACERUNNER):latest
IMAGE_INITCONTAINER_BRANCH := $(IMAGE_NAME_INITCONTAINER):$(GIT_BRANCH_CLEAN)
IMAGE_INITCONTAINER_COMMIT := $(IMAGE_NAME_INITCONTAINER):$(GIT_COMMIT)
IMAGE_INITCONTAINER_TAG := $(IMAGE_NAME_INITCONTAINER):$(GIT_TAG)
IMAGE_INITCONTAINER_LATEST := $(IMAGE_NAME_INITCONTAINER):latest
IMAGE_BUILD_FLAGS_EXTRA ?= # convenience to allow to specify extra build flags with env var, defaults to nil
IMG_REPO ?= quay.io/iovisor/
IMG_SHA ?= latest
BPFTRACEVERSION ?= "v0.19.1"
LDFLAGS := -ldflags '-X github.com/iovisor/kubectl-trace/pkg/version.buildTime=$(shell date +%s) -X github.com/iovisor/kubectl-trace/pkg/version.gitCommit=${GIT_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.ImageName=${IMAGE_NAME_TRACERUNNER} -X github.com/iovisor/kubectl-trace/pkg/cmd.ImageTag=${GIT_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.InitImageName=${IMAGE_NAME_INITCONTAINER} -X github.com/iovisor/kubectl-trace/pkg/cmd.InitImageTag=${GIT_COMMIT}'
TESTPACKAGES := $(shell go list ./... | grep -v github.com/iovisor/kubectl-trace/integration)
TEST_ONLY ?=
kubectl_trace ?= _output/bin/kubectl-trace
trace_runner ?= _output/bin/trace-runner
trace_uploader ?= _output/bin/trace-uploader
# ensure variables are available to child invocations of make
export
.PHONY: build
build: clean ${kubectl_trace}
${kubectl_trace}:
CGO_ENABLED=1 $(GO) build ${LDFLAGS} -o $@ ./cmd/kubectl-trace
${trace_runner}:
CGO_ENABLED=1 $(GO) build ${LDFLAGS} -o $@ ./cmd/trace-runner
${trace_uploader}:
CGO_ENABLED=1 $(GO) build ${LDFLAGS} -o $@ ./cmd/trace-uploader
.PHONY: cross
cross:
IMAGE_NAME_TRACERUNNER=$(IMAGE_NAME_TRACERUNNER) GO111MODULE=on goreleaser --snapshot --clean
.PHONY: release
release:
IMAGE_NAME_TRACERUNNER=$(IMAGE_NAME_TRACERUNNER) GO111MODULE=on goreleaser --clean
.PHONY: clean
clean:
$(RM) -R _output
$(RM) -R dist
.PHONY: image/build-init
image/build-init:
$(DOCKER) build \
--progress=$(DOCKER_BUILD_PROGRESS) \
-t $(IMAGE_INITCONTAINER_BRANCH) \
-f ./build/Dockerfile.initcontainer \
${IMAGE_BUILD_FLAGS_EXTRA} \
./build
$(DOCKER) tag "$(IMAGE_INITCONTAINER_BRANCH)" "$(IMAGE_INITCONTAINER_COMMIT)"
$(DOCKER) tag "$(IMAGE_INITCONTAINER_BRANCH)" "$(IMAGE_INITCONTAINER_TAG)"
$(DOCKER) tag "$(IMAGE_INITCONTAINER_BRANCH)" "$(IMAGE_INITCONTAINER_LATEST)"
.PHONY: image/build
image/build:
DOCKER_BUILDKIT=1 $(DOCKER) build \
--build-arg bpftraceversion=$(BPFTRACEVERSION) \
--build-arg GIT_ORG=$(GIT_ORG) \
--progress=$(DOCKER_BUILD_PROGRESS) \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from "$(IMAGE_TRACERUNNER_BRANCH)" \
-t "$(IMAGE_TRACERUNNER_BRANCH)" \
-f build/Dockerfile.tracerunner \
${IMAGE_BUILD_FLAGS_EXTRA} \
.
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" "$(IMAGE_TRACERUNNER_COMMIT)"
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" "$(IMAGE_TRACERUNNER_TAG)"
$(DOCKER) tag "$(IMAGE_TRACERUNNER_BRANCH)" "$(IMAGE_TRACERUNNER_LATEST)"
.PHONY: image/integration-support
image/integration-support: image/ruby-target
.PHONY: image/ruby-target
image/ruby-target:
make -C build/test/ruby image/ruby-target
.PHONY: image/push
image/push:
$(DOCKER) push $(IMAGE_TRACERUNNER_BRANCH)
$(DOCKER) push $(IMAGE_TRACERUNNER_COMMIT)
$(DOCKER) push $(IMAGE_TRACERUNNER_TAG)
$(DOCKER) push $(IMAGE_INITCONTAINER_BRANCH)
$(DOCKER) push $(IMAGE_INITCONTAINER_COMMIT)
$(DOCKER) push $(IMAGE_INITCONTAINER_TAG)
.PHONY: image/latest
image/latest:
$(DOCKER) tag $(IMAGE_TRACERUNNER_COMMIT) $(IMAGE_TRACERUNNER_LATEST)
$(DOCKER) push $(IMAGE_TRACERUNNER_LATEST)
$(DOCKER) tag $(IMAGE_INITCONTAINER_COMMIT) $(IMAGE_INITCONTAINER_LATEST)
$(DOCKER) push $(IMAGE_INITCONTAINER_LATEST)
.PHONY: test
test:
$(GO) test -v -race $(TESTPACKAGES)
.PHONY: integration
integration: build image/build image/build-init image/integration-support
TEST_KUBECTLTRACE_BINARY=$(shell pwd)/$(kubectl_trace) $(GO) test ${LDFLAGS} -failfast -count=1 -v ./integration/... -run TestKubectlTraceSuite $(if $(TEST_ONLY),-testify.m $(TEST_ONLY),)