IMG ?= cluster-proxy:local
GOOS ?= "linux"
GOARCH ?= $(shell go env GOARCH)

.PHONY: build dev docker-build test e2e version-check

check: version-check build test
	go mod tidy

dev: build test

build:
	CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="-s -w" -o bin/proxy cmd/proxy/main.go

docker-build: build
	docker build . -t $(IMG)

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.8.0
golangci-lint:
	@[ -f $(GOLANGCI_LINT) ] || { \
	set -e ;\
	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
	}

.PHONY: lint
lint: golangci-lint
	$(GOLANGCI_LINT) run --timeout 20m --config ./.golangci.yml

test: build
	go test -short ./...

e2e:
	./scripts/run-e2e.sh

version-check:
	./scripts/version-check.sh

local-build-image: build
	docker build -f ./local/Dockerfile_local . -t ${IMG}

local-push-image: ## Push the config-manager docker image.
	docker push ${IMG}
