# Container base name
NAME := iperf3

# Version to clone and build.  You can use any valid tag on the upstream
# https://github.com/esnet/iperf/ repo.
VERSION := 3.19.1

# Registry naming for the push steps
PRIREG   := quay.io
SECREG   := docker.io
PRIORG   := tangent
SECORG   := tangentsoft
PRIBNAME := $(PRIREG)/$(PRIORG)/$(NAME)
SECBNAME := $(SECREG)/$(SECORG)/$(NAME)
PRILTAG  := $(PRIBNAME):latest
SECLTAG  := $(SECBNAME):latest
PRIVTAG  := $(PRIBNAME):v$(VERSION)
SECVTAG  := $(SECBNAME):v$(VERSION)

# Create OCI image in build cache
image: Containerfile Makefile
	-podman untag $(PRILTAG) 2> /dev/null
	podman farm build \
		--tag $(PRIBNAME) \
		--build-arg VERSION=$(VERSION) \
		$(DBFLAGS) .
	for t in $(PRIVTAG) $(SECVTAG) $(SECLTAG) ; do \
		podman tag  $(PRILTAG) $$t ; \
		podman push $$t ; \
	done

# Remove build outputs
clean:
	-podman image rm $(PRILTAG) $(PRIVTAG) $(SECLTAG) $(SECVTAG)

login:
	podman login --username $(PRIORG) $(PRIREG)
	podman login --username $(SECORG) $(SECREG)

# Run the native version of the built container locally, for testing
run:
	podman run $(DRFLAGS) \
		--rm \
		--tty \
		--interactive \
		--publish 5201:5201/tcp \
		--publish 5201:5201/udp \
		$(PRIVTAG) $(EPFLAGS)
