Commit 3c83b18c authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Permite omitir limpieza también cuando falla

Extrae el proceso de limpieza de las condiciones de despliegue con
éxito, para evaluar antes si se hace o no en función de los ajustes del
usuario, tanto si el despliegue fue correcto como si no.
parent 5ba1ddb2
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

echo -e "\n${INFO_COLOR}Deploying at host ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}\n"

if [ ${deployingToSwarm} -ne 0 ]
if [ "${deployingToSwarm}" -ne 0 ]
then
	if [ ${docker23CompatibleTarget} -eq 0 ]
	if [ "${docker23CompatibleTarget}" -eq 0 ]
	then
		composeBaseCmd="docker compose"
	else
@@ -13,7 +13,7 @@ then
fi

deployCmd="\
	cd ${deployHome} && \
	cd \"${deployHome}\" && \
	if [ ! -z \"${REGISTRY_USER}\" ] ; \
	then \
		docker login -u \"${REGISTRY_USER}\" -p \"${REGISTRY_PASS}\" ${REGISTRY_URL} ; \
@@ -21,13 +21,13 @@ deployCmd="\
	else \
		deployAuthParam=\"\" ; \
	fi ; \
	if [ ${deployingToSwarm} -eq 0 ] ; \
	if [ \"${deployingToSwarm}\" -eq 0 ] ; \
	then \
		${GREP_BIN} -v '^[#| ]' \"${COMPOSE_ENV_FILE_NAME}\" | sed -r \"s/(\w+)=(.*)/export \1='\2'/g\" > .env-deploy && \
		env -i /bin/sh -c \"\
			. \$(pwd)/.env-deploy && \
			rm \$(pwd)/.env-deploy && \
			docker stack deploy \${deployAuthParam} --resolve-image ${SWARM_RESOLVE_IMAGE} -c ${swarmComposeFileSplitted} ${STACK}\" && \
			docker stack deploy \${deployAuthParam} --resolve-image \"${SWARM_RESOLVE_IMAGE}\" -c ${swarmComposeFileSplitted} ${STACK}\" && \
		if [ ! -z \"\${deployAuthParam}\" ] ; \
		then \
			servicesToAuth=\"${SERVICES_TO_AUTH:-${servicesInComposeFiles}}\" && \
@@ -47,20 +47,22 @@ deployCmd="\
		\${composeCmd} up -d ${SERVICES_TO_DEPLOY} ; \
	fi"

cleanDeployCmd="ssh ${SSH_PARAMS} \"${SSH_REMOTE}\" \"rm -rf ${deployHome}\""
ssh ${SSH_PARAMS} "${SSH_REMOTE}" "${deployCmd}"
deployExitCode=${?}

if ssh ${SSH_PARAMS} "${SSH_REMOTE}" "${deployCmd}"
if [ "${OMIT_CLEAN_DEPLOY}" -eq 0 ]
then
	echo -e "\n${PASS_COLOR}Services successfully deployed!${NULL_COLOR}"
	if [ ${OMIT_CLEAN_DEPLOY} -eq 0 ]
	then
		eval "${cleanDeployCmd}"
	cleanDeployCmd="rm -rf \"${deployHome}\""
	ssh ${SSH_PARAMS} "${SSH_REMOTE}" "${cleanDeployCmd}"
else
		echo -e "${INFO_COLOR}Deployment resources cleaning omitted${NULL_COLOR}"
	echo -e "\n${INFO_COLOR}Deployment resources cleaning omitted${NULL_COLOR}"
fi

if [ ${deployExitCode} -eq 0 ]
then
	echo -e "\n${PASS_COLOR}Services successfully deployed!${NULL_COLOR}"
else
	echo -e "\n${FAIL_COLOR}Services deployment failed!${NULL_COLOR}"
	eval "${cleanDeployCmd}"
	eval "${closeSshCmd}"
	exit 1
fi