Commit 25731030 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Depura relaunch y añade nueva opción

Corrige errores de código y problemas de funcionamiento para algunos
casos de uso.

Agrega nueva opción para omitir la espera a que el servicio converja,
permitiendo acelerar el proceso de relaunch si fuera necesario.

Corrige saltos de línea y muestra más información de salida.
parent 9a423774
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ You may define these environment variables (**bold** are mandatory):
| *GREP_BIN* | `grep` | Path to *grep* binary in deployment target host. |
| *OMIT_CLEAN_DEPLOY* | `0` | Leave at deployment target host all deployment resources after doing a deploy. Useful when using bind mounts or *Compose* secrets (pointing to static content in deployment resources) or you want to check sent contents. |
| *OMIT_STATUS_CHECK* | `0` | Bypass status check process after deploying services. Useful when you need to be fast. |
| *OMIT_WAITING_TO_CONVERGE* | `0` | Bypass waiting for relaunched service to converge (when all service tasks are running and healthy, if supported). Useful when you need to be fast. Available only for *relaunch* action. |
| *REGISTRY_PASS* | - | Docker registry password, corresponding to a user with read permissions. **Required** for private registry or repository. |
| *REGISTRY_URL* | - | Docker registry address, where Docker must log in to retrieve images. Useful only when using private registry or repository. Default is empty, to use Docker Hub registry. |
| *REGISTRY_USER* | - | Docker registry username, corresponding to a user with read permissions. **Required** for private registry or repository. |
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ FORCE_DOCKER_COMPOSE="${FORCE_DOCKER_COMPOSE:-0}"
OMIT_CLEAN_DEPLOY="${OMIT_CLEAN_DEPLOY:-0}"
SWARM_RESOLVE_IMAGE="${SWARM_RESOLVE_IMAGE:-always}"
ALLOW_COMPOSE_ENV_FILE_INTERPOLATION="${ALLOW_COMPOSE_ENV_FILE_INTERPOLATION:-0}"
OMIT_WAITING_TO_CONVERGE="${OMIT_WAITING_TO_CONVERGE:-0}"

OMIT_STATUS_CHECK="${OMIT_STATUS_CHECK:-0}"
STATUS_CHECK_RETRIES="${STATUS_CHECK_RETRIES:-10}"
+6 −4
Original line number Diff line number Diff line
#!/bin/sh

echo -e "\n${INFO_COLOR}Using digest data to obtain updated image for relaunch ..${NULL_COLOR}"
echo -e "\n${INFO_COLOR}Using digest data to obtain updated image for relaunch${NULL_COLOR}"

getServiceImageCmd="docker service ls -f 'name=${serviceToRelaunch}' --format '{{.Image}}' | cut -d '@' -f 1"
serviceImageNameAndTag=$(runRemoteCmd "${getServiceImageCmd}")
@@ -12,20 +12,22 @@ then
	exit 1
fi

echo -e "\n${INFO_COLOR}Pulling service image [ ${DATA_COLOR}${serviceImageNameAndTag}${INFO_COLOR} ] ..${NULL_COLOR}\n"

# Se obtiene la imagen actualizada.
getUpdatedServiceImageCmd="docker pull ${serviceImageNameAndTag}"

if runRemoteCmd "${getUpdatedServiceImageCmd}"
then
	echo -e "\n${PASS_COLOR}Image updated successfully!${NULL_COLOR}"
	echo -e "\n${PASS_COLOR}Image updated successfully!${NULL_COLOR}\n"
else
	echo -e "\n${FAIL_COLOR}Image update failed!${NULL_COLOR}"
	echo -e "\n${FAIL_COLOR}Image update failed!${NULL_COLOR}\n"
fi

serviceImageName=$(echo "${serviceImageNameAndTag}" | cut -d ':' -f 1)

# Se obtiene el valor de digest de la imagen actualizada.
getServiceImageDigestCmd="docker images --digests --format '{{.Digest}}' ${serviceImageName})"
getServiceImageDigestCmd="docker images --digests --format '{{.Digest}}' ${serviceImageName} | head -1"
serviceImageDigest=$(runRemoteCmd "${getServiceImageDigestCmd}")

