Ver código fonte

Merge pull request #466 from dotcloud/441-vagrant-improve

* Packaging: simplify Vagrantfile
Solomon Hykes 12 anos atrás
pai
commit
03855b0027

+ 20 - 49
Vagrantfile

@@ -1,55 +1,27 @@
 # -*- mode: ruby -*-
 # vi: set ft=ruby :
 
-def v10(config)
-  config.vm.box = 'precise64'
-  config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
-
-  # Install ubuntu packaging dependencies and create ubuntu packages
-  config.vm.provision :shell, :inline => "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >>/etc/apt/sources.list"
-  config.vm.provision :shell, :inline => 'export DEBIAN_FRONTEND=noninteractive; apt-get -qq update; apt-get install -qq -y --force-yes lxc-docker'
-end
-
-Vagrant::VERSION < "1.1.0" and Vagrant::Config.run do |config|
-  v10(config)
-end
-
-Vagrant::VERSION >= "1.1.0" and Vagrant.configure("1") do |config|
-  v10(config)
-end
-
-Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
-  config.vm.provider :aws do |aws|
-    config.vm.box = "dummy"
-    config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
-    aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
-    aws.secret_access_key =     ENV["AWS_SECRET_ACCESS_KEY"]
-    aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
-    aws.ssh_private_key_path = ENV["AWS_SSH_PRIVKEY"]
-    aws.region = "us-east-1"
-    aws.ami = "ami-d0f89fb9"
-    aws.ssh_username = "ubuntu"
-    aws.instance_type = "t1.micro"
-  end
-
-  config.vm.provider :rackspace do |rs|
-    config.vm.box = "dummy"
-    config.vm.box_url = "https://github.com/mitchellh/vagrant-rackspace/raw/master/dummy.box"
-    config.ssh.private_key_path = ENV["RS_PRIVATE_KEY"]
-    rs.username = ENV["RS_USERNAME"]
-    rs.api_key  = ENV["RS_API_KEY"]
-    rs.public_key_path = ENV["RS_PUBLIC_KEY"]
-    rs.flavor   = /512MB/
-    rs.image    = /Ubuntu/
-  end
-
-  config.vm.provider :virtualbox do |vb|
-    config.vm.box = 'precise64'
-    config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
+BOX_NAME = "ubuntu"
+BOX_URI = "http://files.vagrantup.com/precise64.box"
+PPA_KEY = "E61D797F63561DC6"
+
+Vagrant::Config.run do |config|
+  # Setup virtual machine box. This VM configuration code is always executed.
+  config.vm.box = BOX_NAME
+  config.vm.box_url = BOX_URI
+  # Add docker PPA key to the local repository and install docker
+  pkg_cmd = "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys #{PPA_KEY}; "
+  pkg_cmd << "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >>/etc/apt/sources.list; "
+  pkg_cmd << "apt-get update -qq; apt-get install -q -y lxc-docker"
+  if ARGV.include?("--provider=aws".downcase)
+    # Add AUFS dependency to amazon's VM
+    pkg_cmd << "; apt-get install linux-image-extra-3.2.0-40-virtual"
   end
+  config.vm.provision :shell, :inline => pkg_cmd
 end
 
-Vagrant::VERSION >= "1.2.0" and Vagrant.configure("2") do |config|
+# Providers were added on Vagrant >= 1.1.0
+Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
   config.vm.provider :aws do |aws, override|
     config.vm.box = "dummy"
     config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
@@ -75,8 +47,7 @@ Vagrant::VERSION >= "1.2.0" and Vagrant.configure("2") do |config|
   end
 
   config.vm.provider :virtualbox do |vb|
-    config.vm.box = 'precise64'
-    config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
+    config.vm.box = BOX_NAME
+    config.vm.box_url = BOX_URI
   end
-
 end

+ 0 - 17
puppet/manifests/quantal64.pp

@@ -1,17 +0,0 @@
-node default {
-    exec {
-        "apt_update" : 
-            command => "/usr/bin/apt-get update"
-    }
-
-    Package {
-        require => Exec['apt_update']
-    }
-
-    group { "puppet":
-        ensure => "present"
-    }
-
-    include "docker"
-
-}

+ 0 - 99
puppet/modules/docker/manifests/init.pp

@@ -1,99 +0,0 @@
-class virtualbox {
-    Package { ensure => "installed" }
-
-    # remove some files from the base vagrant image because they're old
-    file { "/home/vagrant/docker-master":
-        ensure => absent,
-        recurse => true,
-        force => true,
-        purge => true,
-    }
-    file { "/usr/local/bin/dockerd":
-        ensure => absent,
-    }
-    file { "/usr/local/bin/docker":
-        ensure => absent,
-    }
-
-    # Set up VirtualBox guest utils
-    package { "virtualbox-guest-utils": }
-    exec { "vbox-add" :
-        command => "/etc/init.d/vboxadd setup",
-        require => [
-            Package["virtualbox-guest-utils"],
-            Package["linux-headers-3.5.0-25-generic"], ],
-    }
-}
-
-class docker {
-    # update this with latest go binary dist
-    $go_url = "http://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz"
-
-    Package { ensure => "installed" }
-
-    package { ["lxc", "debootstrap", "wget", "bsdtar", "git",
-               "linux-image-3.5.0-25-generic",
-               "linux-image-extra-3.5.0-25-generic",
-               "linux-headers-3.5.0-25-generic"]: }
-
-    $ec2_version = file("/etc/ec2_version", "/dev/null")
-    $rax_version = inline_template("<%= %x{/usr/bin/xenstore-read vm-data/provider_data/provider} %>")
-
-    if ($ec2_version) {
-        $vagrant_user = "ubuntu"
-        $vagrant_home = "/home/ubuntu"
-    } elsif ($rax_version) {
-        $vagrant_user = "root"
-        $vagrant_home = "/root"
-    } else {
-        # virtualbox is the vagrant default, so it should be safe to assume
-        $vagrant_user = "vagrant"
-        $vagrant_home = "/home/vagrant"
-        include virtualbox
-    }
-
-    exec { "fetch-go":
-        require => Package["wget"],
-        command => "/usr/bin/wget -O - $go_url | /bin/tar xz -C /usr/local",
-        creates => "/usr/local/go/bin/go",
-    }
-
-    file { "/etc/init/dockerd.conf":
-        mode => 600,
-        owner => "root",
-        group => "root",
-        content => template("docker/dockerd.conf"),
-    }
-
-    file { "/opt/go":
-        owner => $vagrant_user,
-        group => $vagrant_user,
-        recurse => true,
-    }
-
-    file { "${vagrant_home}/.profile":
-        mode => 644,
-        owner => $vagrant_user,
-        group => $vagrant_user,
-        content => template("docker/profile"),
-    }
-
-     exec { "build-docker" :
-        cwd  => "/opt/go/src/github.com/dotcloud/docker",
-        user => $vagrant_user,
-        environment => "GOPATH=/opt/go",
-        command => "/usr/local/go/bin/go get -v ./... && /usr/local/go/bin/go install ./docker",
-        creates => "/opt/go/bin/docker",
-        logoutput => "on_failure",
-        require => [ Exec["fetch-go"], File["/opt/go"] ],
-    }
-
-    service { "dockerd" :
-        ensure => "running",
-        start => "/sbin/initctl start dockerd",
-        stop => "/sbin/initctl stop dockerd",
-        require => [ Exec["build-docker"], File["/etc/init/dockerd.conf"] ],
-        name => "dockerd",
-        provider => "base"
-    }
-}

+ 0 - 12
puppet/modules/docker/templates/dockerd.conf

@@ -1,12 +0,0 @@
-description     "Run dockerd"
-
-stop on runlevel [!2345]
-start on runlevel [3]
-
-# if you want it to automatically restart if it crashes, leave the next line in
-respawn
-
-script
-    test -f /etc/default/locale && . /etc/default/locale || true
-    LANG=$LANG LC_ALL=$LANG /opt/go/bin/docker -d >> /var/log/dockerd 2>&1
-end script

+ 0 - 30
puppet/modules/docker/templates/profile

@@ -1,30 +0,0 @@
-# ~/.profile: executed by the command interpreter for login shells.
-# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
-# exists.
-# see /usr/share/doc/bash/examples/startup-files for examples.
-# the files are located in the bash-doc package.
-
-# the default umask is set in /etc/profile; for setting the umask
-# for ssh logins, install and configure the libpam-umask package.
-#umask 022
-
-# if running bash
-if [ -n "$BASH_VERSION" ]; then
-    # include .bashrc if it exists
-    if [ -f "$HOME/.bashrc" ]; then
-        . "$HOME/.bashrc"
-    fi
-fi
-
-# set PATH so it includes user's private bin if it exists
-if [ -d "$HOME/bin" ] ; then
-    PATH="$HOME/bin:$PATH"
-fi
-
-export GOPATH=/opt/go
-export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
-
-docker=/opt/go/src/github.com/dotcloud/docker
-if [ -d $docker ]; then
-  cd $docker
-fi