Skip to content

Commit

Permalink
Clean dev script
Browse files Browse the repository at this point in the history
- create functions for handle docker ops
- split long line arguments list with new line
- wait for docker service removal on exit
  • Loading branch information
krhubert committed Aug 7, 2019
1 parent e8c7197 commit d3e5225
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions dev
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@ LDFLAGS+=" -X 'github.com/mesg-foundation/engine/config.EnvMarketplaceToken=0x58

MESG_SERVER_PORT=${MESG_SERVER_PORT:-50052}

networkExists=$(docker network list -f name=$MESG_NAME -f driver=overlay -q)
if [ "$networkExists" == "" ]; then
docker network create --driver overlay $MESG_NAME --label com.docker.stack.namespace=$MESG_NAME
fi
function onexit {
set +e
echo -e "\nshuting down, please wait..."
docker_service_remove "$MESG_NAME"
docker_network_remove "$MESG_NAME"
}

function docker_service_remove {
docker service rm $1
docker wait $(docker ps -f name="$1" -q) 2> /dev/null
}

function docker_network_exist {
[ ! -z $(docker network list -f name="$1" -f driver=overlay -q) ]
}

function docker_network_create {
echo -ne "create docker network $1: "
docker network create --driver overlay "$1" --label com.docker.stack.namespace="$1"
}

function docker_network_remove {
echo -ne "remove docker network: "
docker network remove "$1"
}

for s in systemservices/* ; do
if [ -d "$s" ]; then
Expand Down Expand Up @@ -68,24 +89,27 @@ if [[ ! $BINCACHED ]] || [[ ! $DOCKERCACHED ]]; then
docker build -f Dockerfile.dev -t "mesg/engine:$VERSION" .
fi

# docker service rm engine

trap onexit EXIT INT
trap onexit EXIT

function onexit {
docker service rm $MESG_NAME
}
if ! docker_network_exist "$MESG_NAME"; then
docker_network_create "$MESG_NAME"
fi

echo "create docker service: "
docker service create \
--name $MESG_NAME \
--tty \
--label com.docker.stack.namespace=$MESG_NAME --label com.docker.stack.image=mesg/engine:$VERSION \
--label com.docker.stack.namespace=$MESG_NAME \
--label com.docker.stack.image=mesg/engine:$VERSION \
--env MESG_NAME=$MESG_NAME \
--env MESG_LOG_FORMAT=$MESG_LOG_FORMAT \
--env MESG_LOG_FORCECOLORS=$MESG_LOG_FORCECOLORS \
--env MESG_LOG_LEVEL=$MESG_LOG_LEVEL \
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock --mount type=bind,source=$MESG_PATH,destination=/root/.mesg \
--network $MESG_NAME --publish $MESG_SERVER_PORT:50052 \
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock \
--mount type=bind,source=$MESG_PATH,destination=/root/.mesg \
--network $MESG_NAME \
--publish $MESG_SERVER_PORT:50052 \
mesg/engine:$VERSION

docker service logs --follow --raw $MESG_NAME

0 comments on commit d3e5225

Please sign in to comment.