# Prepara variable usada desde el script principal
+5 −5
Original line number Diff line number Diff line
@@ -5,12 +5,12 @@ if [ ! -z "${REGISTRY_USER}" ]
then
	serviceUpdateAdditionalArgs="${serviceUpdateAdditionalArgs} --with-registry-auth"

	echo -e "\n${INFO_COLOR}Login to registry ${DATA_COLOR}${REGISTRY_URL:-<default>}${INFO_COLOR} ..${NULL_COLOR}\n"
	echo -e "${INFO_COLOR}Login to registry ${DATA_COLOR}${REGISTRY_URL:-<default>}${INFO_COLOR} ..${NULL_COLOR}\n"

	# Se prepara la ruta de trabajo.
	randomValue="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
	relaunchHome="${DEPLOY_PATH}/docker-deploy/${randomValue}"
	createDirCmd="mkdir -p ${deployHome}"
	createDirCmd="mkdir -p ${relaunchHome}"

	if ! runRemoteCmd "${createDirCmd}"
	then
@@ -26,12 +26,12 @@ then

	echo -e "${ddRegistryPassVarName}=${REGISTRY_PASS}" > "${relaunchEnvFile}"

	echo -e "\n${INFO_COLOR}Sending relaunch resources to host ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}"
	echo -e "${INFO_COLOR}Sending relaunch resources to host ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}"
	echo -e "  ${INFO_COLOR}relaunch path [ ${DATA_COLOR}${relaunchHome}${INFO_COLOR} ]${NULL_COLOR}"

	if scp ${SSH_PARAMS} "${relaunchEnvFile}" "${SSH_REMOTE}:${relaunchHome}"
	then
		echo -e "\n${PASS_COLOR}Relaunch resources successfully sent!${NULL_COLOR}"
		echo -e "\n${PASS_COLOR}Relaunch resources successfully sent!${NULL_COLOR}\n"
	else
		echo -e "\n${FAIL_COLOR}Relaunch resources sending failed!${NULL_COLOR}"
		eval "${closeSshCmd}"
@@ -55,5 +55,5 @@ then
	eval "${rmRelaunchEnvFileCmd}"
	runRemoteCmd "${moveToRelaunchDirCmd}${rmRelaunchEnvFileCmd}"
else
	echo -e "\n${INFO_COLOR}Omitting login to registry${NULL_COLOR}"
	echo -e "${INFO_COLOR}Omitting login to registry${NULL_COLOR}"
fi
+16 −10
Original line number Diff line number Diff line
#!/bin/sh

servicesFoundByName=$(runRemoteCmd "docker service ls -f 'name=${SERVICE}' --format '{{.Name}}'")
servicesSeparatorCount=$(echo "${servicesFoundByName}" | grep -c ' ')
servicesSeparatorCount=$(echo "${servicesFoundByName}" | wc -l)

if [ "${servicesSeparatorCount}" -ne 0 ]
if [ "${servicesSeparatorCount}" -ne 1 ]
then
	serviceToRelaunch=$(echo "${servicesFoundByName}" | cut -d ' ' -f 1)
	servicesToRelaunch=$(echo "${servicesFoundByName}" | tr '\n' ' ')
	serviceToRelaunch=$(echo "${servicesToRelaunch}" | cut -d ' ' -f 1)

	echo -e "\n${INFO_COLOR}Found more than one service filtering by name ${DATA_COLOR}${SERVICE}${INFO_COLOR} ..${NULL_COLOR}"
	echo -e "  ${INFO_COLOR}services [ ${DATA_COLOR}${servicesFoundByName}${INFO_COLOR} ]${NULL_COLOR}"
	echo -e "  ${INFO_COLOR}will relaunch only ${DATA_COLOR}${serviceToRelaunch}${INFO_COLOR} service${NULL_COLOR}"
else
	echo -e "  ${INFO_COLOR}services [ ${DATA_COLOR}${servicesToRelaunch}${INFO_COLOR} ]${NULL_COLOR}"
	echo -e "  ${INFO_COLOR}will relaunch only ${DATA_COLOR}${serviceToRelaunch}${INFO_COLOR} service${NULL_COLOR}\n"
elif [ ! -z "${servicesFoundByName}" ]
then
	serviceToRelaunch="${SERVICE}"
fi

if [ -z "${serviceToRelaunch}" ]
then
	echo -e "  ${INFO_COLOR}service found [ ${DATA_COLOR}${serviceToRelaunch}${INFO_COLOR} ]${NULL_COLOR}\n"
else
	echo -e "\n${FAIL_COLOR}Service to relaunch not found at remote!${NULL_COLOR}"
	eval "${closeSshCmd}"
	exit 1
fi

if [ "${OMIT_WAITING_TO_CONVERGE}" -ne 0 ]
then
	serviceUpdateAdditionalArgs="${serviceUpdateAdditionalArgs} --detach"
fi

if [ "${SWARM_RESOLVE_IMAGE}" = "never" ]
then
	serviceUpdateAdditionalArgs="--no-resolve-image"
	serviceUpdateAdditionalArgs="${serviceUpdateAdditionalArgs} --no-resolve-image"
fi