.PHONY: build-production
build-production: ## Build the production container image. Usage: make build-production TAG=15.4.0
	@test -n "$(TAG)" || { echo "Usage: make build-production TAG=15.4.0" >&2; exit 1; }
	@echo "Building image..."
	@podman manifest rm registry.tanshu.com/brewman:latest 2>/dev/null || true
	@podman build \
		--platform linux/amd64,linux/arm64 \
		--manifest registry.tanshu.com/brewman:latest \
		--pull \
		--build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(TAG) \
		https://git.tanshu.com/tanshu/brewman.git#v$(TAG)

	@echo "Pushing manifests..."
	@podman manifest push --all registry.tanshu.com/brewman:latest docker://registry.tanshu.com/brewman:latest
	$(if $(TAG),@podman manifest push --all registry.tanshu.com/brewman:latest docker://registry.tanshu.com/brewman:$(TAG))

.PHONY: build-check
build-check: ## Multi-arch build without push (compile check). Usage: make build-check TAG=15.4.0
	@test -n "$(TAG)" || { echo "Usage: make build-check TAG=15.4.0" >&2; exit 1; }
	@echo "Building image..."
	@podman manifest rm brewman:test 2>/dev/null || true
	@podman build \
		--platform linux/amd64,linux/arm64 \
		--manifest brewman:test \
		--pull \
		--build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(TAG) \
		https://git.tanshu.com/tanshu/brewman.git#v$(TAG)

.PHONY: build-check-local
# Defaults the version when built without a tag; an explicit TAG still wins.
build-check-local: TAG = 0.0.0
build-check-local: ## Single-arch build without push (compile check). Usage: make build-check-local [TAG=15.4.0]
	@echo "Building image..."
	@podman manifest rm brewman:test 2>/dev/null || true
	@podman build \
		--platform linux/amd64 \
		--manifest brewman:test \
		--no-cache \
		--build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(TAG) \
		.
