GO := CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go

SHELL=bash

.PHONY: run fmt

testbed: #install-tcctl
	tcctl testbed create -f testbed.yaml
	echo 'TI_PARAM_STR_br_opts: {"storage":"s3://tmp/br-backup-basic?access-key=minioadmin&secret-access-key=minioadmin&endpoint=http%3a%2f%2fminio.pingcap.net%3a9000&force-path-style=true","timeout":"10m","crc32-checksum":0}' >> .env
	echo 'TI_PARAM_STR_mc_rm_opts: {"path":"qa-minio/tmp/br-backup-basic","timeout":"10m"}' >> .env
	echo 'TI_PARAM_STR_version: nightly' >> .env
destroy-testbed:
	tcctl testbed delete

run:
	KUBECONFIG=kubeconfig.yml MYSQL_PROXY=socks5://rms-staging.pingcap.net:30081 go run main.go

build:
	$(GO) build -trimpath -o ./case main.go

image:
	GOOS=linux GOARCH=amd64 make build
	docker build -t hub.pingcap.net/qa/br-tiup-basic .
	docker image push hub.pingcap.net/qa/br-tiup-basic

apply:
	tcctl apply -f cases.yaml

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-testbed-cli:
	go install github.com/pingcap/test-infra/services/rms/cmd/testbed@latest

