.PHONY: all build test lint docker-build e2e-images e2e-run

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

E2E_IMG ?= service-proxy:e2e
E2E_MOCK_IMG ?= mock-server:e2e

all: lint test build

build:
	CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="-s -w" -o bin/$(BINARY_NAME)

test:
	go test -v -race -coverprofile=coverage.out ./...

lint:
	golangci-lint run -v ./...

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

e2e-images: ## Build images for SkyWalking Infra E2E
	docker build -t $(E2E_IMG) .
	docker build -t $(E2E_MOCK_IMG) -f test/e2e/mock_server/Dockerfile .

e2e-run: ## Run SkyWalking Infra E2E (KinD)
	@command -v kind >/dev/null 2>&1 || { echo "kind not installed. Install: https://kind.sigs.k8s.io/docs/user/quick-start/#installation"; exit 1; }
	@command -v kubectl >/dev/null 2>&1 || { echo "kubectl not installed. Install: https://kubernetes.io/docs/tasks/tools/"; exit 1; }
	@command -v e2e >/dev/null 2>&1 || { echo "e2e CLI not installed. See: https://github.com/apache/skywalking-infra-e2e"; exit 1; }
	e2e run -c test/e2e/e2e.yaml
