#!/bin/bash

set -e

# Import external functions
chmod +x ./devops/PipeLines/Functions.core.sh
source ./devops/PipeLines/Functions.core.sh

function CI()
{
    declare serviceName=$1
    declare publishFile=$2
	declare publishOutputDir="/tmp/${serviceName}"

	GetVersion version
	GetImageUserName registryUserName

	# repository name must be lowercase
	ToLower "${RegistryHost}/${registryUserName}/${serviceName}:${version}" imagefullname
	
	echo ""
	echo "Begin delivering for ${serviceName}..."
	echo "Tips: Image full name: ${imagefullname}"
	mkdir -p ${publishOutputDir}
	dotnet publish ${publishFile} -o ${publishOutputDir} -c release --no-restore  
	docker build -t ${imagefullname} ${publishOutputDir}
	docker push ${imagefullname}
	rm -fr ${publishOutputDir}
	echo "Delivery for ${serviceName} has been successful."
}