# HG changeset patch # User Goffi # Date 1413803551 -7200 # Node ID f0a59c8f349044e9a1339e682a0ea9405e37dcfe # Parent b10f0188594964dcaac0d18d10f850fe87e7e334 docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress) diff -r b10f01885949 -r f0a59c8f3490 docker/libervia_cont.sh --- a/docker/libervia_cont.sh Sun Oct 19 19:44:47 2014 +0200 +++ b/docker/libervia_cont.sh Mon Oct 20 13:12:31 2014 +0200 @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -VERSION="0.1.0" +VERSION="0.2.0" ACCOUNT="salutatoi" CONTAINERS="prosody sat_pubsub salut sat libervia" @@ -24,7 +24,8 @@ DETACH="-d" TERM="-ti" -VOLUME_CONT="$ACCOUNT/data" +VOLUME_NAME="data" +VOLUME_CONT="$ACCOUNT/$VOLUME_NAME" VOLUME_ALIAS="sat_data" VOLUME="--volumes-from $VOLUME_ALIAS" @@ -42,6 +43,8 @@ PORT_8443_NAME="HTTPS" NO_PORT="No public port" +DOCKER_EXE="docker" + USAGE="Usage: $0 [run|stop|update|backup|ports] [ARGS...]" HELP_SITE="http://wiki.goffi.org/wiki/Docker/en" @@ -105,6 +108,32 @@ echo $ARG } +download_missing() { + # download images wich are not present locally + for cont in $VOLUME_NAME $CONTAINERS; do + image="$ACCOUNT/$cont" + docker inspect $image:latest > /dev/null 2>&1 + if [ $? -ne 0 ]; then + printf "$image is not present locally, downloading it\n" + docker pull $image:latest + if [ $? -eq 0 ]; then + printf "\nDownload of latest $image finished\n\n" + else + printf "\nError while downloading $image, please check your connection and logs\n" + return 1 + fi + fi + done +} + +check_docker() { + which $DOCKER_EXE > /dev/null 2>&1 + if [ $? -ne 0 ]; then + printf "Docker is not installed or not accessible, please install it.\nYou can check http://wiki.goffi.org/wiki/Docker/en for instructions\n" + return 1 + fi +} + parse_run_args() { # manage arguments for run command @@ -144,6 +173,7 @@ done } +check_docker || exit 1 if [ $# -ge 1 ];then case $1 in @@ -165,6 +195,8 @@ case $CMD in RUN) parse_run_args "$@" + download_missing || exit 1 + printf "Running data container... " docker_id=$(docker run -d -ti --name $VOLUME_ALIAS $VOLUME_CONT 2>&1) if [ $? -eq 0 ]; then