|
| 1 | +#!/bin/bash -ex |
| 2 | + |
| 3 | +# |
| 4 | +# Prepare a Deis-optimized AMI from a vanilla Ubuntu 12.04 |
| 5 | +# Prepare a Deis-optimized Vagrant box from vanilla Ubuntu 12.04 |
| 6 | +# |
| 7 | +# Instructions: |
| 8 | +# |
| 9 | +# 1. Launch a vanilla Ubuntu 12.04 instance with `vagrant up` |
| 10 | +# 2. SSH in with `vagrant ssh`, do `sudo -i` and install the 3.8 kernel with: |
| 11 | +# apt-get update && apt-get install -yq linux-image-generic-lts-raring linux-headers-generic-lts-raring && reboot |
| 12 | +# 3. After reboot is complete, SSH in again and `uname -r` to confirm kernel is 3.8 |
| 13 | +# 4. Run this script (as root!) to optimize the image for fast boot times |
| 14 | +# 5. Create a new box with `vagrant package && cp -f package.box contrib/vagrant/deis-base.box` |
| 15 | +# |
| 16 | + |
| 17 | +# Remove any temporary work files, including the postinstall.sh script |
| 18 | +rm -f /home/${account}/{*.iso,postinstall*.sh} |
| 19 | + |
| 20 | +# Install some essentials and mDNS daemon |
| 21 | +apt-get install python-software-properties curl apt-transport-https -y |
| 22 | + |
| 23 | +# Add the Docker repository key to your local keychain |
| 24 | +# using apt-key finger you can check the fingerprint matches 36A1 D786 9245 C895 0F96 6E92 D857 6A8B A88D 21E9 |
| 25 | +curl https://get.docker.io/gpg | apt-key add - |
| 26 | + |
| 27 | +# Add the Docker repository to your apt sources list. |
| 28 | +echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list |
| 29 | + |
| 30 | +# upgrade to latest packages |
| 31 | +apt-get update |
| 32 | +apt-get dist-upgrade -yq |
| 33 | + |
| 34 | +# install required packages |
| 35 | +apt-get install lxc-docker git make python-setuptools python-pip -yq |
| 36 | + |
| 37 | +# create buildstep docker image |
| 38 | +git clone https://github.com/opdemand/buildstep.git |
| 39 | +cd buildstep |
| 40 | +git checkout deis |
| 41 | +make |
| 42 | +cd .. |
| 43 | +rm -rf buildstep |
| 44 | + |
| 45 | +# install chef 11.x deps |
| 46 | +apt-get install -yq ruby1.9.1 ruby1.9.1-dev make |
| 47 | +update-alternatives --set ruby /usr/bin/ruby1.9.1 |
| 48 | +update-alternatives --set gem /usr/bin/gem1.9.1 |
| 49 | + |
| 50 | +# install mDNS support |
| 51 | +apt-get install avahi-daemon -yq |
| 52 | + |
| 53 | +# clean and remove old packages |
| 54 | +apt-get clean |
| 55 | +apt-get autoremove -yq |
| 56 | + |
| 57 | +# reset cloud-init |
| 58 | +rm -rf /var/lib/cloud |
| 59 | + |
| 60 | +# purge SSH authorized keys |
| 61 | +# rm -f /home/ubuntu/.ssh/authorized_keys |
| 62 | +rm -f /root/.ssh/authorized_keys |
| 63 | + |
| 64 | +# ssh host keys are automatically regenerated |
| 65 | +# on system boot by ubuntu cloud init |
| 66 | + |
| 67 | +# purge /var/log |
| 68 | +find /var/log -type f | xargs rm |
| 69 | + |
| 70 | +# Removing leftover leases and persistent rules |
| 71 | +rm -f /var/lib/dhcp3/* |
| 72 | + |
| 73 | +# Make sure Udev doesn't block our network, see: http://6.ptmc.org/?p=164 |
| 74 | +rm /etc/udev/rules.d/70-persistent-net.rules |
| 75 | +mkdir /etc/udev/rules.d/70-persistent-net.rules |
| 76 | +rm -rf /dev/.udev/ |
| 77 | +rm /lib/udev/rules.d/75-persistent-net-generator.rules |
| 78 | + |
| 79 | +# flush writes to block storage |
| 80 | +sync |
| 81 | + |
| 82 | +# Zero out the free space to save space in the final image |
| 83 | +dd if=/dev/zero of=/EMPTY bs=1M |
| 84 | +rm -f /EMPTY |
0 commit comments