#!/bin/bash

source ./setenv

# generates a unique machine ID (runs on Mac)
MACHINE_NAME=$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 32)

# create a docker machine on AWS (512 gb disk space, 7.5 GB ram)
# this runs against the "development" VPC
echo Creating Docker machine: $MACHINE_NAME
docker-machine create --driver amazonec2 --amazonec2-region $REGION --amazonec2-iam-instance-profile $IAM_ROLE_INSTANCE_PROFILE --amazonec2-vpc-id $VPC --amazonec2-zone $ZONE --amazonec2-instance-type $INSTANCE_TYPE --amazonec2-subnet-id $SUBNET_ID --amazonec2-root-size $ROOT_DISK_SIZE --amazonec2-use-ebs-optimized-instance=true $MACHINE_NAME

# switch to AWS docker machine
eval $(docker-machine env $MACHINE_NAME)



#
# CUSTOMIZE DOCKER MACHINE
#

# update
docker-machine ssh $MACHINE_NAME "sudo apt-get install -y curl awscli"

# copy ebs-attach-mount.sh to docker machine
docker-machine scp _files/ebs-attach-mount.sh $MACHINE_NAME:/tmp

# mount volume: MongoDB
docker-machine ssh $MACHINE_NAME "sudo /bin/bash /tmp/ebs-attach-mount.sh $MONGODB_VOLUME_NAME /storage/mongodb"

# mount volume: Elastic Search
docker-machine ssh $MACHINE_NAME "sudo /bin/bash /tmp/ebs-attach-mount.sh $ELASTICSEARCH_VOLUME_NAME /storage/elasticsearch"

# mount volume: virtual hosts
docker-machine ssh $MACHINE_NAME "sudo /bin/bash /tmp/ebs-attach-mount.sh $VIRTUAL_HOSTS_VOLUME_NAME /storage/virtualhosts"

IP_ADDRESS=$(docker-machine ip $MACHINE_NAME)
#
# END CUSTOMIZE DOCKER MACHINE
#



echo Machine ID: $MACHINE_NAME
echo IP Address: $IP_ADDRESS

echo


