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

Merge branch 'dev' into 'master'

Dev

See merge request redmic-project/docker/docker-deploy!56
parents 1594adbf c60c6a39
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -61,12 +61,14 @@ You may define these environment variables (**bold** are mandatory):
* *ENV_SPACE_REPLACEMENT*: Unique string (change this if that is not true for you) used to replace spaces into variable values while handling them. Default `<dd-space>`.
* *FORCE_DOCKER_COMPOSE*: Use always standard (*docker-compose*) mode instead of Docker *Swarm*, even if it is available on remote Docker environment. Default `0`.
* *OMIT_CLEAN_DEPLOY*: Leave at remote host deployment resources after doing a successful deploy. Useful when using bind mounts or *docker-compose* secrets (pointing to static content in deployment resources). Default `0`.
* *SWARM_RESOLVE_IMAGE*: Allow edit behaviour of query the registry to resolve image digest and supported platforms ("always"|"changed"|"never"). Default `always`.
* *GREP_BIN*: Path to *grep* binary in remote host. Default `grep`.
* *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.
* *SERVICES_TO_AUTH*: Names of services which need authorization to access to private registry, separated by space. Default is empty, to use service names found into docker-compose files with stack prefix (`<stack-name>_<service-name>`).
* *SERVICE*: Name of service to relaunch (`<stack-name>_<service-name>`). Available and **required** only for *relaunch* action.
* *SERVICES_TO_CHECK*: Names of services to check after deployment, separated by space. Default is `STACK` variable value, but setting this to a valid service name is recommended (`<stack-name>_<service-name>`).
* *SERVICES_TO_CHECK*: Names of services to check after deployment, separated by space. Default is empty, to use service names found into docker-compose files with stack prefix (`<stack-name>_<service-name>`).
* *SERVICES_TO_DEPLOY*: Names of services to deploy, separated by space. Available only for standard (*docker-compose*) mode. Default is empty, to deploy all defined services.
* *STATUS_CHECK_DELAY*: Seconds to wait before check deployment. Default `120`.
* *STATUS_CHECK_INTERVAL*: Seconds to wait between check iterations. Default `20`.
+9 −2
Original line number Diff line number Diff line
#!/bin/sh

echo -e "\n${INFO_COLOR}Checking deployment of services [${DATA_COLOR} ${SERVICES_TO_CHECK} ${INFO_COLOR}] at ${DATA_COLOR}${remoteHost}${INFO_COLOR} ..${NULL_COLOR}"
servicesToCheck="${SERVICES_TO_CHECK}"
if [ -z "${servicesToCheck}" ]
then
	standardComposeFileSplitted=$(echo ${COMPOSE_FILE} | sed 's/:/ -f /g')
	servicesToCheck=$(docker-compose --log-level ERROR -f ${standardComposeFileSplitted} config --services | sed "s/^/${STACK}_/g")
fi

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

checkDeployCmd="\
	success='' ; \
	for serviceToCheck in ${SERVICES_TO_CHECK} ; \
	for serviceToCheck in $(echo ${servicesToCheck}) ; \
	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}\\n\" ; \
+1 −1
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@ DEPLOY_DIR_NAME="${DEPLOY_DIR_NAME:-deploy}"
DEFAULT_DEPLOY_FILES="${DEFAULT_DEPLOY_FILES:-docker-compose*.yml .env}"
FORCE_DOCKER_COMPOSE="${FORCE_DOCKER_COMPOSE:-0}"
OMIT_CLEAN_DEPLOY="${OMIT_CLEAN_DEPLOY:-0}"
SWARM_RESOLVE_IMAGE="${SWARM_RESOLVE_IMAGE:-always}"

SERVICES_TO_CHECK="${SERVICES_TO_CHECK:-${STACK}}"
STATUS_CHECK_RETRIES="${STATUS_CHECK_RETRIES:-10}"
STATUS_CHECK_INTERVAL="${STATUS_CHECK_INTERVAL:-20}"
STATUS_CHECK_DELAY="${STATUS_CHECK_DELAY:-120}"
+19 −4
Original line number Diff line number Diff line
@@ -11,15 +11,30 @@ deployCmd="\
	else \
		deployAuthParam=\"\" ; \
	fi ; \
	standardComposeFileSplitted=\$(echo ${COMPOSE_FILE} | sed 's/:/ -f /g') ; \
	if [ ${FORCE_DOCKER_COMPOSE} -eq 0 ] && docker stack ls > /dev/null 2> /dev/null ; \
	then \
		composeFileSplitted=\$(echo ${COMPOSE_FILE} | sed 's/:/ -c /g') && \
		swarmComposeFileSplitted=\$(echo ${COMPOSE_FILE} | sed 's/:/ -c /g') && \
		${GREP_BIN} -v '^[#| ]' .env | sed -r \"s/(\w+)=(.*)/export \1='\2'/g\" > .env-deploy && \
		env -i /bin/sh -c \". \$(pwd)/.env-deploy && \
			docker stack deploy \${deployAuthParam} -c \${composeFileSplitted} ${STACK}\" ; \
			docker stack deploy \${deployAuthParam} --resolve-image ${SWARM_RESOLVE_IMAGE} -c \${swarmComposeFileSplitted} ${STACK}\" && \
		if [ ! -z \"\${deployAuthParam}\" ] ; \
		then \
			servicesToAuth=\"${SERVICES_TO_AUTH}\" && \
			if [ -z \"\${servicesToAuth}\" ] ; \
			then \
				servicesToAuth=\"\$(docker-compose --log-level ERROR -f \${standardComposeFileSplitted} config --services | sed \"s/^/${STACK}_/g\")\" ; \
			fi && \
			if [ ! -z \"\${servicesToAuth}\" ] ; \
			then \
				for serviceToAuth in \${servicesToAuth} ; \
				do \
					docker service update -d \${deployAuthParam} \${serviceToAuth} ; \
				done ; \
			fi ; \
		fi ; \
	else \
		composeFileSplitted=\$(echo ${COMPOSE_FILE} | sed 's/:/ -f /g') && \
		composeCmd=\"docker-compose -f \${composeFileSplitted} -p ${STACK}\" && \
		composeCmd=\"docker-compose -f \${standardComposeFileSplitted} -p ${STACK}\" && \
		\${composeCmd} stop ${SERVICES_TO_DEPLOY} && \
		\${composeCmd} rm -f ${SERVICES_TO_DEPLOY} && \
		\${composeCmd} pull ${SERVICES_TO_DEPLOY} && \