Browse code

vagrant: Simplify provisioning to build from repo

This sets up an idiomatic Go workspace in /opt/go with the source
shared from the host directory in
/opt/go/src/github.com/dotcloud/docker and docker installed into
/opt/go

Jonathan Rudenberg authored on 2013/03/28 08:19:30
Showing 5 changed files
... ...
@@ -1,4 +1,4 @@
1
-.vagrant
1
+.vagrant*
2 2
 bin
3 3
 docker/docker
4 4
 .*.swp
... ...
@@ -2,115 +2,30 @@
2 2
 # vi: set ft=ruby :
3 3
 
4 4
 def v10(config)
5
-  # All Vagrant configuration is done here. The most common configuration
6
-  # options are documented and commented below. For a complete reference,
7
-  # please see the online documentation at vagrantup.com.
8
-
9
-  # Every Vagrant virtual environment requires a box to build off of.
10 5
   config.vm.box = "quantal64_3.5.0-25"
11
-
12
-  # The url from where the 'config.vm.box' box will be fetched if it
13
-  # doesn't already exist on the user's system.
14 6
   config.vm.box_url = "http://get.docker.io/vbox/ubuntu/12.10/quantal64_3.5.0-25.box"
15 7
 
16
-  # Boot with a GUI so you can see the screen. (Default is headless)
17
-  # config.vm.boot_mode = :gui
18
-
19
-  # Assign this VM to a host-only network IP, allowing you to access it
20
-  # via the IP. Host-only networks can talk to the host machine as well as
21
-  # any other machines on the same network, but cannot be accessed (through this
22
-  # network interface) by any external networks.
23
-  config.vm.network :hostonly, "192.168.33.10"
24
-
25
-  # Assign this VM to a bridged network, allowing you to connect directly to a
26
-  # network using the host's network device. This makes the VM appear as another
27
-  # physical device on your network.
28
-  #config.vm.network :bridged
29
-
30
-  # Forward a port from the guest to the host, which allows for outside
31
-  # computers to access the VM, whereas host only networking does not.
32
-  # config.vm.forward_port 80, 8080
8
+  config.vm.share_folder "v-data", "/opt/go/src/github.com/dotcloud/docker", File.dirname(__FILE__)
33 9
 
34 10
   # Ensure puppet is installed on the instance
35 11
   config.vm.provision :shell, :inline => "apt-get -qq update; apt-get install -y puppet"
36 12
 
37
-  # Share an additional folder to the guest VM. The first argument is
38
-  # an identifier, the second is the path on the guest to mount the
39
-  # folder, and the third is the path on the host to the actual folder.
40
-  config.vm.share_folder "v-data", "~/docker", File.dirname(__FILE__)
41
-
42
-  # Enable provisioning with Puppet stand alone.  Puppet manifests
43
-  # are contained in a directory path relative to this Vagrantfile.
44
-  # You will need to create the manifests directory and a manifest in
45
-  # the file quantal64.pp in the manifests_path directory.
46
-  #
47
-  # An example Puppet manifest to provision the message of the day:
48
-  #
49
-  # # group { "puppet":
50
-  # #   ensure => "present",
51
-  # # }
52
-  # #
53
-  # # File { owner => 0, group => 0, mode => 0644 }
54
-  # #
55
-  # # file { '/etc/motd':
56
-  # #   content => "Welcome to your Vagrant-built virtual machine!
57
-  # #               Managed by Puppet.\n"
58
-  # # }
59
-  #
60 13
   config.vm.provision :puppet do |puppet|
61 14
     puppet.manifests_path = "puppet/manifests"
62 15
     puppet.manifest_file  = "quantal64.pp"
63 16
     puppet.module_path = "puppet/modules"
64 17
   end
65
-
66
-  # Enable provisioning with chef solo, specifying a cookbooks path, roles
67
-  # path, and data_bags path (all relative to this Vagrantfile), and adding 
68
-  # some recipes and/or roles.
69
-  #
70
-  # config.vm.provision :chef_solo do |chef|
71
-  #   chef.cookbooks_path = "../my-recipes/cookbooks"
72
-  #   chef.roles_path = "../my-recipes/roles"
73
-  #   chef.data_bags_path = "../my-recipes/data_bags"
74
-  #   chef.add_recipe "mysql"
75
-  #   chef.add_role "web"
76
-  #
77
-  #   # You may also specify custom JSON attributes:
78
-  #   chef.json = { :mysql_password => "foo" }
79
-  # end
80
-
81
-  # Enable provisioning with chef server, specifying the chef server URL,
82
-  # and the path to the validation key (relative to this Vagrantfile).
83
-  #
84
-  # The Opscode Platform uses HTTPS. Substitute your organization for
85
-  # ORGNAME in the URL and validation key.
86
-  #
87
-  # If you have your own Chef Server, use the appropriate URL, which may be
88
-  # HTTP instead of HTTPS depending on your configuration. Also change the
89
-  # validation key to validation.pem.
90
-  #
91
-  # config.vm.provision :chef_client do |chef|
92
-  #   chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
93
-  #   chef.validation_key_path = "ORGNAME-validator.pem"
94
-  # end
95
-  #
96
-  # If you're using the Opscode platform, your validator client is
97
-  # ORGNAME-validator, replacing ORGNAME with your organization name.
98
-  #
99
-  # IF you have your own Chef Server, the default validation client name is
100
-  # chef-validator, unless you changed the configuration.
101
-  #
102
-  #   chef.validation_client_name = "ORGNAME-validator"
103 18
 end
