Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Last active May 30, 2016 06:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjeanes/61a359b74a3ae641311c7781e2ca6e67 to your computer and use it in GitHub Desktop.
Save bjeanes/61a359b74a3ae641311c7781e2ca6e67 to your computer and use it in GitHub Desktop.
Little script for me to pipe over SSH to a fresh Ubuntu VPS/VM to get it running a docker agent (used with cloudatcost.com as cheap build boxes)
#!/usr/bin/env bash
if [ -z "$BUILDKITE_AGENT_TOKEN" ]; then
echo
>&2 echo "No buildkite agent token set! Set BUILDKITE_AGENT_TOKEN"
exit 1
fi
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
apt-get -qq -y update
apt-get -qq -y install apt-transport-https ca-certificates
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list
apt-get -qq -y update
apt-get -qq -y purge lxc-docker
apt-get -qq -y install linux-image-extra-`uname -r` apparmor
apt-get -qq -y install docker-engine
service docker start
DOCKER_VERSION="`docker version | awk '/Version:/ { if(lastLine == "Server:") { print $2 } } { lastLine = $1 }'`"
docker run -d --restart=always --name buildkite-agent \
-v /var/run/docker.sock:/var/run/docker.sock \
-e BUILDKITE_AGENT_TOKEN="$BUILDKITE_AGENT_TOKEN" \
-e BUILDKITE_AGENT_NAME="ubuntu-%n" \
-e BUILDKITE_AGENT_PRIORITY=10 \
-e BUILDKITE_AGENT_META_DATA="docker=$DOCKER_VERSION" \
buildkite/agent
DOCKER_GC_CMD="docker run --name=docker-gc --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc -e FORCE_IMAGE_REMOVAL=1 -e FORCE_CONTAINER_REMOVAL=1 -e GRACE_PERIOD_SECONDS=7200 spotify/docker-gc"
echo "0 * * * * root $DOCKER_GC_CMD" > /etc/cron.d/docker-gc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment