VOL-211: Integrate a clustered Consul service with all Voltha components that use it

The Dockerfile for the CLI container runs a setup.sh script at container startup.
This script hard-codes the Consul lookup (-L) and endpoint (-C) arguments passed
to /cli/cli/main.py. In Docker swarm mode, Consul is no longer used for service
lookup; instead, Docker's DNS is used. It is desirable that the lookup argument
be specified in the compose file. For v2 -L is supplied and the Voltha gRPC and
SIM endpoints are specified by Consul service name. For v3 -L is withheld and the
Voltha gRPC and SIM endpoints are specified by Docker service name. Therefore, in
addition to a new v3 compose file for use by Docker swarm, the existing v2 compose
file used by the single-node Voltha implementation must be changed.

Change-Id: Ifef3e06ef9479594bfb11328dd1b1004e4f6c74f
diff --git a/cli/setup.sh b/cli/setup.sh
index d800ee9..ee0a643 100755
--- a/cli/setup.sh
+++ b/cli/setup.sh
@@ -1,11 +1,28 @@
 #!/bin/bash
+
+while getopts LC:g:s: option
+do
+    case "${option}"
+    in
+	L) LOOKUP_OPT="-L";;
+	C) CONSUL_OPT="-C ${OPTARG}";;
+	g) GRPC_OPT="-g ${OPTARG}";;
+	s) SIM_OPT="-s ${OPTARG}";;
+    esac
+done
+
+if [ -z "$CONSUL_OPT" ]
+then
+    CONSUL_OPT="-C $DOCKER_HOST_IP:8500"
+fi
+
 echo "export DOCKER_HOST_IP=$DOCKER_HOST_IP" > /home/voltha/.bashrc
 echo "export PYTHONPATH=/cli" >> /home/voltha/.bashrc
 echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /home/voltha/.bashrc
 echo "export DOCKER_HOST_IP=$DOCKER_HOST_IP" > /home/voltha/.bash_profile
 echo "export PYTHONPATH=/cli" >> /home/voltha/.bash_profile
 echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /home/voltha/.bash_profile
-echo '/cli/cli/main.py -L -C $DOCKER_HOST_IP:8500' >> /home/voltha/.bash_profile
+echo "/cli/cli/main.py $LOOKUP_OPT $CONSUL_OPT $GRPC_OPT $SIM_OPT" >> /home/voltha/.bash_profile
 echo "logout" >> /home/voltha/.bash_profile
 chown voltha.voltha /home/voltha/.bash_profile
 /usr/sbin/sshd -D
diff --git a/compose/docker-compose-system-test-encrypted.yml b/compose/docker-compose-system-test-encrypted.yml
index d6c4c25..55063da 100644
--- a/compose/docker-compose-system-test-encrypted.yml
+++ b/compose/docker-compose-system-test-encrypted.yml
@@ -156,6 +156,10 @@
   #
   vcli:
     image: cord/vcli
+    command: [
+      "/cli/cli/setup.sh",
+      "-L"
+    ]
     environment:
       DOCKER_HOST_IP: "${DOCKER_HOST_IP}"
     ports:
diff --git a/compose/docker-compose-system-test.yml b/compose/docker-compose-system-test.yml
index 7d15c16..2e2185c 100644
--- a/compose/docker-compose-system-test.yml
+++ b/compose/docker-compose-system-test.yml
@@ -154,6 +154,10 @@
   #
   vcli:
     image: cord/vcli
+    command: [
+      "/cli/cli/setup.sh",
+      "-L"
+    ]
     environment:
       DOCKER_HOST_IP: "${DOCKER_HOST_IP}"
     ports:
diff --git a/compose/docker-compose-vcli.yml b/compose/docker-compose-vcli.yml
new file mode 100644
index 0000000..f3aafa3
--- /dev/null
+++ b/compose/docker-compose-vcli.yml
@@ -0,0 +1,32 @@
+#
+# This Docker stackfile deploys a Voltha CLI container along with one backup.
+#
+# The stackfile assumes that overlay network 'voltha_net' has already been
+# created. To deploy the stack, issue the command:
+#
+#     docker stack deploy -c docker-compose-vcli.yml cli
+#
+
+version: "3"
+services:
+  cli:
+    image: cord/vcli:latest
+    deploy:
+      replicas: 2
+    environment:
+      DOCKER_HOST_IP: "${DOCKER_HOST_IP}"
+    entrypoint:
+      - /cli/cli/setup.sh
+      - -C consul:8500
+      - -g voltha:50555
+      - -s voltha:18880
+    networks:
+      - voltha-net
+    ports:
+      - "5022:22"
+      
+networks:
+  voltha-net:
+    external:
+      name: voltha_net
+