GO := CGO_ENABLED=0 go

.PHONY: run fmt

testbed: install-tcctl
	tcctl testbed create -f testbed.yaml

destroy-testbed:
	tcctl testbed delete

run:
	KUBECONFIG=./kubeconfig.yml go run main.go

build:
	$(GO) build -o bin/example main.go

image:
	GOOS=linux GOARCH=amd64 make build
	docker build --platform linux/amd64 -t hub.pingcap.net/qa/example_workload_node .

fmt: groupimports
	go fmt ./...

groupimports: install-goimports
	goimports -w -l -local github.com/pingcap/test-infra .

install-goimports:
ifeq (, $(shell which goimports))
	@{ \
	set -e ;\
	TMP_DIR=$$(mktemp -d) ;\
	cd $$TMP_DIR ;\
	GO111MODULE=on go get golang.org/x/tools/cmd/goimports ;\
	rm -rf $$TMP_DIR ;\
	}
endif

install-tcctl:
ifeq (, $(shell which tcctl))
	curl http://fileserver.pingcap.net/download/pingcap/qa/test-infra/tcctl-install.sh | bash
endif
