|
| 1 | +#!/bin/bash -ex |
| 2 | + |
| 3 | +# |
| 4 | +# Prepare a Deis Node image for Rackspace. |
| 5 | +# |
| 6 | +# Instructions: |
| 7 | +# |
| 8 | +# 1. Launch a vanilla Ubuntu 12.04.3 droplet (64-bit) |
| 9 | +# 2. Run this script (as root!) to optimize the image for faster provisioning |
| 10 | +# 3. Create a new snapshot named "deis-node-image" from this droplet |
| 11 | +# |
| 12 | + |
| 13 | +# Remove old kernel(s) |
| 14 | +dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge |
| 15 | + |
| 16 | +# Add the Docker repository key to your local keychain |
| 17 | +# using apt-key finger you can check the fingerprint matches 36A1 D786 9245 C895 0F96 6E92 D857 6A8B A88D 21E9 |
| 18 | +curl https://get.docker.io/gpg | apt-key add - |
| 19 | + |
| 20 | +# Add the Docker repository to your apt sources list. |
| 21 | +echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list |
| 22 | + |
| 23 | +# upgrade to latest packages |
| 24 | +apt-get update |
| 25 | +apt-get upgrade -yq |
| 26 | + |
| 27 | +# install required packages |
| 28 | +apt-get install lxc-docker-0.7.6 fail2ban curl git inotify-tools make python-setuptools python-pip -yq |
| 29 | + |
| 30 | +# wait for docker to start |
| 31 | +while [ ! -e /var/run/docker.sock ] ; do |
| 32 | + inotifywait -t 2 -e create $(dirname /var/run/docker.sock) |
| 33 | +done |
| 34 | + |
| 35 | +# pull docker images |
| 36 | +docker pull deis/slugrunner |
| 37 | + |
| 38 | +# install chef 11.x deps |
| 39 | +apt-get install -yq ruby1.9.1 ruby1.9.1-dev make |
| 40 | +update-alternatives --set ruby /usr/bin/ruby1.9.1 |
| 41 | +update-alternatives --set gem /usr/bin/gem1.9.1 |
| 42 | + |
| 43 | +# clean and remove old packages |
| 44 | +apt-get clean |
| 45 | +apt-get autoremove -yq |
| 46 | + |
| 47 | +# reset cloud-init |
| 48 | +rm -rf /var/lib/cloud |
| 49 | + |
| 50 | +# purge SSH authorized keys |
| 51 | +rm -f /home/ubuntu/.ssh/authorized_keys |
| 52 | +rm -f /root/.ssh/authorized_keys |
| 53 | + |
| 54 | +# remove /etc/chef so contents can't intefere with |
| 55 | +# node being converged (i.e. old keys) |
| 56 | +rm -f /etc/chef/* |
| 57 | + |
| 58 | +# purge /var/log |
| 59 | +find /var/log -type f | xargs rm |
| 60 | + |
| 61 | +# flush writes to block storage |
| 62 | +sync |
0 commit comments