
VERSION ?= $(shell git describe)


all:


download-all: vlkb-soda vlkbd vlkb-obscore vlkb

vlkb-soda:
	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-soda:
	docker build --build-arg VLKB_VERSION=$(VERSION) -t soda -f Dockerfile.soda .

build-vlkb:
	docker build --build-arg VLKB_VERSION=$(VERSION) -t vlkb -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/vialactea/vlkb-soda

publish-locally-soda:
	docker tag soda git.ia2.inaf.it:5050/vialactea/vlkb-soda/soda:$(VERSION)
	docker push     git.ia2.inaf.it:5050/vialactea/vlkb-soda/soda:$(VERSION)
	docker image rm git.ia2.inaf.it:5050/vialactea/vlkb-soda/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)


# Aug 2024:
# login to Harbor: https://harbor.srcdev.skao.int --> SKA-IAM login page: and "Sign in with your SKA IAM Prototype credentials"
# https://ska-iam.stfc.ac.uk -> robert.butora & xCf*n (valoszinuleg; browser cache-ben van valami ami ennyi character)
# --> Authorize access to docker-image repos
#  when logged in Harbor: copy secret from UserProfile -> secret-COPY cmd and use is -p swicth
login-ska-harbor:
	docker login -u robert.butora -p LwevJLIh6yMcBu9RNUeQdJ48lneTTkVR  harbor.srcdev.skao.int/soda


publish-remotely-to-ska-harbor:
	docker tag soda harbor.srcdev.skao.int/soda/visivo-vlkb-soda:$(VERSION)
	docker push     harbor.srcdev.skao.int/soda/visivo-vlkb-soda:$(VERSION)
	docker image rm harbor.srcdev.skao.int/soda/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)
###############################################################################


