export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':')
#export REGISTRY=localhost:5000
export REGISTRY=registry.reymota.es

export IMG_VERSION = 0.27
export IMG_NGINX_VERSION = 2.3

# limpia todo
all: imagen clean install

imagen:
	cd ../; make

install:
	-kubectl create -f namespace.yaml
	-kubectl create -f reg-secret.yaml
	-kubectl create -f env-prod-configmap.yaml 
	-kubectl create -f env-prod-db-configmap.yaml 

	-kubectl create -f pv-local-jugaralpadel.yaml
	-kubectl create -f jugaralpadel-prod-persistentvolumeclaim.yaml
	-kubectl create -f static-volume-persistentvolumeclaim.yaml
	-kubectl create -f postgres-data-persistentvolumeclaim.yaml

	-kubectl create -f db-deployment.yaml
	-kubectl create -f db-service.yaml

	-envsubst < jugaralpadel-deployment.yaml |kubectl create -f -
	-envsubst < nginx-deployment.yaml |kubectl create -f -
	-kubectl create -f nginx-service.yaml

clean:
	-envsubst < nginx-deployment.yaml |kubectl delete -f -
	-kubectl delete -f nginx-service.yaml
	-envsubst < jugaralpadel-deployment.yaml |kubectl delete -f -

	-kubectl delete -f db-deployment.yaml
	-kubectl delete -f db-service.yaml

	-kubectl delete -f env-prod-configmap.yaml 
	-kubectl delete -f env-prod-db-configmap.yaml 

	-kubectl delete -f postgres-data-persistentvolumeclaim.yaml
	-kubectl delete -f static-volume-persistentvolumeclaim.yaml
	-kubectl delete -f jugaralpadel-prod-persistentvolumeclaim.yaml
	-kubectl delete -f pv-local-jugaralpadel.yaml
	-kubectl delete -f reg-secret.yaml
	-kubectl delete -f namespace.yaml

nginx:
	cd ../nginx; make

verimg:
	docker run -it  ${REGISTRY}/jugaralpadel-${ARQUITECTURA}:${IMG_VERSION} bash

backup:
	kubectl --kubeconfig /home/creylopez/.kube/config -n jugaralpadel exec -ti deployment.apps/db -- /usr/lib/postgresql/15/bin/pg_dump --username=creylopez --dbname=jugaralpadel > jugaralpadel-$(IMG_VERSION).sql
