#!/bin/bash

# See: https://github.com/Microsoft/azure-pipelines-image-generation/issues/738
# If azure-pipelines adds docker to MacOS, we can skip this.

# We need to use a specific version of docker, the latest version
# fails to start.
brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/8ce4e89d10716666743b28c5a46cd54af59a9cc2/Casks/docker.rb
sudo /Applications/Docker.app/Contents/MacOS/Docker --quit-after-install --unattended
/Applications/Docker.app/Contents/MacOS/Docker --unattended &

attempts=0
while ! docker info 2>/dev/null ; do
    sleep 5
    attempts=`expr $attempts + 1`
    if pgrep -xq -- "Docker"; then
        echo 'docker still running, waiting...'
    else
        echo 'docker not running, restarting...'
        /Applications/Docker.app/Contents/MacOS/Docker --unattended &
    fi
    if [ $attempts -gt 30 ]; then
        >&2 echo 'Failed to run docker'
        exit 1
    fi;

    echo 'Waiting for docker service to be in the running state'
done

#!/bin/bash

# See: https://github.com/Microsoft/azure-pipelines-image-generation/issues/738
# If azure-pipelines adds docker to MacOS, we can skip this.

# We need to use a specific version of docker, the latest version
# fails to start.
brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/8ce4e89d10716666743b28c5a46cd54af59a9cc2/Casks/docker.rb
sudo /Applications/Docker.app/Contents/MacOS/Docker --quit-after-install --unattended
/Applications/Docker.app/Contents/MacOS/Docker --unattended &

attempts=0
while ! docker info 2>/dev/null ; do
    sleep 5
    attempts=`expr $attempts + 1`
    if pgrep -xq -- "Docker"; then
        echo 'docker still running, waiting...'
    else
        echo 'docker not running, restarting...'
        /Applications/Docker.app/Contents/MacOS/Docker --unattended &
    fi
    if [ $attempts -gt 120 ]; then
        >&2 echo 'Failed to run docker'
        exit 1
    fi;

    echo 'Waiting for docker service to be in the running state'
done

Increase mac attempts waiting for docker to start
Increase mac attempts waiting for docker to start

Docker on the azure-pipelines mac images can be pretty slow in general.
It can also take a long time for it to start up. This can cause the
mac build to fail if waiting for docker to start takes too long.

Increase the max amount of time waiting for docker to start to
hopefully prevent more of these failures.

Signed-off-by: Patrick Avery <743342299f279e7a8c3ff5eb40671fce3e95f13a@kitware.com>
