Skip to content

Commit

Permalink
Added Microsoft Azure, Updated to 1.12 GA (docker#44)
Browse files Browse the repository at this point in the history
* Added Microsoft Azure, Updated to 1.12 GA

* Added Microsoft Azure, Updated to 1.12 GA

Signed-off-by: Daniel Falkner <[email protected]>

* Added azure to error message

Signed-off-by: Daniel Falkner <[email protected]>
  • Loading branch information
derdanu authored and Mano Marks committed Aug 3, 2016
1 parent ebe2d09 commit e560a1c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
15 changes: 11 additions & 4 deletions swarm-mode/beginner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Script that create a swarm cluster and deploy a simple service.
Swarm is created with Swarm mode of Engine 1.12. Can be created on
* Virtualbox
* Microsoft Azure
* Digitalocean
* Amazon EC2

Expand All @@ -12,6 +13,7 @@ Note: currently, if deploying on AWS, only EU (Ireland) region is available. Mak

```
./swarm.sh [--driver provider]
[--azure-subscription-id azure_subscription_id]
[--amazonec2-access-key ec2_access_key]
[--amazonec2-secret-key ec2_secret_key]
[--amazonec2-security-group ec2_security_group]
Expand All @@ -25,11 +27,12 @@ Note: currently, if deploying on AWS, only EU (Ireland) region is available. Mak
```

Several parameters can be provided
* driver used ("virtualbox", "digitalocean", "amazonec2") (default: "virtualbox")
* driver used ("azure", "virtualbox", "digitalocean", "amazonec2") (default: "virtualbox")
* number of manager (default: 3)
* number of worker (default: 5)
* number of replicas for the deployed service (lucj/randomcity:1.1) (default: 5)
* port exposed by the cluster (default: 8080)
* azure subscription id (if azure driver selected)
* digitalocean token (if digitalocean driver specified)
* amazon access key, secret key, security group (currently only for EU (Ireland) region) (if amazonec2 driver is specified)

Expand Down Expand Up @@ -133,6 +136,12 @@ The requests are dispatched in a round robin fashion to the running containers.

# Examples with other drivers

## Run 3 managers and 6 workers on Microsoft Azure based on ehazlett/docker-demo image (default image if none specified)

```
./swarm.sh --driver azure --azure-subscription-id $AZURE_SUBSCRIPTION_ID --manager 3 --worker 6
```

## Run 3 managers and 6 workers on DigitalOcean and use service based on ehazlett/docker-demo image (default image if none specified)

```
Expand All @@ -155,9 +164,7 @@ note: make sure the security group provided (**default** in this example) allow

# Status

- [x] Virtualbox deployment
- [x] Digitalocean deployment (Ubuntu 14.04 / 1gb / lon1)
- [x] Amazon deployment (Ubuntu 14.04 / t2.micro / EU (Ireland))
- [ ] Azure deployment with image / size / region selection
- [ ] DigitalOcean deployment with image / size / region selection
- [ ] Amazon deployment with AMI / instance type / region selection
- [ ] Amazon deployment with automatic opening of exposed port in SecurityGroup
61 changes: 43 additions & 18 deletions swarm-mode/beginner/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MANAGER=${PREFIX}-manager
WORKER=${PREFIX}-worker

function usage {
echo "Usage: $0 [--driver provider] [--amazonec2-access-key ec2_access_key] [--amazonec2-secret-key ec2_secret_key] [--amazonec2-security-group ec2_security_group] [--do_token do_token][-m|--manager nbr_manager] [-w|--worker nbr_worker] [-r|--replica nbr_replica] [-p|--port exposed_port] [--service_image service_image] [--service_port service_port]"
echo "Usage: $0 [--driver provider] [--azure-subscription-id] [--amazonec2-access-key ec2_access_key] [--amazonec2-secret-key ec2_secret_key] [--amazonec2-security-group ec2_security_group] [--do_token do_token][-m|--manager nbr_manager] [-w|--worker nbr_worker] [-r|--replica nbr_replica] [-p|--port exposed_port] [--service_image service_image] [--service_port service_port]"
exit 1
}

Expand Down Expand Up @@ -79,15 +79,19 @@ while [ "$#" -gt 0 ]; do
EC2_SECURITY_GROUP="$2"
shift 2
;;
--azure-subscription-id)
AZURE_SUBSCRIPTION_ID="$2"
shift 2
;;
-h|--help)
usage
;;
esac
done

# Value of driver parameter's value must be among "digitalocean", "amazonec2", "virtualbox" (if no value is provided, "virtualbox" driver is used)
if [ "$DRIVER" != "virtualbox" -a "$DRIVER" != "digitalocean" -a "$DRIVER" != "amazonec2" ];then
error "driver value must be among digitalocean, amazonec2, virtualbox"
# Value of driver parameter's value must be among "azure", "digitalocean", "amazonec2", "virtualbox" (if no value is provided, "virtualbox" driver is used)
if [ "$DRIVER" != "virtualbox" -a "$DRIVER" != "digitalocean" -a "$DRIVER" != "amazonec2" -a "$DRIVER" != "azure" ];then
error "driver value must be among azure, digitalocean, amazonec2, virtualbox"
fi

# No additional parameters needed for virtualbox driver
Expand Down Expand Up @@ -117,6 +121,21 @@ if [ "$DRIVER" == "amazonec2" ];then
echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (eu-west-1 / t2.micro / Ubuntu 14.04)"
fi

# Make sure mandatory parameter for azure driver
if [ "$DRIVER" == "azure" ];then
if [ "$AZURE_SUBSCRIPTION_ID" == "" ];then
error "--azure-subscription-id must be provided"
fi
# For Azure Storage Container the Manager and Worker prefix must be lowercase
PREFIX=$(date "+%Y%m%dt%H%M%S")
MANAGER=${PREFIX}-manager
WORKER=${PREFIX}-worker

PERMISSION="sudo"
ADDITIONAL_PARAMS="--driver azure --azure-subscription-id ${AZURE_SUBSCRIPTION_ID} --azure-open-port ${EXPOSED_PORT}"
echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (westus / Standard_A2 / Ubuntu 15.10)"
fi

echo "-> service is based on image ${SERVICE_IMAGE} exposing port ${SERVICE_PORT}"
echo "-> once deployed service will be accessible via port ${EXPOSED_PORT} to the outside"

Expand All @@ -132,6 +151,8 @@ fi
function getIP {
if [ "$DRIVER" == "amazonec2" ]; then
echo $(docker-machine inspect -f '{{ .Driver.PrivateIPAddress }}' $1)
elif [ "$DRIVER" == "azure" ]; then
echo $(docker-machine ssh $1 ifconfig eth0 | awk '/inet addr/{print substr($2,6)}')
else
echo $(docker-machine inspect -f '{{ .Driver.IPAddress }}' $1)
fi
Expand All @@ -143,11 +164,24 @@ function check_status {
fi
}

function get_manager_token {
echo $(docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm join-token manager -q)
}

function get_worker_token {
echo $(docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm join-token worker -q)
}

# Create Docker host for managers
function create_manager {
for i in $(seq 1 $NBR_MANAGER); do
echo "-> creating Docker host for manager $i (please wait)"
docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i 1>/dev/null
# Azure needs Stdout for authentication. Workaround: Show Stdout on first Manager.
if [ "$DRIVER" == "azure" ] && [ "$i" -eq 1 ];then
docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i
else
docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i 1>/dev/null
fi
done
}

Expand All @@ -162,32 +196,24 @@ function create_workers {
# Init swarm from first manager
function init_swarm {
echo "-> init swarm from ${MANAGER}1"
docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm init --listen-addr $(getIP ${MANAGER}1):2377
docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm init --listen-addr $(getIP ${MANAGER}1):2377 --advertise-addr $(getIP ${MANAGER}1):2377
}

# Join other managers to the cluster
function join_other_managers {
if [ "$((NBR_MANAGER-1))" -ge "1" ];then
for i in $(seq 2 $NBR_MANAGER);do
echo "-> ${MANAGER}$i requests membership to the swarm"
docker-machine ssh ${MANAGER}$i $PERMISSION docker swarm join --manager --listen-addr $(getIP ${MANAGER}$i):2377 $(getIP ${MANAGER}1):2377 2>&1
docker-machine ssh ${MANAGER}$i $PERMISSION docker swarm join --token $(get_manager_token) --listen-addr $(getIP ${MANAGER}$i):2377 --advertise-addr $(getIP ${MANAGER}$i):2377 $(getIP ${MANAGER}1):2377 2>&1
done
fi
}

# Accept other manager that requested membership to the cluster
function accept_other_managers {
echo "-> accepting membership requests from other managers"
for id in $(docker-machine ssh ${MANAGER}1 $PERMISSION docker node ls | grep Pending | awk '{print $1}'); do
docker-machine ssh ${MANAGER}1 $PERMISSION docker node accept $id
done
}

# Join worker to the cluster
function join_workers {
for i in $(seq 1 $NBR_WORKER);do
echo "-> join worker $i to the swarm"
docker-machine ssh ${WORKER}$i $PERMISSION docker swarm join --listen-addr $(getIP ${WORKER}$i):2377 $(getIP ${MANAGER}1):2377
docker-machine ssh ${WORKER}$i $PERMISSION docker swarm join --token $(get_worker_token) --listen-addr $(getIP ${WORKER}$i):2377 --advertise-addr $(getIP ${WORKER}$i):2377 $(getIP ${MANAGER}1):2377
done
}

Expand Down Expand Up @@ -222,7 +248,7 @@ function status {
echo
echo "-> list tasks"
echo
docker-machine ssh ${MANAGER}1 $PERMISSION docker service tasks demo
docker-machine ssh ${MANAGER}1 $PERMISSION docker service ps demo
echo
echo "-> list machines"
docker-machine ls | egrep $PREFIX
Expand All @@ -240,7 +266,6 @@ function main {
create_workers
init_swarm
join_other_managers
accept_other_managers
join_workers
deploy_service
wait_service
Expand Down

0 comments on commit e560a1c

Please sign in to comment.