project_root := justfile_directory()
env_file := project_root + "/Env/.env.local"
backend_dir := project_root + "/Backend"
backend_bake := project_root + "/Backend/docker-bake.hcl"
store_dir := project_root + "/Store"
store_bake := project_root + "/Store/docker-bake.hcl"
compose_file := project_root + "/Docker/docker-compose.remote.dev.yaml"

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

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

# Start the remote development 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 development images to the registry.
push:
	set -a && source '{{env_file}}' && set +a && cd '{{backend_dir}}' && docker buildx bake -f '{{backend_bake}}' dev-image && cd '{{store_dir}}' && docker buildx bake -f '{{store_bake}}' dev-image

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

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

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

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