Browse code

Add AWS support for running Docker on AWS

Charles Hooper authored on 2013/03/15 13:22:07
Showing 3 changed files
... ...
@@ -53,6 +53,37 @@ Under the hood, Docker is built on the following components:
53 53
 Install instructions
54 54
 ==================
55 55
 
56
+Installing with Vagrant
57
+-----------------------
58
+
59
+Currently, Docker can be installed with Vagrant both on your localhost
60
+with VirtualBox as well as on Amazon EC2. Vagrant 1.1 is required for
61
+EC2, but deploying is as simple as:
62
+
63
+```bash
64
+		$ export AWS_ACCESS_KEY_ID=xxx \
65
+			AWS_SECRET_ACCESS_KEY=xxx \
66
+			AWS_KEYPAIR_NAME=xxx \
67
+			AWS_SSH_PRIVKEY=xxx
68
+		$ vagrant plugin install vagrant-aws
69
+		$ vagrant up --provider=aws
70
+```
71
+
72
+The environment variables are:
73
+
74
+* `AWS_ACCESS_KEY_ID` - The API key used to make requests to AWS
75
+* `AWS_SECRET_ACCESS_KEY` - The secret key to make AWS API requests
76
+* `AWS_KEYPAIR_NAME` - The name of the keypair used for this EC2 instance
77
+* `AWS_SSH_PRIVKEY` - The path to the private key for the named keypair
78
+
79
+For VirtualBox, you can simply ignore setting any of the environment
80
+variables and omit the ``provider`` flag. VirtualBox is still supported with
81
+VirtualBox <= 1.1:
82
+
83
+```bash
84
+		$ vagrant up --provider=aws
85
+```
86
+
56 87
 Installing on Ubuntu 12.04 and 12.10
57 88
 ------------------------------------
58 89
 
... ...
@@ -1,7 +1,7 @@
1 1
 # -*- mode: ruby -*-
2 2
 # vi: set ft=ruby :
3 3
 
4
-Vagrant::Config.run do |config|
4
+Vagrant.configure("1") do |config|
5 5
   # All Vagrant configuration is done here. The most common configuration
6 6
   # options are documented and commented below. For a complete reference,
7 7
   # please see the online documentation at vagrantup.com.
... ...
@@ -98,3 +98,22 @@ Vagrant::Config.run do |config|
98 98
   #
99 99
   #   chef.validation_client_name = "ORGNAME-validator"
100 100
 end
101
+
102
+Vagrant.configure("2") do |config|
103
+  config.vm.provider :aws do |aws|
104
+		config.vm.box = "dummy"
105
+		config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
106
+    aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
107
+		aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
108
+		aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
109
+		aws.ssh_private_key_path = ENV["AWS_SSH_PRIVKEY"]
110
+		aws.region = "us-east-1"
111
+    aws.ami = "ami-1c1e8075"
112
+    aws.ssh_username = "vagrant"
113
+		aws.instance_type = "t1.micro"
114
+  end
115
+  config.vm.provider :virtualbox do |vb|
116
+		config.vm.box = "quantal64_3.5.0-25"
117
+		config.vm.box_url = "http://get.docker.io/vbox/ubuntu/12.10/quantal64_3.5.0-25.box"
118
+	end
119
+end
... ...
@@ -1,7 +1,34 @@
1
+class virtualbox {
2
+	Package { ensure => "installed" }
3
+
4
+	# remove some files from the base vagrant image because they're old
5
+	file { "/home/vagrant/docker-master":
6
+		ensure => absent,
7
+		recurse => true,
8
+		force => true,
9
+		purge => true,
10
+	}
11
+	file { "/usr/local/bin/dockerd":
12
+		ensure => absent,
13
+	}
14
+
15
+	# Set up VirtualBox guest utils
16
+	package { "virtualbox-guest-utils": }
17
+    exec { "vbox-add" :
18
+        command => "/etc/init.d/vboxadd setup",
19
+        require => [
20
+			Package["virtualbox-guest-utils"],
21
+			Package["linux-headers-3.5.0-25-generic"], ],
22
+    }
23
+}
24
+
25
+class ec2 {
26
+}
27
+
1 28
 class docker {
2 29
 
3 30
     # update this with latest docker binary distro
4
-    $docker_url = "http://docker.io.s3.amazonaws.com/builds/$kernel/$hardwaremodel/docker-master.tgz"
31
+    $docker_url = "http://get.docker.io/builds/$kernel/$hardwaremodel/docker-master.tgz"
5 32
     # update this with latest go binary distry
6 33
     $go_url = "http://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz"
7 34
 
... ...
@@ -11,18 +38,32 @@ class docker {
11 11
                "pkg-config", "libsqlite3-dev",
12 12
                "linux-image-3.5.0-25-generic",
13 13
                "linux-image-extra-3.5.0-25-generic",
14
-               "virtualbox-guest-utils",
15 14
                "linux-headers-3.5.0-25-generic"]: }
