all: download-rpm build-image save-image

build-image:
	# If you configure your host docker to listen on tcp://127.0.0.1:2376
	# then you can omit the following line
	docker run --privileged --name dind --net=host -d docker:dind
	# sleep 10 seconds to wait for the container complete init
	sleep 10
	# copy the client certs from container dind
	docker cp dind:/certs .
	# start to build image
	docker build --network=host -t tep-installer:latest .

save-image: build-image
	mkdir -p tep-installer
	docker save -o tep-installer/tep-installer.tar tep-installer:latest

download-rpm:
	mkdir -p tep-installer
	wget -c http://vault.centos.org/centos/7.4.1708/extras/x86_64/Packages/container-selinux-2.42-1.gitad8f0f7.el7.noarch.rpm -P tep-installer/
	wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.6-3.el7.x86_64.rpm -P tep-installer/
	wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.6-3.el7.x86_64.rpm -P tep-installer/
	wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.2-3.3.el7.x86_64.rpm -P tep-installer/
	# for newer kernel version(>3.10.0-327) we may use higher version of containerd, according to https://github.com/docker/for-linux/issues/595#issuecomment-465722994
	# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.5-3.1.el7.x86_64.rpm

.PHONY: build-image save-image download-rpm