104 19
 
105
-"#{Vagrant::VERSION}" < "1.1.0" and Vagrant::Config.run do |config|
20
+Vagrant::VERSION < "1.1.0" and Vagrant::Config.run do |config|
106 21
   v10(config)
107 22
 end
108 23
 
109
-"#{Vagrant::VERSION}" >= "1.1.0" and Vagrant.configure("1") do |config|
24
+Vagrant::VERSION >= "1.1.0" and Vagrant.configure("1") do |config|
110 25
   v10(config)
111 26
 end
112 27
 
113
-"#{Vagrant::VERSION}" >= "1.1.0" and Vagrant.configure("2") do |config|
28
+Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
114 29
   config.vm.provider :aws do |aws|
115 30
     config.vm.box = "dummy"
116 31
     config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
... ...
@@ -130,10 +45,10 @@ end
130 130
     config.ssh.private_key_path = ENV["RS_PRIVATE_KEY"]
131 131
     rs.username = ENV["RS_USERNAME"]
132 132
     rs.api_key  = ENV["RS_API_KEY"]
133
-    rs.public_key_path = ENV["RS_PUBLIC_KEY"] 
133
+    rs.public_key_path = ENV["RS_PUBLIC_KEY"]
134 134
     rs.flavor   = /512MB/
135 135
     rs.image    = /Ubuntu/
136
-  end   
136
+  end
137 137
 
138 138
   config.vm.provider :virtualbox do |vb|
139 139
     config.vm.box = "quantal64_3.5.0-25"
... ...
@@ -1,76 +1,29 @@
1 1
 class virtualbox {
2
-	Package { ensure => "installed" }
3
-
4
-	user { "vagrant":
5
-		name => "vagrant",
6
-		ensure => present,
7
-		comment => "Vagrant User",
8
-		shell => "/bin/bash",
9
-		home => "/home/vagrant",
10
-	}
11
-
12
-	file { "/home/vagrant":
13
-		mode => 644,
14
-		require => User["vagrant"],
15
-	}
2
+    Package { ensure => "installed" }
16 3
 
17
-	# remove some files from the base vagrant image because they're old
18
-	file { "/home/vagrant/docker-master":
19
-		ensure => absent,
20
-		recurse => true,
21
-		force => true,
22
-		purge => true,
23
-		require => File["/home/vagrant"],
24
-	}
25
-	file { "/usr/local/bin/dockerd":
26
-		ensure => absent,
27
-	}
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
+    }
28 14
 
29
-	# Set up VirtualBox guest utils
30
-	package { "virtualbox-guest-utils": }
15
+    # Set up VirtualBox guest utils
16
+    package { "virtualbox-guest-utils": }
31 17
     exec { "vbox-add" :
32 18
         command => "/etc/init.d/vboxadd setup",
33 19
         require => [
34
-			Package["virtualbox-guest-utils"],
35
-			Package["linux-headers-3.5.0-25-generic"], ],
20
+            Package["virtualbox-guest-utils"],
21
+            Package["linux-headers-3.5.0-25-generic"], ],
36 22
     }
37 23
 }
38 24
 
39
-class ec2 {
40
-	user { "vagrant":
41
-		name => "ubuntu",
42
-		ensure => present,
43
-		comment => "Vagrant User",
44
-		shell => "/bin/bash",
45
-		home => "/home/ubuntu",
46
-	}
47
-	file { "/home/vagrant":
48
-		ensure => link,
49
-		target => "/home/ubuntu",
50
-		require => User["vagrant"],
51
-	}
52
-}
53
-
54
-class rax {
55
-	user { "vagrant":
56
-		name => "ubuntu",
57
-		ensure => present,
58
-		comment => "Vagrant User",
59
-		shell => "/bin/bash",
60
-		home => "/home/ubuntu",
61
-	}
62
-	file { "/home/vagrant":
63
-		ensure => link,
64
-		target => "/home/ubuntu",
65
-		require => User["vagrant"],
66
-	}
67
-}
68
-
69 25
 class docker {
70
-
71
-    # update this with latest docker binary distro
72
-    $docker_url = "http://get.docker.io/builds/$kernel/$hardwaremodel/docker-master.tgz"
73
-    # update this with latest go binary distry
26
+    # update this with latest go binary dist
74 27
     $go_url = "http://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz"
75 28
 
76 29
     Package { ensure => "installed" }
... ...
@@ -81,67 +34,63 @@ class docker {
81 81
                "linux-image-extra-3.5.0-25-generic",
82 82
                "linux-headers-3.5.0-25-generic"]: }
