Skip to content

Instantly share code, notes, and snippets.

@cliffom
Created February 9, 2016 01:27
Show Gist options
  • Save cliffom/97905344ca35bc032745 to your computer and use it in GitHub Desktop.
Save cliffom/97905344ca35bc032745 to your computer and use it in GitHub Desktop.
Docker Cloud AWS Kickstart Script
#!/bin/bash
DEPLOYMENT_TIMEOUT="5m"
METADATA_SERVICE_URL="http://169.254.169.254/latest/meta-data"
apt-get update
# apt-get upgrade -y
apt-get install -y jq python-pip
pip install docker-cloud awscli
export DOCKERCLOUD_USER=<DOCKERCLOUD_USER>
export DOCKERCLOUD_PASS=<DOCKERCLOUD_PASS>
export AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>
export AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
export AWS_DEFAULT_REGION=$(curl -fs ${METADATA_SERVICE_URL}/placement/availability-zone | sed 's/.$//')
docker-cloud node byo | sed -n 4p | source /dev/stdin
export DOCKERCLOUD_UUID=$(cat /etc/dockercloud/agent/dockercloud-agent.conf | jq -r .UUID)
echo "Waiting for node to be deployed..."
timeout $DEPLOYMENT_TIMEOUT bash -c "while [ \"\$(docker-cloud node inspect $DOCKERCLOUD_UUID | jq -r .state)\" != \"Deployed\" ]; do sleep 10; done;"
if [ $? != 0 ]; then echo "Node never came up"; exit 2; fi
INSTANCE_ID=$(curl -fs ${METADATA_SERVICE_URL}/instance-id)
EC2_TAGS=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" | jq -r '.Tags | map(select(.Key)) | .[].Value')
for TAG in $EC2_TAGS
do
docker-cloud tag add -t $TAG $DOCKERCLOUD_UUID
done
usermod -a -G docker ubuntu
@cliffom
Copy link
Author

cliffom commented Feb 9, 2016

Thanks to @revett for the initial gist for Tutum: https://gist.github.com/revett/b2bf66e95589139529b5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment