forked from wavefrontHQ/wavefront-collector-for-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
96 lines (72 loc) · 3.24 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
PREFIX?=wavefronthq
DOCKER_IMAGE=wavefront-kubernetes-collector
ARCH?=amd64
REPO_DIR=$(shell git rev-parse --show-toplevel)
KUSTOMIZE_DIR=$(REPO_DIR)/hack/kustomize
DEPLOY_DIR=$(REPO_DIR)/hack/deploy
OUT_DIR?=$(REPO_DIR)/_output
GOLANG_VERSION?=1.15
BINARY_NAME=wavefront-collector
ifndef TEMP_DIR
TEMP_DIR:=$(shell mktemp -d /tmp/wavefront.XXXXXX)
endif
VERSION?=1.3.3
GIT_COMMIT:=$(shell git rev-parse --short HEAD)
# for testing, the built image will also be tagged with this name provided via an environment variable
OVERRIDE_IMAGE_NAME?=${COLLECTOR_TEST_IMAGE}
LDFLAGS=-w -X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT)
all: container
fmt:
find . -type f -name "*.go" | grep -v "./vendor*" | xargs gofmt -s -w
tests:
go clean -testcache
go test -timeout 30s -race ./...
build: clean fmt
go vet -composites=false ./...
GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(ARCH)/$(BINARY_NAME) ./cmd/wavefront-collector/
# test driver for local development
driver: clean fmt
GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(ARCH)/$(BINARY_NAME)-test ./cmd/test-driver/
container:
# Run build in a container in order to have reproducible builds
docker run --rm -v $(TEMP_DIR):/build -v $(REPO_DIR):/go/src/github.com/wavefronthq/wavefront-collector-for-kubernetes -w /go/src/github.com/wavefronthq/wavefront-collector-for-kubernetes golang:$(GOLANG_VERSION) /bin/bash -c "\
cp /etc/ssl/certs/ca-certificates.crt /build \
&& GOARCH=$(ARCH) CGO_ENABLED=0 go build -ldflags \"$(LDFLAGS)\" -o /build/$(BINARY_NAME) github.com/wavefronthq/wavefront-collector-for-kubernetes/cmd/wavefront-collector/"
cp deploy/docker/Dockerfile $(TEMP_DIR)
docker build --pull -t $(PREFIX)/$(DOCKER_IMAGE):$(VERSION) $(TEMP_DIR)
rm -rf $(TEMP_DIR)
ifneq ($(OVERRIDE_IMAGE_NAME),)
docker tag $(PREFIX)/$(DOCKER_IMAGE):$(VERSION) $(OVERRIDE_IMAGE_NAME)
endif
redeploy: token-check
(cd $(KUSTOMIZE_DIR) && ./deploy.sh -c nimba -t ${WAVEFRONT_API_KEY} -v ${VERSION} -i "$(PREFIX)\/$(DOCKER_IMAGE)")
deploy-targets:
(cd $(DEPLOY_DIR) && ./deploy-targets.sh)
output-test: token-check
docker exec -it kind-control-plane crictl rmi $(PREFIX)/$(DOCKER_IMAGE):$(VERSION) || true
kind load docker-image $(PREFIX)/$(DOCKER_IMAGE):$(VERSION) --name kind
(cd $(KUSTOMIZE_DIR) && ./test.sh nimba $(WAVEFRONT_API_KEY) $(VERSION))
token-check:
if [ -z ${WAVEFRONT_API_KEY} ]; then echo "Need to set WAVEFRONT_API_KEY" && exit 1; fi
full-loop: token-check build tests container output-test
nuke-loop: token-check nuke-kind deploy-targets full-loop
nuke-kind:
kind delete cluster
kind create cluster
k9s:
watch -n 1 k9s
#This rule need to be run on RHEL with podman installed.
container_rhel: build
cp $(OUT_DIR)/$(ARCH)/$(BINARY_NAME) $(TEMP_DIR)
cp LICENSE $(TEMP_DIR)/license.txt
cp deploy/docker/Dockerfile-rhel $(TEMP_DIR)/Dockerfile
cp deploy/examples/openshift-config.yaml $(TEMP_DIR)/collector.yaml
sudo docker build --pull -t $(PREFIX)/$(DOCKER_IMAGE):$(VERSION) $(TEMP_DIR)
rm -rf $(TEMP_DIR)
ifneq ($(OVERRIDE_IMAGE_NAME),)
sudo docker tag $(PREFIX)/$(DOCKER_IMAGE):$(VERSION) $(OVERRIDE_IMAGE_NAME)
endif
clean:
rm -f $(OUT_DIR)/$(ARCH)/$(BINARY_NAME)
rm -f $(OUT_DIR)/$(ARCH)/$(BINARY_NAME)-test
.PHONY: all fmt container clean