project_root := justfile_directory()
env_file := project_root + "/Env/.env.production"
backend_dir := project_root + "/Backend"
backend_bake := project_root + "/Backend/docker-bake.hcl"
proxy_bake := project_root + "/Proxy/docker-bake.hcl"
compose_file := project_root + "/Docker/docker-compose.remote.prod.yaml"

# Default flow: refresh the registry images and recreate the stack.
rebuild: up

# Pull the latest remote production images from the registry.
pull:
	docker compose --env-file '{{env_file}}' -f '{{compose_file}}' pull

# Start the remote production stack locally using the current registry images.
up: pull
	docker compose --env-file '{{env_file}}' -f '{{compose_file}}' up -d --remove-orphans --force-recreate

# Publish the remote production images to the registry.
push:
	set -a && source '{{env_file}}' && set +a && cd '{{backend_dir}}' && docker buildx bake -f '{{backend_bake}}' prod-image && cd '{{project_root}}' && docker buildx bake -f '{{proxy_bake}}' prod-image

# Stop and remove the remote production stack.
down:
	docker compose --env-file '{{env_file}}' -f '{{compose_file}}' down --remove-orphans

# Follow logs for the remote production stack.
logs:
	docker compose --env-file '{{env_file}}' -f '{{compose_file}}' logs -f

# Restart the remote production stack.
restart:
	docker compose --env-file '{{env_file}}' -f '{{compose_file}}' restart

# Show remote production stack status.
ps:
	docker compose --env-file '{{env_file}}' -f '{{compose_file}}' ps
