|
| 1 | +#!/bin/bash -ex |
| 2 | + |
| 3 | +# |
| 4 | +# Prepare a Deis-optimized Controller AMI from a vanilla Ubuntu 12.04 |
| 5 | +# |
| 6 | +# Instructions: |
| 7 | +# |
| 8 | +# 1. Launch a vanilla Ubuntu 12.04 instance (64-bit with an EBS root volume) |
| 9 | +# 2. SSH in and install the 3.8 kernel with: |
| 10 | +# apt-get update && apt-get install -yq linux-image-generic-lts-raring linux-headers-generic-lts-raring && reboot |
| 11 | +# 3. After reboot is complete, SSH in and `uname -r` to confirm kernel is 3.8 |
| 12 | +# 4. Run this script (as root!) to optimize the image for fast boot times |
| 13 | +# 5. Create a new AMI from the root volume |
| 14 | +# 6. Distribute the AMI to other regions using `ec2-copy-image` |
| 15 | +# 7. Update `provision-ec2-controller.sh` script with new AMIs |
| 16 | +# |
| 17 | + |
| 18 | +# Remove old kernel(s) |
| 19 | +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 |
| 20 | + |
| 21 | +# Add the Docker repository key to your local keychain |
| 22 | +# using apt-key finger you can check the fingerprint matches 36A1 D786 9245 C895 0F96 6E92 D857 6A8B A88D 21E9 |
| 23 | +curl https://get.docker.io/gpg | apt-key add - |
| 24 | + |
| 25 | +# Add the Docker repository to your apt sources list. |
| 26 | +echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list |
| 27 | + |
| 28 | +# upgrade to latest packages |
| 29 | +apt-get update |
| 30 | +apt-get dist-upgrade -yq |
| 31 | + |
| 32 | +# install required packages |
| 33 | +apt-get install lxc-docker-0.7.6 fail2ban curl git inotify-tools make python-setuptools python-pip -yq |
| 34 | + |
| 35 | +# wait for docker to start |
| 36 | +while [ ! -e /var/run/docker.sock ] ; do |
| 37 | + inotifywait -t 2 -e create $(dirname /var/run/docker.sock) |
| 38 | +done |
| 39 | + |
| 40 | +# pull docker images |
| 41 | +docker pull deis/etcd |
| 42 | +docker pull deis/postgres |
| 43 | +docker pull deis/redis |
| 44 | +docker pull deis/server |
| 45 | +docker pull deis/worker |
| 46 | +docker pull deis/registry |
| 47 | +docker pull deis/builder |
| 48 | +docker pull deis/rsyslog |
| 49 | + |
| 50 | +# install chef 11.x deps |
| 51 | +apt-get install -yq ruby1.9.1 ruby1.9.1-dev make |
| 52 | +update-alternatives --set ruby /usr/bin/ruby1.9.1 |
| 53 | +update-alternatives --set gem /usr/bin/gem1.9.1 |
| 54 | + |
| 55 | +# clean and remove old packages |
| 56 | +apt-get clean |
| 57 | +apt-get autoremove -yq |
| 58 | + |
| 59 | +# reset cloud-init |
| 60 | +rm -rf /var/lib/cloud |
| 61 | + |
| 62 | +# purge SSH authorized keys |
| 63 | +rm -f /home/ubuntu/.ssh/authorized_keys |
| 64 | +rm -f /root/.ssh/authorized_keys |
| 65 | + |
| 66 | +# remove /etc/chef so contents can't intefere with |
| 67 | +# node being converged (i.e. old keys) |
| 68 | +rm -f /etc/chef/* |
| 69 | + |
| 70 | +# purge /var/log |
| 71 | +find /var/log -type f | xargs rm |
| 72 | + |
| 73 | +# flush writes to block storage |
| 74 | +sync |
0 commit comments