IMAGE = debby-agent-img
VERSION = latest
NAME = debby-agent


.PHONY: runpgaas
all: runlocalpgaas rundebbylocalpgaasnovolume


.PHONY: rundebbylocalpgaasnovolume
rundebbylocalpgaasnovolume:
	rm -f *.tar *.conf *.patch
	tar -cf debby.tar ../../src
	cp ../../src/requirements.txt requirements_debby.txt
	tar -cf ivre.tar ../../../ivre
	cp ../../../ivre/requirements-postgres.txt /requirements_postgres.txt
	cp ../../patches/nmap_7_70_port_timestamp.patch nmap_7_70_port_timestamp.patch
	cp ../../patches/ivre-0.9.11-ipv6-and-noinfos.patch ivre.patch
	cp ../../config/supervisord.conf supervisord.conf
	cp ../../config/local_pgaas_ivre.conf ivre.conf
	docker build -t $(IMAGE):$(VERSION) .
	docker run --rm -d --name $(NAME) --network host $(IMAGE):$(VERSION)


.PHONY: runlocalpgaas
runlocalpgaas:
	docker run --rm -p 12000:12000 -d --name $(NAME)-db registry.yandex.net/dbaas/minipgaas


.PHONY: rundebbylocaldb
rundebbylocaldb:
	rm -f *.tar *.conf *.patch
	tar -cf debby.tar ../../src
	cp ../../src/requirements.txt requirements_debby.txt
	tar -cf ivre.tar ../../../ivre
	cp ../../../ivre/requirements-postgres.txt requirements_postgres.txt
	cp ../../patches/nmap_7_70_port_timestamp.patch nmap_7_70_port_timestamp.patch
	cp ../../patches/ivre-0.9.11-ipv6.patch ivre-0.9.11-ipv6.patch
	cp ../../config/supervisord.conf supervisord.conf
	cp ../../config/host_ivre.conf ivre.conf
	docker build -t $(IMAGE):$(VERSION) .
	docker volume create ivre-share
	docker run --rm -d -v ivre-share:/usr/local/share/ivre --name $(NAME) --network host $(IMAGE):$(VERSION)


.PHONY: attach
attach:
	docker exec -it $(NAME) /bin/bash


.PHONY: vclean
vclean:
	docker volume rm ivre-share
