include .env


namespaces:
	./scripts/k8s-namespaces.sh

secrets:
	./scripts/k8s-secrets.sh

flux-prod:
	./scripts/flux-bootstrap-prod.sh

flux-staging:
	(cd ./scripts; ./flux-bootstrap-staging.expect)

dev: kind namespaces secrets chisel velero

prod: namespaces secrets velero flux-prod

staging: namespaces secrets velero flux-staging

velero:
	./scripts/velero-create.sh

tilt:
	kind get kubeconfig > ~/.kube/kind.yaml
	KUBECONFIG=~/.kube/kind.yaml tilt up -f ./t.wip.tiltfile


define _script
cat <<'EOF' | ctlptl apply -f -
apiVersion: ctlptl.dev/v1alpha1
kind: Cluster
product: minikube
registry: ctlptl-registry
kubernetesVersion: v1.28.3
EOF
endef
export script = $(value _script)
minikube:
	@ eval "$$script"
	minikube addons enable volumesnapshots
	minikube addons enable csi-hostpath-driver
	minikube addons enable metrics-server

kind:
	./scripts/kind-with-local-registry.sh

chisel:
	./scripts/k8s-chisel-operator.sh

deps:
	sudo pamac install make entr nvm minikube kubectl docker helm expect
	curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
	curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
	echo "go to https://github.com/txn2/kubefwd/releases/latest to get kubefwd"
	echo "go to https://github.com/tilt-dev/ctlptl/releases/latest to get ctlptl"
	sudo systemctl enable docker
	sudo systemctl start docker
	usermod -aG docker cj
	newgrp docker
	curl -OL 'https://github.com/vmware-tanzu/velero/releases/download/v1.13.2/velero-v1.13.2-linux-amd64.tar.gz'

# A gitea act runner which runs locally
# https://docs.gitea.com/next/usage/actions/overview
# this doesnt work because of missing docker in docker
# I'm running this using systemd instead
#runner:
#	docker run -d --rm -e GITEA_INSTANCE_URL=https://gitea.futureporn.net -e GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_REGISTRATION_TOKEN} -v /var/run/docker.sock:/var/run/docker.sock -v $$HOME/.local/share/applications/fp/act-runner-data:/data --privileged --name fp-gitea-act-runner gitea/act_runner