16 15
 
17 16
     notify { "docker_url = $docker_url": withpath => true }
18 17
 
19
-    exec { "debootstrap" :
20
-        require => Package["debootstrap"],
21
-        command => "/usr/sbin/debootstrap --arch=amd64 quantal /var/lib/docker/images/docker-ut",
22
-        creates => "/var/lib/docker/images/docker-ut",
23
-        timeout => 0
18
+	$ec2_version = file("/etc/ec2_version", "/dev/null")
19
+	if ($ec2_version) {
20
+		include ec2
21
+	} else {
22
+		# virtualbox is the vagrant default, so it should be safe to assume
23
+		include virtualbox
24
+	}
25
+
26
+    user { "vagrant":
27
+        ensure => present,
28
+        comment => "Vagrant User",
29
+        shell => "/bin/bash",
30
+        home => "/home/vagrant",
24 31
     }
25 32
 
33
+	file { "/usr/local/bin":
34
+		ensure => directory,
35
+		owner => root,
36
+		group => root,
37
+		mode => 755,
38
+	}
39
+
26 40
     exec { "fetch-go":
27 41
         require => Package["wget"],
28 42
         command => "/usr/bin/wget -O - $go_url | /bin/tar xz -C /usr/local",
... ...
@@ -30,9 +71,8 @@ class docker {
30 30
     }
31 31
 
32 32
     exec { "fetch-docker" :
33
+        command => "/usr/bin/wget -O - $docker_url | /bin/tar xz -C /tmp",
33 34
         require => Package["wget"],
34
-        command => "/usr/bin/wget -O - $docker_url | /bin/tar xz -C /home/vagrant",
35
-        creates => "/home/vagrant/docker-master"
36 35
     }
37 36
 
38 37
     file { "/etc/init/dockerd.conf":
... ...
@@ -40,25 +80,25 @@ class docker {
40 40
         owner => "root",
41 41
         group => "root",
42 42
         content => template("docker/dockerd.conf"),
43
-        require => [Exec["fetch-docker"], Exec["debootstrap"]]
43
+        require => Exec["fetch-docker"],
44
+    }
45
+
46
+    file { "/home/vagrant":
47
+        mode => 644,
48
+        require => User["vagrant"],
44 49
     }
45 50
 
46 51
     file { "/home/vagrant/.profile":
47 52
         mode => 644,
48 53
         owner => "vagrant",
49
-        group => "vagrant",
54
+        group => "ubuntu",
50 55
         content => template("docker/profile"),
56
+        require => File["/home/vagrant"],
51 57
     }
52 58
 
53 59
     exec { "copy-docker-bin" :
54
-        require => Exec["fetch-docker"],
55
-        command => "/bin/cp /home/vagrant/docker-master/docker /usr/local/bin",
56
-        creates => "/usr/local/bin/docker"
57
-    }
58
-
59
-    exec { "vbox-add" :
60
-        require => Package["linux-headers-3.5.0-25-generic"],
61
-        command => "/etc/init.d/vboxadd setup",
60
+        command => "/usr/bin/sudo /bin/cp -f /tmp/docker-master/docker /usr/local/bin/",
61
+        require => [ Exec["fetch-docker"], File["/usr/local/bin"] ],
62 62
     }
63 63
 
64 64
     service { "dockerd" :
... ...
@@ -69,6 +109,4 @@ class docker {
69 69
         name => "dockerd",
70 70
         provider => "base"
71 71
     }
72
-
73
-
74 72
 }