# Container base name
NAME := iperf3
TARBALL := $(NAME).tar

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

# Image repo prefix to use for "push"
IMGREPO := tangentsoft
LNINAME := $(IMGREPO)/$(NAME):latest
LVINAME := $(IMGREPO)/$(NAME):v$(VERSION)

# The list of platforms we build the container for.  It should cover 99%
# of all practical use cases.
PLATFORMS := linux/x86_64,linux/i386,linux/arm,linux/arm64

# Create OCI image in build cache
$(TARBALL): Dockerfile Makefile
	docker build \
		--build-arg VERSION=$(VERSION) \
		--platform $(PLATFORMS) \
		--tag $(LNINAME) \
		--tag $(LVINAME) \
		$(DBFLAGS) .
	docker image save $(LVINAME) > $@

# Remove build outputs
clean:
	rm -f $(TARBALL)
	-docker image rm $(LVINAME)
	-docker image rm $(NAME):latest

login:
	docker login

# Push the built container bundle
push: $(TARBALL)
	docker push $(LNINAME)
	docker push $(LVINAME)

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