
VERSION ?= $(shell git describe)


all:


download-all: vlkb-search vlkb-cutout vlkbd vlkb-obscore vlkb

vlkb-search vlkb-cutout:
	make download PACK_FILE=$@-$(VERSION).war

vlkbd vlkb-obscore vlkb:
	make download PACK_FILE=$@-$(VERSION).rpm
	make download PACK_FILE=$@-$(VERSION).deb


.PHONY: download
download: GITLAB_PROJ_ID := 79
download: GITLAB_PROJ_NAME := $(shell basename -s .git `git config --get remote.origin.url`)
download: VER_MAJOR := $(shell echo $(VERSION) | cut -f1 -d.)
download: VER_MINOR := $(shell echo $(VERSION) | cut -f2 -d.)
download: PACK_URL := "https://ict.inaf.it/gitlab/api/v4/projects/$(GITLAB_PROJ_ID)/packages/generic/$(GITLAB_PROJ_NAME)/$(VER_MAJOR).$(VER_MINOR)/$(PACK_FILE)"
download:
	curl -O --header "PRIVATE-TOKEN: glpat-CJZDcks7bYqE__ePn4J6" $(PACK_URL)


ast-9.2.9.tar.gz:
	wget https://github.com/Starlink/ast/files/8843897/ast-9.2.9.tar.gz



.PHONY: build
build:
	docker build --build-arg VLKB_VERSION=$(VERSION) -t siav2 -f Dockerfile.vlkb .

# the docker-login below needed a ca-cert(?) which in the middle of the certificate-chain,
# but was not automatically downloaded and also local cert/ket pair(?) ->
# -> see: /etc/docker/certs.d/git.ia2.ianf.it:5050/*
#
# docker login git.ia2.inaf.it:5050 (robert.butora C-tol szokasos-hossu)
# to download: use image: ... in compose.yaml or
# docker run ... git.ia2.inaf.it:5050/butora/vlkb-datasets/vlkb

publish-locally-soda:
	docker tag soda git.ia2.inaf.it:5050/butora/vlkb-datasets-docker/soda:$(VERSION)
	docker push     git.ia2.inaf.it:5050/butora/vlkb-datasets-docker/soda:$(VERSION)
	docker image rm git.ia2.inaf.it:5050/butora/vlkb-datasets-docker/soda:$(VERSION)


##docker login registry.gitlab.com --> robert.butora xC*n
publish-remotely-to-ska:
	docker tag soda registry.gitlab.com/ska-telescope/src/visivo-vlkb-soda:$(VERSION)
	docker push     registry.gitlab.com/ska-telescope/src/visivo-vlkb-soda:$(VERSION)
	docker image rm registry.gitlab.com/ska-telescope/src/visivo-vlkb-soda:$(VERSION)

###############################################################################
#TAG ?= $(VERSION)
#REMOTE_SODA_IMAGE_NAME = registry.gitlab.com/ska-telescope/src/visivo-vlkb-soda:$(TAG)
#SODA_IMAGE_NAME = soda:$(TAG)
# https://gitlab.com/ska-telescope/src/visivo-vlkb-soda/container_registry/3917365
###############################################################################
#.PHONY: publish
#publish:
#	docker tag $(SODA_IMAGE_NAME) $(REMOTE_SODA_IMAGE_NAME)
#	docker push $(REMOTE_SODA_IMAGE_NAME)
#	docker image rm $(REMOTE_SODA_IMAGE_NAME)
#	@echo "SODA_IMAGE_NAME        : "$(SODA_IMAGE_NAME)
#	@echo "REMOTE_SODA_IMAGE_NAME : "$(REMOTE_SODA_IMAGE_NAME)
###############################################################################


