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

Merge branch 'dev' into 'master'

Controla más casos de error y añade más info

See merge request redmic-project/docker/docker-deploy!23
parents 722f0ac8 cf70a923
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2,12 +2,12 @@

SERVICES_TO_CHECK="${SERVICES_TO_CHECK:-${STACK:-${SERVICE}}}"

echo -e "\n${INFO_COLOR}Checking deployment of services [${DATA_COLOR} ${SERVICES_TO_CHECK} ${INFO_COLOR}] ..${NULL_COLOR}"
echo -e "\n${INFO_COLOR}Checking deployment of services [${DATA_COLOR} ${SERVICES_TO_CHECK} ${INFO_COLOR}] at ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}"

for serviceToCheck in ${SERVICES_TO_CHECK}
do
	echo -e "\n${INFO_COLOR}Checking deployment of service ${DATA_COLOR}${serviceToCheck}${INFO_COLOR} ..${NULL_COLOR}"
	echo -e "  ${INFO_COLOR}retries ${DATA_COLOR}${STATUS_CHECK_RETRIES}${INFO_COLOR}, interval ${DATA_COLOR}${STATUS_CHECK_INTERVAL}${INFO_COLOR}s, hits ${DATA_COLOR}${STATUS_CHECK_MIN_HITS}${NULL_COLOR}"
	echo -e "  ${INFO_COLOR}retries ${DATA_COLOR}${STATUS_CHECK_RETRIES}${INFO_COLOR}, interval ${DATA_COLOR}${STATUS_CHECK_INTERVAL}${INFO_COLOR}s, hits ${DATA_COLOR}${STATUS_CHECK_MIN_HITS}${NULL_COLOR}\n"

	checkDeployCmd="\
		if docker stack ls > /dev/null 2> /dev/null ; \
+8 −2
Original line number Diff line number Diff line
#!/bin/sh

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

deployCmd="\
	cd ${DEPLOY_HOME} && \
@@ -20,4 +20,10 @@ deployCmd="\
	rm -rf ${DEPLOY_HOME}\
"

ssh ${SSH_PARAMS} "${SSH_REMOTE}" "${deployCmd}"
if ssh ${SSH_PARAMS} "${SSH_REMOTE}" "${deployCmd}"
then
	echo -e "${PASS_COLOR}Service successfully deployed!${NULL_COLOR}"
else
	echo -e "${FAIL_COLOR}Service deploy failed!${NULL_COLOR}"
	exit 1
fi
+19 −6
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ else
fi

echo -e "\n${INFO_COLOR}Setting environment variables to local and remote environments ..${NULL_COLOR}"
echo -en "  ${INFO_COLOR}variable names [ ${DATA_COLOR}SERVICE${INFO_COLOR}, ${DATA_COLOR}STACK${INFO_COLOR}"

# Los argumentos pasados (opcionales) se tratan como variables de entorno.
# Se prepara el fichero .env para usarlas en la máquina destino y se setean en este entorno también.
@@ -20,14 +21,16 @@ for arg in "${@}"
do
	export "${arg}"
	envDefs="${envDefs}\\n${arg}"
	variableName=$(echo "$arg" | cut -f 1 -d '=')
	echo -en "${INFO_COLOR}, ${DATA_COLOR}${variableName}${INFO_COLOR}"
done
echo -e ${envDefs} >> .env
echo -e " ]${NULL_COLOR}"

echo -e "\n${INFO_COLOR}Checking deploy configuration in docker-compose files ..${NULL_COLOR}"
echo -e "  ${INFO_COLOR}compose files [ ${DATA_COLOR}${COMPOSE_FILE}${INFO_COLOR} ]${NULL_COLOR}"
echo -e "  ${INFO_COLOR}compose files [ ${DATA_COLOR}${COMPOSE_FILE}${INFO_COLOR} ]${NULL_COLOR}\n"

# Antes de continuar, se comprueba que la configuración de despliegue sea válida.

if docker-compose config > /dev/null
then
	echo -e "${PASS_COLOR}Valid docker-compose configuration!${NULL_COLOR}"
@@ -39,13 +42,23 @@ fi
randomValue="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
DEPLOY_HOME="${DEPLOY_PATH}/docker-deploy/${randomValue}"

echo -e "\n${INFO_COLOR}Sending deploy resources to remote ..${NULL_COLOR}"
echo -e "\n${INFO_COLOR}Sending deploy resources to remote ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}"
echo -e "  ${INFO_COLOR}deploy path [ ${DATA_COLOR}${DEPLOY_HOME}${INFO_COLOR} ]${NULL_COLOR}"
echo -e "  ${INFO_COLOR}deploy files [ ${DATA_COLOR}${deployFiles}${INFO_COLOR} ]${NULL_COLOR}"
echo -e "  ${INFO_COLOR}deploy files [ ${DATA_COLOR}${deployFiles}${INFO_COLOR} ]${NULL_COLOR}\n"

# Se crea el directorio donde guardar los ficheros de despliegue del servicio.
createDirCmd="mkdir -p ${DEPLOY_HOME}"
ssh ${SSH_PARAMS} "${SSH_REMOTE}" ${createDirCmd}
if ! ssh ${SSH_PARAMS} "${SSH_REMOTE}" ${createDirCmd}
then
	echo -e "${FAIL_COLOR}Deploy path ${DATA_COLOR}${DEPLOY_HOME}${FAIL_COLOR} creation failed!${NULL_COLOR}"
	exit 1
fi

# Se envían a su destino los ficheros de despliegue del servicio.
scp ${SSH_PARAMS} ${deployFiles} "${SSH_REMOTE}:${DEPLOY_HOME}"
if scp ${SSH_PARAMS} ${deployFiles} "${SSH_REMOTE}:${DEPLOY_HOME}"
then
	echo -e "${PASS_COLOR}Deploy resources successfully sent!${NULL_COLOR}"
else
	echo -e "${FAIL_COLOR}Deploy resources sending failed!${NULL_COLOR}"
	exit 1
fi
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ then
	exit 1
fi

remoteHost=$(echo "${SSH_REMOTE}" | cut -f 2 -d '@')

if [ -z "${GITLAB_DEPLOY_KEY}" ]
then
	echo -e "${FAIL_COLOR}You must define 'GITLAB_DEPLOY_KEY' in environment, with a SSH private key accepted by remote server${NULL_COLOR}"
+9 −3
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@

. _definitions.sh

echo -e "\n${INFO_COLOR}Creating networks ..${NULL_COLOR}\n"

if [ "${#}" -lt "1" ]
then
	echo -e "${FAIL_COLOR}One network name (at least) must be provided by parameters!${NULL_COLOR}"
@@ -12,6 +10,8 @@ fi

. _ssh-config.sh

echo -e "\n${INFO_COLOR}Creating networks at remote ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}\n"

createNetsCmd=""
for arg in "${@}"
do
@@ -28,4 +28,10 @@ createNetsInRemoteCmd="\
	createNetsCmd=\$(echo \"${createNetsCmd}\") && \
	eval \"\${createNetsCmd}\""

ssh ${SSH_PARAMS} "${SSH_REMOTE}" ${createNetsInRemoteCmd}
if ssh ${SSH_PARAMS} "${SSH_REMOTE}" ${createNetsInRemoteCmd}
then
	echo -e "${PASS_COLOR}Network creation was successful!${NULL_COLOR}"
else
	echo -e "${FAIL_COLOR}Network creation failed!${NULL_COLOR}"
	exit 1
fi
Loading