diff --git a/.gitignore b/.gitignore index be5e011..a32e551 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -packer_cache \ No newline at end of file +packer_cache +*.box +output-* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..61e5605 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +build: + packer build template.json + +only-vmware: + packer build --only vmware-iso template.json + +only-virtualbox: + packer build --only virtualbox-iso template.json + +clean: + rm -fv *.box + rm -rfv output-* + +add-box: + -vagrant box remove docker-vmware + vagrant box add ubuntu-14.04-with-docker.vmware.box --name docker-vmware diff --git a/scripts/dev-tools.sh b/scripts/dev-tools.sh new file mode 100644 index 0000000..cada6a6 --- /dev/null +++ b/scripts/dev-tools.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +apt-get -yq install dstat diff --git a/scripts/docker-compose.sh b/scripts/docker-compose.sh new file mode 100755 index 0000000..acec33c --- /dev/null +++ b/scripts/docker-compose.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +curl -L https://github.com/docker/compose/releases/download/1.4.1/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose +chmod +x /usr/local/bin/docker-compose diff --git a/scripts/docker-containers.sh b/scripts/docker-containers.sh index 5240276..7c0ce5d 100755 --- a/scripts/docker-containers.sh +++ b/scripts/docker-containers.sh @@ -3,27 +3,14 @@ set -eu CONTAINERS=( - "clue/httpie" + "java:8u66" + "nginx:1.9.1" "mysql" - "selenium/hub:2.44.0" "shouldbee/ansible-boto" "shouldbee/baseimage-go" - "shouldbee/bootstrap-compile-kit" - "shouldbee/codecept" - "shouldbee/coffeescript" - "shouldbee/dredd" "shouldbee/flyway" "shouldbee/go" - "shouldbee/html2pdf" - "shouldbee/nginx-https-reverse-proxy" - "shouldbee/phantomjs" - "shouldbee/php" - "shouldbee/php-cs-fixer" - "shouldbee/scala:2.10.4" "shouldbee/selenium" - "shouldbee/selenium-node-chrome" - "shouldbee/selenium-node-firefox" - "shouldbee/tcpproxy" "sylvainlasnier/memcached" ) diff --git a/scripts/docker-fig.sh b/scripts/docker-fig.sh deleted file mode 100755 index 6076edc..0000000 --- a/scripts/docker-fig.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -curl -L https://github.com/docker/compose/releases/download/0.5.2/linux > /usr/local/bin/fig -chmod +x /usr/local/bin/fig diff --git a/scripts/docker.sh b/scripts/docker.sh index d7d339a..e5db65c 100755 --- a/scripts/docker.sh +++ b/scripts/docker.sh @@ -11,21 +11,9 @@ do sudo usermod -a -G docker $user done -# add repository -sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 - -sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" - # install curl apt-get update apt-get install -y curl -# Update your sources -apt-get update - -# Install. Confirm install. -# apt-get install -y docker.io -apt-get install -y lxc-docker - -# Link docker.io to docker -# ln -s /usr/bin/docker.io /usr/bin/docker +# install docker +curl -sSL https://get.docker.com/ | sh diff --git a/scripts/fusion.sh b/scripts/fusion.sh index bb97044..016f7e7 100644 --- a/scripts/fusion.sh +++ b/scripts/fusion.sh @@ -1,11 +1,18 @@ -# Install the Linux headers -apt-get -y install build-essential linux-headers-$(uname -r) +set -eu -# Install the VMware Fusion guest tools +echo "==> install the linux headers" +apt-get -yqq install git build-essential linux-headers-$(uname -r) + +echo "==> install the vmware fusion guest tools" cd /tmp + +echo "==> download vmware-tools-patches" +git clone https://github.com/rasa/vmware-tools-patches.git mkdir -p /mnt/cdrom mount -o loop ~/linux.iso /mnt/cdrom -tar zxf /mnt/cdrom/VMwareTools-*.tar.gz -C /tmp/ -/tmp/vmware-tools-distrib/vmware-install.pl -d +cp /mnt/cdrom/VMwareTools-*.tar.gz /tmp/vmware-tools-patches/ +cd /tmp/vmware-tools-patches/ +./untar-and-patch-and-compile.sh rm /home/ubuntu/linux.iso umount /mnt/cdrom +rm -rf /tmp/vmware-tools-patches diff --git a/scripts/vagrant.sh b/scripts/vagrant.sh index 89f072f..e860b3d 100755 --- a/scripts/vagrant.sh +++ b/scripts/vagrant.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -eu + useradd -m -s /bin/bash vagrant for user in vagrant ubuntu @@ -15,15 +17,15 @@ do mkdir -p /home/$user/.ssh chmod 700 /home/$user/.ssh cd /home/$user/.ssh - wget --no-check-certificate 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -O authorized_keys + wget --quiet --no-check-certificate 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -O authorized_keys chmod 600 /home/$user/.ssh/authorized_keys chown -R $user /home/$user/.ssh done # Install NFS for ubuntu -apt-get update -apt-get install -y nfs-common +apt-get -qq update +apt-get -yqq install nfs-common # Set up .bashrc cat << EOF >> /home/vagrant/.bashrc diff --git a/scripts/vm_cleanup.sh b/scripts/vm_cleanup.sh index 70df56c..2c35e4c 100755 --- a/scripts/vm_cleanup.sh +++ b/scripts/vm_cleanup.sh @@ -1,5 +1,11 @@ #!/bin/bash +# Removing apt caches +echo "cleaning apt caches" +rm -rf /var/lib/apt/lists/* +apt-get autoremove +apt-get clean + # Removing leftover leases and persistent rules echo "cleaning up dhcp leases" rm /var/lib/dhcp/* @@ -14,6 +20,10 @@ rm /lib/udev/rules.d/75-persistent-net-generator.rules echo "Adding a 2 sec delay to the interface up, to make the dhclient happy" echo "pre-up sleep 2" >> /etc/network/interfaces +# Truncate log files +echo "cleaning /var/log files" +find /var/log -type f -exec truncate -s 0 {} \; + # Zero out the free space to save space in the final image: echo "Zeroing device to make space..." dd if=/dev/zero of=/EMPTY bs=1M diff --git a/template.json b/template.json index 0fb36c4..c9ee7b4 100644 --- a/template.json +++ b/template.json @@ -3,12 +3,13 @@ "aws_access_key": "", "aws_secret_key": "" }, - "builders": [ { "type": "vmware-iso", - "iso_url": "http://ftp.jaist.ac.jp/pub/Linux/ubuntu-releases/trusty/ubuntu-14.04.2-server-amd64.iso", - "iso_checksum": "8acd2f56bfcba2f7ac74a7e4a5e565ce68c024c38525c0285573e41c86ae90c0", + "vm_name": "ubuntu", + "headless": true, + "iso_url": "http://ftp.jaist.ac.jp/pub/Linux/ubuntu-releases/trusty/ubuntu-14.04.3-server-amd64.iso", + "iso_checksum": "a3b345908a826e262f4ea1afeb357fd09ec0558cf34e6c9112cead4bb55ccdfb", "iso_checksum_type": "sha256", "boot_wait": "5s", "boot_command": [ @@ -29,8 +30,10 @@ }, { "type": "virtualbox-iso", - "iso_url": "http://ftp.jaist.ac.jp/pub/Linux/ubuntu-releases/trusty/ubuntu-14.04.2-server-amd64.iso", - "iso_checksum": "8acd2f56bfcba2f7ac74a7e4a5e565ce68c024c38525c0285573e41c86ae90c0", + "vm_name": "ubuntu", + "headless": true, + "iso_url": "http://ftp.jaist.ac.jp/pub/Linux/ubuntu-releases/trusty/ubuntu-14.04.3-server-amd64.iso", + "iso_checksum": "a3b345908a826e262f4ea1afeb357fd09ec0558cf34e6c9112cead4bb55ccdfb", "iso_checksum_type": "sha256", "boot_wait": "5s", "boot_command": [ @@ -54,6 +57,11 @@ ], "provisioners": [ + { + "type": "shell", + "scripts": "scripts/dev-tools.sh", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'" + }, { "type": "shell", "script": "scripts/fusion.sh", @@ -95,7 +103,7 @@ }, { "type": "shell", - "scripts": "scripts/docker-fig.sh", + "scripts": "scripts/docker-compose.sh", "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'" }, { @@ -108,6 +116,8 @@ "post-processors": [ { "type": "vagrant", + "output": "ubuntu-14.04-with-docker.{{.Provider}}.box", + "compression_level": 9, "keep_input_artifact": true } ]