<commit_before>
# Must define:
# CLUSTER_NAME
# PROJECT_ID
# CLUSTER_LOCATION

ROOT_DIR?=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
OUT?=${ROOT_DIR}/../out/krun

-include .local.mk

PROJECT_ID?=wlhe-cr
export PROJECT_ID


CLUSTER_NAME?=istio
export CLUSTER_NAME

# also mcp-prod - setup for multi-project
CONFIG_PROJECT_ID?=${PROJECT_ID}
# mesh-config-1
CONFIG_CLUSTER_NAME?=${CLUSTER_NAME}

# If the project is part of a multi-project, this is the hub id.
FLEET_ID?=${CONFIG_PROJECT_ID}
export FLEET_ID


# Region where the cloudrun services are running
REGION?=us-central1
export REGION

CLUSTER_LOCATION?=us-central1-c
export CLUSTER_LOCATION


TAG ?= latest
export TAG

# Derived values

REPO?=gcr.io/${PROJECT_ID}

DOCKER_REPO?=gcr.io/${PROJECT_ID}/krun
export DOCKER_REPO

KRUN_IMAGE?=${DOCKER_REPO}:${TAG}

HGATE_IMAGE?=${DOCKER_REPO}/gate:${TAG}

WORKLOAD_NAME?=fortio-cr
WORKLOAD_NAMESPACE?=fortio

CLOUDRUN_SERVICE_ACCOUNT=k8s-${WORKLOAD_NAMESPACE}@${PROJECT_ID}.<EMAIL>

ISTIO_HUB?=gcr.io/istio-testing
export ISTIO_HUB
ISTIO_TAG?=latest

# Also possible to use 1.11.2
ISTIO_PROXY_IMAGE?=${ISTIO_HUB}/proxyv2:latest

FORTIO_IMAGE?=${REPO}/fortio-mesh:${TAG}
export FORTIO_IMAGE
export HGATE_IMAGE

# Build krun, fortio, push fortio, deploy to main test cloudrun config
# Expects Istio cluster and in-cluster fortio to be running
all: build build/krun build/fortio push/fortio deploy/fortio

# Build, push, deploy hgate.
all-hgate: build docker/hgate push/hgate deploy/hgate

deploy/hgate:
	mkdir -p ${OUT}/manifests
	echo ${HGATE_IMAGE}
	cat manifests/kustomization-tmpl.yaml | envsubst > ${OUT}/manifests/kustomization.yaml
	cp -a manifests/hgate ${OUT}/manifests
	kubectl apply -k ${OUT}/manifests
	#kubectl apply -f manifests/hgate/
	kubectl rollout restart deployment hgate -n istio-system
	kubectl wait deployments hgate -n istio-system --for=condition=available

# Remove the namespaces and apps, for testing 'clean install'
cluster/clean:
	helm delete -n istio-system istiod
	kubectl delete -k manifests/
	kubectl delete ns istio-system || true
	kubectl delete ns fortio || true
	kubectl delete ns test || true

test:
	go test -timeout 2m -v ./...

# Build all binaries in one step - faster.
# Static build so it works with 'scratch' and not dependent on distro
build:
	mkdir -p ${OUT}/bin/
	mkdir -p ${OUT}/docker-hgate
	mkdir -p ${OUT}/docker-krun
	CGO_ENABLED=0  time  go build -ldflags '-s -w -extldflags "-static"' -o ${OUT}/bin/ ./cmd/hbone/ ./cmd/krun ./cmd/hgate
	ls -l ${OUT}/bin
	mv ${OUT}/bin/krun ${OUT}/docker-krun
	mv ${OUT}/bin/hgate ${OUT}/docker-hgate

# Build and tag krun image locally, will be used in the next phase and for local testing, no push

build/fortio: build/krun
	(cd samples/fortio; GOLDEN_IMAGE=${KRUN_IMAGE} make image)

build/krun: docker/krun


build/hgate: docker/hgate

docker/hgate:
	time docker build ${OUT}/docker-hgate -f tools/docker/Dockerfile.meshcon -t ${HGATE_IMAGE}

docker/krun:
	time docker build ${OUT}/docker-krun -f tools/docker/Dockerfile.golden -t ${KRUN_IMAGE}

test/e2e: CR_URL=$(shell gcloud run services describe ${WORKLOAD_NAME} --region ${REGION} --project ${PROJECT_ID} --format="value(status.address.url)")
test/e2e:
	curl  -v  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Ffortio.fortio.svc%3A8080%2Fecho
	curl  -v  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Ffortio.fortio-mcp.svc%3A8080%2Fecho
	curl  -v  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Fhttpbin.httpbin.svc%3A8000%2Fheaders
    #curl  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Flocalhost%3A15000%2Fconfig_dump

#### Pushing images
<commit_msg>Copy TD script files in make<commit_after>
# Must define:
# CLUSTER_NAME
# PROJECT_ID
# CLUSTER_LOCATION

ROOT_DIR?=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
OUT?=${ROOT_DIR}/../out/krun

-include .local.mk