83 83
 
84
-    notify { "docker_url = $docker_url": withpath => true }
85
-
86 84
     $ec2_version = file("/etc/ec2_version", "/dev/null")
87 85
     $rax_version = inline_template("<%= %x{/usr/bin/xenstore-read vm-data/provider_data/provider} %>")
88 86
 
89 87
     if ($ec2_version) {
90
-		$vagrant_user = "ubuntu"
91
-		include ec2
88
+        $vagrant_user = "ubuntu"
89
+        $vagrant_home = "/home/ubuntu"
92 90
     } elsif ($rax_version) {
93
-		$vagrant_user = "vagrant"
94
-        include rax
91
+        $vagrant_user = "root"
92
+        $vagrant_home = "/root"
95 93
     } else {
96
-    # virtualbox is the vagrant default, so it should be safe to assume
97
-		$vagrant_user = "vagrant"
94
+        # virtualbox is the vagrant default, so it should be safe to assume
95
+        $vagrant_user = "vagrant"
96
+        $vagrant_home = "/home/vagrant"
98 97
         include virtualbox
99 98
     }
100 99
 
101
-	file { "/usr/local/bin":
102
-		ensure => directory,
103
-		owner => root,
104
-		group => root,
105
-		mode => 755,
106
-	}
107
-
108 100
     exec { "fetch-go":
109 101
         require => Package["wget"],
110 102
         command => "/usr/bin/wget -O - $go_url | /bin/tar xz -C /usr/local",
111 103
         creates => "/usr/local/go/bin/go",
112 104
     }
113 105
 
114
-    exec { "fetch-docker" :
115
-        command => "/usr/bin/wget -O - $docker_url | /bin/tar xz -C /tmp",
116
-        require => Package["wget"],
117
-    }
118
-
119 106
     file { "/etc/init/dockerd.conf":
120 107
         mode => 600,
121 108
         owner => "root",
122 109
         group => "root",
123 110
         content => template("docker/dockerd.conf"),
124
-        require => Exec["copy-docker-bin"],
125 111
     }
126 112
 
127
-    file { "/home/vagrant/.profile":
113
+    file { "/opt/go":
114
+        owner => $vagrant_user,
115
+        group => $vagrant_user,
116
+        recurse => true,
117
+    }
118
+
119
+    file { "${vagrant_home}/.profile":
128 120
         mode => 644,
129 121
         owner => $vagrant_user,
130
-        group => "ubuntu",
122
+        group => $vagrant_user,
131 123
         content => template("docker/profile"),
132
-        require => File["/home/vagrant"],
133 124
     }
134 125
 
135
-    exec { "copy-docker-bin" :
136
-        command => "/usr/bin/sudo /bin/cp -f /tmp/docker-master/docker /usr/local/bin/",
137
-        require => [ Exec["fetch-docker"], File["/usr/local/bin"] ],
126
+     exec { "build-docker" :
127
+        cwd  => "/opt/go/src/github.com/dotcloud/docker",
128
+        user => $vagrant_user,
129
+        environment => "GOPATH=/opt/go",
130
+        command => "/usr/local/go/bin/go get -v ./... && /usr/local/go/bin/go install ./docker",
131
+        creates => "/opt/go/bin/docker",
132
+        logoutput => "on_failure",
133
+        require => [ Exec["fetch-go"], File["/opt/go"] ],
138 134
     }
139 135
 
140 136
     service { "dockerd" :
141 137
         ensure => "running",
142 138
         start => "/sbin/initctl start dockerd",
143 139
         stop => "/sbin/initctl stop dockerd",
144
-        require => File["/etc/init/dockerd.conf"],
140
+        require => [ Exec["build-docker"], File["/etc/init/dockerd.conf"] ],
145 141
         name => "dockerd",
146 142
         provider => "base"
147 143
     }
... ...
@@ -8,5 +8,5 @@ respawn
8 8
 
9 9
 script
10 10
     test -f /etc/default/locale && . /etc/default/locale || true
11
-    LANG=$LANG LC_ALL=$LANG /usr/local/bin/docker -d >> /var/log/dockerd 2>&1
11
+    LANG=$LANG LC_ALL=$LANG /opt/go/bin/docker -d >> /var/log/dockerd 2>&1
12 12
 end script
... ...
@@ -21,7 +21,10 @@ if [ -d "$HOME/bin" ] ; then
21 21
     PATH="$HOME/bin:$PATH"
22 22
 fi
23 23
 
24
-# set ~/docker as the go path
25
-export GOPATH=~/docker
26
-# add go to the PATH
27
-export PATH=$PATH:/usr/local/go/bin
28 24
\ No newline at end of file
25
+export GOPATH=/opt/go
26
+export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
27
+
28
+docker=/opt/go/src/github.com/dotcloud/docker
29
+if [ -d $docker ]; then
30
+  cd $docker
31
+fi