004 CD.sh 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#!/bin/bash
set -e

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

GetAppName appName

echo "Continuous deployment of ${Environment} branch for ${appName} starting..." 

GetCiCdSettings allPublishable noPublishable

if [ "${noPublishable}" == "1" ] ;
then
    echo ""
    echo "Tips: No services need to be cded."
else
    echo "Please check the version of each microservice carefully !!!"
	echo ""

	GetVersion version
	GetNameSpace namespace
	GetImageRegistrySettings registryHost registryUserName

	function CD()
	{
		declare publishable=$1
		declare appName=$2
		declare imageName=$3

		echo ""
		if [ "${publishable}" == "1" ]; 
		then 
			kubectl -n ${namespace} set image deployments/${appName} "${appName}=${registryHost}/${registryUserName}/${imageName}:${version}"; 
			if [ "${Environment}" == "Staging" ]; then
				kubectl -n ${namespace} scale deploy ${appName} --replicas=0; 
				kubectl -n ${namespace} scale deploy ${appName} --replicas=1; 
			fi
			echo "deployment of ${Environment} branch for ${appName}:${version} has been successful."
		else
			echo "Tips: ${Environment} branch for ${appName}:${version} will not be cded!!!"
		fi
	}

	declare services=$(ls -l src/services | awk 'NR>1')
	declare servicePrefix=""
	declare serviceName=""
	declare isPublishable="0"
	for service in ${services}
	do
	  servicePrefix=($(echo ${service} | awk '{print $9}')) 
	  isPublishable=($(grep -oP "(?<=${servicePrefix}Publishable>)[^<]+" "/tmp/cicd.props"))
	  GetServiceName "${servicePrefix}" serviceName
	  CD ${apiPublishable} "${serviceName}" "${serviceName}"
	done
fi

echo ""
echo "Continuous deployment of ${Environment} branch for ${appName} has been successful."