github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/contrib/scripts/functions.sh (about)

     1  #!/bin/bash
     2  # Containers MUST be labeled with "cluster:test" to be restarted and stopped
     3  # by these functions.
     4  
     5  # May be called with an argument which is a docker compose file
     6  # to use *instead of* the default docker-compose.yml.
     7  function restartCluster {
     8    if [[ -z $1 ]]; then
     9      compose_file="docker-compose.yml"
    10    else
    11      compose_file="$(readlink -f $1)"
    12    fi
    13  
    14    basedir=$GOPATH/src/github.com/dgraph-io/dgraph
    15    pushd $basedir/dgraph >/dev/null
    16    echo "Rebuilding dgraph ..."
    17    if [[ "$OSTYPE" == "darwin"* ]]; then
    18      (env GOOS=linux GOARCH=amd64 go build) && mv -f dgraph $GOPATH/bin/dgraph
    19    else
    20      make install
    21    fi
    22    docker ps -a --filter label="cluster=test" --format "{{.Names}}" | xargs -r docker rm -f
    23    docker-compose -p dgraph -f $compose_file up --force-recreate --remove-orphans --detach || exit 1
    24    popd >/dev/null
    25  
    26    $basedir/contrib/wait-for-it.sh -t 60 localhost:6180 || exit 1
    27    $basedir/contrib/wait-for-it.sh -t 60 localhost:9180 || exit 1
    28    sleep 10 || exit 1
    29  }
    30  
    31  function stopCluster {
    32    basedir=$GOPATH/src/github.com/dgraph-io/dgraph
    33    pushd $basedir/dgraph >/dev/null
    34    docker ps --filter label="cluster=test" --format "{{.Names}}" \
    35    | xargs -r docker stop | sed 's/^/Stopped /'
    36    docker ps -a --filter label="cluster=test" --format "{{.Names}}" \
    37    | xargs -r docker rm | sed 's/^/Removed /'
    38    popd >/dev/null
    39  }