Add wait and domain check logic
Closes coop-cloud/abra#116. Also see coop-cloud/abra#113.
This commit is contained in:
		| @ -22,6 +22,8 @@ | ||||
| - Fix git branch handling when not passing `-b <branch>` ([#122](https://git.autonomic.zone/coop-cloud/abra/issues/122)) | ||||
| - Add work-around to correctly git clone non-master default branch app repositories ([#122](https://git.autonomic.zone/coop-cloud/abra/issues/122)) | ||||
| - Replace `--force` with a global `--no-prompt` for avoiding interactive questions ([#118](https://git.autonomic.zone/coop-cloud/abra/issues/118)) | ||||
| - Use [docker-stack-wait-deploy](https://github.com/vitalets/docker-stack-wait-deploy) inspired logic to deploy apps ([#116](https://git.autonomic.zone/coop-cloud/abra/issues/116)) | ||||
| - Add a domain polling check when deploying apps ([#113](https://git.autonomic.zone/coop-cloud/abra/issues/113)) | ||||
|  | ||||
| # abra 0.6.0 (2021-03-17) | ||||
|  | ||||
|  | ||||
							
								
								
									
										60
									
								
								abra
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								abra
									
									
									
									
									
								
							| @ -632,6 +632,64 @@ output_version_summary() { | ||||
|   fi | ||||
| } | ||||
|  | ||||
| # Note(decentral1se): inspired by https://github.com/vitalets/docker-stack-wait-deploy | ||||
| ensure_stack_deployed() { | ||||
|   STACK_NAME=$1 | ||||
|  | ||||
|   info "Waiting for deployment to succeed" | ||||
|  | ||||
|   while true; do | ||||
|     all_services_done=1 | ||||
|     has_errors=0 | ||||
|  | ||||
|     service_ids=$(docker stack services -q "$STACK_NAME") | ||||
|  | ||||
|     for service_id in $service_ids; do | ||||
|       # see: https://github.com/moby/moby/issues/28012 | ||||
|       service_state=$(docker service inspect --format "{{if .UpdateStatus}}{{.UpdateStatus.State}}{{else}}created{{end}}" "$service_id") | ||||
|  | ||||
|       case "$service_state" in | ||||
|         created|completed) | ||||
|           ;; | ||||
|         paused|rollback_completed) | ||||
|           has_errors=1 | ||||
|           ;; | ||||
|         *) | ||||
|           all_services_done=0 | ||||
|           ;; | ||||
|       esac | ||||
|     done | ||||
|  | ||||
|     if [ "$all_services_done" == "1" ]; then | ||||
|       if [ "$has_errors" == "1" ]; then | ||||
|         debug "Deployment appears to have failed" | ||||
|         break | ||||
|       else | ||||
|         debug "Deployment appears to have suceeded" | ||||
|         break | ||||
|       fi | ||||
|     else | ||||
|       sleep 1 | ||||
|     fi | ||||
|   done | ||||
| } | ||||
|  | ||||
| ensure_domain_deployed() { | ||||
|   DOMAIN=$1 | ||||
|  | ||||
|   info "Waiting for $DOMAIN to come up" | ||||
|  | ||||
|   idx=1 | ||||
|   until curl --output /dev/null --silent --head --fail "$DOMAIN"; do | ||||
|     debug "Polled $DOMAIN $idx time(s) already" | ||||
|     sleep 3 | ||||
|     idx=$(("$idx" + 1)) | ||||
|     if [[ $idx -gt 10 ]]; then | ||||
|       error "$DOMAIN still isn't up, check status by running \"abra app ${STACK_NAME} ps\"" | ||||
|     fi | ||||
|   done | ||||
| } | ||||
|  | ||||
| ###### FIXME 3wc: name this section | ||||
|  | ||||
| get_servers() { | ||||
| @ -1132,7 +1190,9 @@ sub_app_deploy (){ | ||||
|     (cd "$APP_DIR" || error "\$APP_DIR '$APP_DIR' not found") | ||||
|     # shellcheck disable=SC2086 | ||||
|     if (cd "$APP_DIR" && docker stack deploy -c ${COMPOSE_FILE//:/ -c } "$STACK_NAME"); then | ||||
|       ensure_stack_deployed "$STACK_NAME" | ||||
|       if [ -n "$DOMAIN" ]; then | ||||
|         ensure_domain_deployed "https://${DOMAIN}" | ||||
|         success "Yay! App should be available at https://${DOMAIN}" | ||||
|       else | ||||
|         success "Yay! That worked. No \$DOMAIN defined, check status by running \"abra app ${STACK_NAME} ps\"" | ||||
|  | ||||
		Reference in New Issue
	
	Block a user