-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
80 lines (69 loc) · 2.86 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
.DEFAULT_GOAL := all
STATES_DIR=$(CURDIR)/.states
DIST_DIR=$(CURDIR)/dist
CONTAINER_IMAGE_BASE_REF="docker.elastic.co/observability-ci/apm-perf"
MODULE_DEPS=$(sort $(shell go list -deps -tags=darwin,linux,windows -f "{{with .Module}}{{if not .Main}}{{.Path}}{{end}}{{end}}" ./...))
all: test
fmt: tools/go.mod
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -license=Elasticv2 -exclude internal/telemetrygen .
@go run -modfile=tools/go.mod golang.org/x/tools/cmd/goimports -local github.com/elastic/ -w .
lint: tools/go.mod
go run -modfile=tools/go.mod honnef.co/go/tools/cmd/staticcheck -checks=all ./...
go list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
-includeIndirect \
-rules tools/notice/rules.json
go mod tidy && git diff --exit-code
.PHONY: clean
clean:
rm -fr bin
.PHONY: build
build: COMMIT_SHA=$$(git rev-parse HEAD)
build: CURRENT_TIME_ISO=$$(date -u +"%Y-%m-%dT%H:%M:%SZ")
build: LDFLAGS=-X 'github.com/elastic/apm-perf/internal/version.commitSha=$(COMMIT_SHA)'
build: LDFLAGS+=-X 'github.com/elastic/apm-perf/internal/version.buildTime=$(CURRENT_TIME_ISO)'
build:
mkdir -p $(DIST_DIR)
go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/apmsoak cmd/apmsoak/*.go
go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/apmbench cmd/apmbench/*.go
go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/apmtelemetrygen cmd/apmtelemetrygen/*.go
.PHONY: test
test: go.mod
go test -race -v ./...
.PHONY: package
package: BASE_IMAGE_VERSION=$$(cat .go-version)
package: COMMIT_SHA_SHORT=$$(git rev-parse --short HEAD)
package: COMMIT_SHA=$$(git rev-parse HEAD)
package: CURRENT_TIME_ISO=$$(date -u +"%Y-%m-%dT%H:%M:%SZ")
package: CURRENT_TIME=$$(date +%s)
package: IMAGE_ID=$${IMAGE_VERSION:-latest}-$(CURRENT_TIME)-$(COMMIT_SHA_SHORT)
package: IMAGE_REF=$(CONTAINER_IMAGE_BASE_REF):$(IMAGE_ID)
package: PROJECT_URL=$$(go list -m all | head -1)
package:
mkdir -p $(STATES_DIR)
echo "$(IMAGE_REF)" > "$(STATES_DIR)/image_ref"
docker build \
--build-arg base_image_version=$(BASE_IMAGE_VERSION) \
--build-arg commit_sha=$(COMMIT_SHA) \
--build-arg current_time=$(CURRENT_TIME_ISO) \
--build-arg image_id=$(IMAGE_ID) \
--build-arg project_url=$(PROJECT_URL) \
-t $$(cat "$(STATES_DIR)/image_ref") \
-f Containerfile \
.
.PHONY: sanitize
sanitize: IMAGE_REF=$$(cat "$(STATES_DIR)/image_ref")
sanitize:
docker run --rm $(IMAGE_REF) apmsoak version
.PHONY: publish`
publish: IMAGE_REF=$$(cat "$(STATES_DIR)/image_ref")
publish:
docker push $(IMAGE_REF)
docker tag $(IMAGE_REF) $(CONTAINER_IMAGE_BASE_REF):latest
docker push $(CONTAINER_IMAGE_BASE_REF):latest
notice: NOTICE.txt
NOTICE.txt: go.mod tools/go.mod
go list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
-includeIndirect \
-rules tools/notice/rules.json \
-noticeTemplate tools/notice/NOTICE.txt.tmpl \
-noticeOut NOTICE.txt