# Build and publish the base image. All logic lives in bin/; targets here
# only wire dependencies and export configuration.
#
#   make release          build, test, push both arches, tag, commit logs
#   make -j2 release      same, with the two arches in parallel
#   make build            build for this machine's arch only
#   make test             run the image smoke test for this machine's arch

IMAGE  ?= git.eeqj.de/sneak/baseimage
DATE   ?= $(shell date +%Y-%m-%d)
ARCHES ?= amd64 arm64

# Docker daemon to use per arch. Empty means the local daemon.
DOCKER_HOST_amd64 ?= ssh://root@fsn1app1
DOCKER_HOST_arm64 ?=

NATIVE_ARCH := $(shell bin/native-arch)

export IMAGE DATE ARCHES DOCKER_HOST_amd64 DOCKER_HOST_arm64

.PHONY: release manifest commit-logs build test push clean \
	$(ARCHES:%=build-%) $(ARCHES:%=test-%) $(ARCHES:%=push-%)

release: commit-logs

commit-logs: manifest
	bin/commit-logs

manifest: $(ARCHES:%=push-%)
	bin/manifest

# Static pattern rules: plain pattern rules are skipped for .PHONY targets.
$(ARCHES:%=push-%): push-%: test-%
	bin/push $*

$(ARCHES:%=test-%): test-%: build-%
	bin/test $*

$(ARCHES:%=build-%): build-%:
	bin/build $*

build: build-$(NATIVE_ARCH)
test: test-$(NATIVE_ARCH)
push: push-$(NATIVE_ARCH)

clean:
	bin/clean
