diff --git a/launcher-image/src/run-mirror-update b/launcher-image/src/run-mirror-update index 76a42a2..47e1178 100755 --- a/launcher-image/src/run-mirror-update +++ b/launcher-image/src/run-mirror-update @@ -26,6 +26,9 @@ trap finish EXIT volume_prefix=cloner clone_prefix=cloner-runner +# last version of image +last_version=$(docker images $mirror_image --no-trunc --quiet) + name=${1:-} [ -n "$name" ] || die "No volume specified" @@ -47,21 +50,28 @@ then fi unset lines -# does it exist? -docker ps --quiet -a --no-trunc --filter name=^/$container_name$ > $scratch/existing -lines=$(wc -l $scratch/existing | cut -d' ' -f1) - -if ! [ $lines -eq 0 ] -then - log "Conflicting container exists, removing.." - docker rm $(cat $scratch/existing) -fi - -unset lines - -# does volume exist? +# check if volume does exist? docker volume inspect $name > /dev/null 2>&1 || die "Volume '$name' does not exist - exiting!" +# does it exist? +image_version=$(docker inspect --format='{{.Image}}' $container_name 2>/dev/null || true) + +# do I need to recreate image? +if ! [ "x$image_version" = "x$last_version" ] +then + # not empty string - need to delete first + if [ -n "$image_version" ] + then + log "Conflicting container exists, removing.." + docker rm $container_name + fi + # create new container + log "Creating new version of container.." + docker create -v $name:/data --name $container_name $mirror_image +fi + + log "Running container of update process..." -docker run -v $name:/data --name $container_name --rm $mirror_image | while read line; do log "$line"; done +docker start -a $container_name | while read line; do log "$line"; done log "Finished." +