#!/bin/bash # Copyright 2017 AT&T Intellectual Property, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #. What this is: Deployment script for a mult-node docker-ce cluster. #. Prerequisites: #. - Ubuntu server for master and worker nodes #. Usage: #. $ git clone https://gerrit.opnfv.org/gerrit/models ~/models #. $ cd ~/models/tools/docker #. #. Usage: #. $ bash docker_cluster.sh all "" #. Automate setup and start demo services. #. : master node IPs #. : space-separated list of worker node IPs #. $ bash docker_cluster.sh setup "" #. Installs and starts master and worker nodes. #. $ bash docker_cluster.sh create #. : Demo service name to start. #. Currently supported: nginx #. $ bash docker_cluster.sh delete #. : Service name to delete. #. $ bash docker_cluster.sh clean [] #. : optional IP address of node to clean. #. By default, cleans the entire cluster. #. function log() { f=$(caller 0 | awk '{print $2}') l=$(caller 0 | awk '{print $1}') echo "$f:$l ($(date)) $1" } # Setup master and worker hosts function setup() { # Per https://docs.docker.com/engine/swarm/swarm-tutorial/ cat >~/tmp/env.sh <~/tmp/prereqs.sh <<'EOF' #!/bin/bash # Per https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/ sudo apt-get remove -y docker docker-engine docker.io docker-ce sudo apt-get update sudo apt-get install -y \ linux-image-extra-$(uname -r) \ linux-image-extra-virtual sudo apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" sudo apt-get update sudo apt-get install -y docker-ce EOF # jq is used for parsing API reponses sudo apt-get install -y jq scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ~/tmp/prereqs.sh ubuntu@$master:/home/ubuntu/prereqs.sh ssh -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$master bash /home/ubuntu/prereqs.sh # activate docker API # Per https://www.ivankrizsan.se/2016/05/18/enabling-docker-remote-api-on-ubuntu-16-04/ ssh -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$master <