# Copyright (C) 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 License.
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>

# This test requires network access, so we can't add it in the
# PKGBUILD itself as requiring network access for packages builds is
# very strongly discouraged.

PKGVER ?= `makepkg --printsrcinfo | grep pkgver | awk '{print $$3}'`
PKGREL ?= `makepkg --printsrcinfo | grep pkgrel | awk '{print $$3}'`
ARCH ?= x86_64
PACKAGE ?= docker-1:$(PKGVER)-$(PKGREL)-$(ARCH).pkg.tar.xz

check:
	set -e
	rm -rf pkg/ src/
	makepkg -f
	sudo pacman -U $(PACKAGE) --noconfirm

	# We need to (re)start the docker daemon for the changes to be
	# taken into account.
	sudo systemctl daemon-reload
	sudo systemctl restart docker

	# This should fail if the registry has been changed and that
	# no registry runs on localhost:5000
	sudo bash -c '! docker run -it --rm pureos/byzantium bash -c "echo hello world"'

	# This should work as we don't want to prevent users from
	# using images from docker.io.
	sudo docker run -it --rm registry-1.docker.io/pureos/byzantium bash -c "echo hello world"

	# Here this should work but currently fails.
	# sudo docker run -it --rm docker.io/pureos/byzantium bash -c "echo hello world"