PROJECT_ID?=wlhe-cr
export PROJECT_ID


CLUSTER_NAME?=istio
export CLUSTER_NAME

# also mcp-prod - setup for multi-project
CONFIG_PROJECT_ID?=${PROJECT_ID}
# mesh-config-1
CONFIG_CLUSTER_NAME?=${CLUSTER_NAME}

# If the project is part of a multi-project, this is the hub id.
FLEET_ID?=${CONFIG_PROJECT_ID}
export FLEET_ID


# Region where the cloudrun services are running
REGION?=us-central1
export REGION

CLUSTER_LOCATION?=us-central1-c
export CLUSTER_LOCATION


TAG ?= latest
export TAG

# Derived values

REPO?=gcr.io/${PROJECT_ID}

DOCKER_REPO?=gcr.io/${PROJECT_ID}/krun
export DOCKER_REPO

KRUN_IMAGE?=${DOCKER_REPO}:${TAG}

HGATE_IMAGE?=${DOCKER_REPO}/gate:${TAG}

WORKLOAD_NAME?=fortio-cr
WORKLOAD_NAMESPACE?=fortio

CLOUDRUN_SERVICE_ACCOUNT=k8s-${WORKLOAD_NAMESPACE}@${PROJECT_<EMAIL>

ISTIO_HUB?=gcr.io/istio-testing
export ISTIO_HUB
ISTIO_TAG?=latest

# Also possible to use 1.11.2
ISTIO_PROXY_IMAGE?=${ISTIO_HUB}/proxyv2:latest

FORTIO_IMAGE?=${REPO}/fortio-mesh:${TAG}
export FORTIO_IMAGE
export HGATE_IMAGE

# Build krun, fortio, push fortio, deploy to main test cloudrun config
# Expects Istio cluster and in-cluster fortio to be running
all: build build/krun build/fortio push/fortio deploy/fortio

# Build, push, deploy hgate.
all-hgate: build docker/hgate push/hgate deploy/hgate

deploy/hgate:
	mkdir -p ${OUT}/manifests
	echo ${HGATE_IMAGE}
	cat manifests/kustomization-tmpl.yaml | envsubst > ${OUT}/manifests/kustomization.yaml
	cp -a manifests/hgate ${OUT}/manifests
	kubectl apply -k ${OUT}/manifests
	#kubectl apply -f manifests/hgate/
	kubectl rollout restart deployment hgate -n istio-system
	kubectl wait deployments hgate -n istio-system --for=condition=available

# Remove the namespaces and apps, for testing 'clean install'
cluster/clean:
	helm delete -n istio-system istiod
	kubectl delete -k manifests/
	kubectl delete ns istio-system || true
	kubectl delete ns fortio || true
	kubectl delete ns test || true

test:
	go test -timeout 2m -v ./...

# Build all binaries in one step - faster.
# Static build so it works with 'scratch' and not dependent on distro
build:
	mkdir -p ${OUT}/bin/
	mkdir -p ${OUT}/docker-hgate
	mkdir -p ${OUT}/docker-krun
	cp ./scripts/bootstrap_template.yaml ${OUT}/docker-krun/
	cp ./scripts/iptables.sh ${OUT}/docker-krun/
	CGO_ENABLED=0  time  go build -ldflags '-s -w -extldflags "-static"' -o ${OUT}/bin/ ./cmd/hbone/ ./cmd/krun ./cmd/hgate
	ls -l ${OUT}/bin
	mv ${OUT}/bin/krun ${OUT}/docker-krun
	mv ${OUT}/bin/hgate ${OUT}/docker-hgate

# Build and tag krun image locally, will be used in the next phase and for local testing, no push

build/fortio: build/krun
	(cd samples/fortio; GOLDEN_IMAGE=${KRUN_IMAGE} make image)

build/krun: docker/krun


build/hgate: docker/hgate

docker/hgate:
	time docker build ${OUT}/docker-hgate -f tools/docker/Dockerfile.meshcon -t ${HGATE_IMAGE}

docker/krun:
	time docker build ${OUT}/docker-krun -f tools/docker/Dockerfile.golden -t ${KRUN_IMAGE}

test/e2e: CR_URL=$(shell gcloud run services describe ${WORKLOAD_NAME} --region ${REGION} --project ${PROJECT_ID} --format="value(status.address.url)")
test/e2e:
	curl  -v  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Ffortio.fortio.svc%3A8080%2Fecho
	curl  -v  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Ffortio.fortio-mcp.svc%3A8080%2Fecho
	curl  -v  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Fhttpbin.httpbin.svc%3A8000%2Fheaders
    #curl  ${CR_URL}/fortio/fetch2/?url=http%3A%2F%2Flocalhost%3A15000%2Fconfig_dump

#### Pushing images

{'fraction_non_alphanumeric': 0.13055973723826467, 'fraction_numerical': 0.01478034761187902, 'mean_word_length': 4.917408906882591, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7597289', 'n_tokens_mistral': 2963, 'n_tokens_neox': 2852, 'n_words': 659}