vagrant-lxc 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/BOXES.md +55 -0
  3. data/CHANGELOG.md +14 -0
  4. data/CONTRIBUTING.md +20 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +4 -3
  7. data/README.md +16 -19
  8. data/boxes/build-debian-box.sh +167 -0
  9. data/boxes/build-ubuntu-box.sh +151 -0
  10. data/boxes/common/install-babushka +4 -3
  11. data/boxes/common/install-chef +3 -2
  12. data/boxes/common/install-puppet +3 -2
  13. data/boxes/common/install-salt +3 -2
  14. data/boxes/common/lxc-template +10 -13
  15. data/boxes/common/metadata.json +2 -1
  16. data/development/Vagrantfile +4 -4
  17. data/development/site.pp +31 -6
  18. data/lib/vagrant-lxc/action.rb +44 -40
  19. data/lib/vagrant-lxc/action/clear_forwarded_ports.rb +4 -0
  20. data/lib/vagrant-lxc/action/fetch_ip_from_dnsmasq_leases.rb +1 -1
  21. data/lib/vagrant-lxc/action/fetch_ip_with_lxc_attach.rb +4 -7
  22. data/lib/vagrant-lxc/action/message.rb +1 -0
  23. data/lib/vagrant-lxc/action/setup_package_files.rb +1 -0
  24. data/lib/vagrant-lxc/action/wait_for_communicator.rb +9 -14
  25. data/lib/vagrant-lxc/driver.rb +10 -7
  26. data/lib/vagrant-lxc/driver/cli.rb +7 -1
  27. data/lib/vagrant-lxc/errors.rb +5 -0
  28. data/lib/vagrant-lxc/version.rb +1 -1
  29. data/locales/en.yml +8 -2
  30. data/spec/Vagrantfile +7 -2
  31. data/spec/unit/driver/cli_spec.rb +8 -0
  32. metadata +8 -18
  33. data/boxes/debian/download +0 -156
  34. data/boxes/debian/finalize +0 -195
  35. data/boxes/debian/lxc-template +0 -367
  36. data/boxes/debian/metadata.json.template +0 -9
  37. data/boxes/ubuntu/download +0 -113
  38. data/boxes/ubuntu/finalize +0 -374
  39. data/boxes/ubuntu/lxc-template +0 -559
  40. data/boxes/ubuntu/metadata.json.template +0 -9
  41. data/development/shell-provisioning/upgrade-kernel +0 -14
  42. data/example/Vagrantfile +0 -46
  43. data/example/cookbooks/hello-world/recipes/default.rb +0 -4
  44. data/example/puppet/manifests/site.pp +0 -5
  45. data/example/puppet/modules/hello_world/manifests/init.pp +0 -3
  46. data/tasks/boxes.rake +0 -115
  47. data/tasks/boxes.v2.rake +0 -188
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fd5ca05e6456d793879dd160fe0746fba08541a
4
- data.tar.gz: 25437c338c3a8a41122e8ff35bdba2bdf9ca5dac
3
+ metadata.gz: d037f1ba303000765f7744d6400f4d6191e24689
4
+ data.tar.gz: ef8dbd484d7768f7b1cdd6efc9d9fed64504b1b0
5
5
  SHA512:
6
- metadata.gz: 16ea43d6b1f598fc62ae3930a2f81ca2f917689144cc313973ae171c695e65daa6aba15e15980fae891c1c7b0867ce8878a84bda4b3c0503a498bbbcd4060980
7
- data.tar.gz: 5ab9575aefa1ddefdcb988232d988c095238a613799c5f3353d2721c5bf53fac0219f413cd96804166f34d9462a6931889e7dfcb060d74e8f2f763e99357d7b2
6
+ metadata.gz: fb469f28e25a5521c907f316df78e4274aaa5c198a39ee89bf2a0500abc7193101b2283a54ea370203f815e92ab98fdf015b0098cd276b0b0d8d72d4c82d2b02
7
+ data.tar.gz: 6c8fc71c88a63a3cd790d7a7577ae8eedf35c920fd611fcf93fdd8951647992c43929f0edc4c45598f58a49efa99d4e165e627098eb8b29e91b93938633e0e2d
@@ -0,0 +1,55 @@
1
+ # vagrant-lxc base boxes
2
+
3
+ Although the official documentation says it is only supported for VirtualBox
4
+ environments, you can use the [`vagrant package`](http://docs.vagrantup.com/v2/cli/package.html)
5
+ command to export a `.box` file from an existing vagrant-lxc container.
6
+
7
+ There is also a set of [bash scripts](https://github.com/fgrehm/vagrant-lxc/tree/master/boxes)
8
+ that you can use to build base boxes as needed. By default it won't include any
9
+ provisioning tool and you can pick the ones you want by providing some environment
10
+ variables.
11
+
12
+ For example:
13
+
14
+ ```
15
+ git clone https://github.com/fgrehm/vagrant-lxc.git
16
+ cd vagrant-lxc/boxes
17
+ PUPPET=1 CHEF=1 sudo -E ./build-ubuntu-box.sh precise amd64
18
+ ```
19
+
20
+ Will build a Ubuntu Precise x86_64 box with latest Puppet and Chef pre-installed, please refer to the scripts for more information.
21
+
22
+ ## "Anatomy" of a box
23
+
24
+ If you need to go deeper and build your scripts from scratch or if you are interested
25
+ on knowing what makes a base box for vagrant-lxc, here's what's needed:
26
+
27
+ ### Expected `.box` contents
28
+
29
+ | FILE | DESCRIPTION |
30
+ | --- | --- |
31
+ | `lxc-template` | Script responsible for creating and setting up the container (used with `lxc-create`), a ["generic script"]() is provided along with project's source. |
32
+ | `rootfs.tar.gz` | Compressed container rootfs tarball (need to remeber to pass in `--numeric-owner` when creating it) |
33
+ | `lxc.conf` | |
34
+ | `metadata.json` | |
35
+
36
+ ### metadata.json
37
+
38
+ ```json
39
+ {
40
+ "provider": "lxc",
41
+ "version": "3",
42
+ "built-on": "Sat Sep 21 21:10:00 UTC 2013",
43
+ "template-opts": {
44
+ "--arch": "amd64",
45
+ "--release": "quantal"
46
+ }
47
+ }
48
+ ```
49
+
50
+ | KEY | REQUIRED? | DESCRIPTION |
51
+ | --- | --- | --- |
52
+ | `provider` | Yes | Required by Vagrant |
53
+ | `version` | Yes | Tracks backward incompatibilities |
54
+ | `built-on` | No | Date / time when the box was packaged |
55
+ | `template-opts` | No | Extra options to be passed to the `lxc-template` script provided with the .box package |
@@ -1,3 +1,17 @@
1
+ ## [0.6.1](https://github.com/fgrehm/vagrant-lxc/compare/v0.6.0...v0.6.1) (Oct 03, 2013)
2
+
3
+ IMPROVEMENTS:
4
+
5
+ - Fall back to `dnsmasq` leases file if not able to fetch IP with `lxc-attach` [#118](https://github.com/fgrehm/vagrant-lxc/issues/118)
6
+ - Make sure lxc templates are executable prior to `lxc-create` [#128](https://github.com/fgrehm/vagrant-lxc/issues/128)
7
+ - New base boxes with support for lxc 1.0+
8
+
9
+ BUG FIXES:
10
+
11
+ - Fix various issues related to detecting whether the container is running
12
+ and is "SSHable" [#142](https://github.com/fgrehm/vagrant-lxc/issues/142)
13
+ - Nicely handle missing templates path [#139](https://github.com/fgrehm/vagrant-lxc/issues/139)
14
+
1
15
  ## [0.6.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.5.0...v0.6.0) (Sep 12, 2013)
2
16
 
3
17
  IMPROVEMENTS:
@@ -0,0 +1,20 @@
1
+ ### Please read before contributing
2
+
3
+ * Try not to post questions in the issues tracker. I will probably answer you
4
+ but I'll most likely close the issue right away and will continue the discussion
5
+ with the issue closed. If you have any questions about the plugin, make sure
6
+ you go through the [Wiki](https://github.com/fgrehm/vagrant-lxc/wiki) pages
7
+ first and if you still need answers please ask a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/vagrant-lxc)
8
+ using the `vagrant-lxc` tag on it so that I get notified :)
9
+
10
+ * Please do a small search on the issues tracker before submitting your issue to
11
+ check if it was already reported / fixed.
12
+
13
+ * When reporting a bug, please include **all** information that you can get
14
+ about your environment. Things like vagrant / vagrant-lxc / kernel / lxc /
15
+ distro versions, the list of plugins you have installed, a [gist](https://gist.github.com/)
16
+ with the output of running `VAGRANT_LOG=debug vagrant COMMAND`, the `Vagrantfile`
17
+ you are using and / or base box URL are really useful when tracking down what's
18
+ going on on your side of the globe and will get bonus points :)
19
+
20
+ Thanks!
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'vagrant', github: 'mitchellh/vagrant'
6
+ gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.3.3'
7
7
  gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
8
8
  gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
9
9
  gem 'vagrant-omnibus'
@@ -12,9 +12,10 @@ GIT
12
12
 
13
13
  GIT
14
14
  remote: git://github.com/mitchellh/vagrant.git
15
- revision: 7b440339f3d801e60e2451823dec04aae772d86a
15
+ revision: db8e7a9c79b23264da129f55cf8569167fc22415
16
+ tag: v1.3.3
16
17
  specs:
17
- vagrant (1.3.2.dev)
18
+ vagrant (1.3.3)
18
19
  childprocess (~> 0.3.7)
19
20
  erubis (~> 2.7.0)
20
21
  i18n (~> 0.6.0)
@@ -25,7 +26,7 @@ GIT
25
26
  PATH
26
27
  remote: .
27
28
  specs:
28
- vagrant-lxc (0.6.0)
29
+ vagrant-lxc (0.6.1)
29
30
 
30
31
  GEM
31
32
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,17 +7,13 @@
7
7
  This is a Vagrant plugin that allows it to control and provision Linux Containers
8
8
  as an alternative to the built in VirtualBox provider for Linux hosts.
9
9
 
10
- Check out this [blog post](http://fabiorehm.com/blog/2013/04/28/lxc-provider-for-vagrant)
11
- to see the plugin in action and find out more about it.
12
10
 
13
11
  ## Features / Limitations
14
12
 
15
13
  * Provides the same workflow as the Vagrant VirtualBox provider
16
14
  * Port forwarding via [`redir`](http://linux.die.net/man/1/redir)
17
- * Does not support private networks
18
-
19
- *Please refer to the [closed issues](https://github.com/fgrehm/vagrant-lxc/issues?labels=&milestone=&page=1&state=closed)
20
- and the [changelog](CHANGELOG.md) for most up to date information.*
15
+ * Does not support public / private networks
16
+ * Assumes you have a `lxcbr0` bridge configured on your host similar to [Ubuntu's built-in](https://help.ubuntu.com/lts/serverguide/lxc.html#lxcbr0)
21
17
 
22
18
 
23
19
  ## Requirements
@@ -33,13 +29,13 @@ and a `apt-get update && apt-get dist-upgrade` to upgrade the kernel. For Debian
33
29
  hosts you'll need to follow the instructions described on the [Wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Usage-on-debian-hosts).
34
30
 
35
31
  Some manual steps are required to set up a Linode machine prior to using this
36
- plugin, please check https://github.com/fgrehm/vagrant-lxc/wiki/Usage-on-Linode
32
+ plugin, please check [the wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Usage-on-Linode)
37
33
  for more information. Documentation on how to set things up for other distros
38
34
  [are welcome](https://github.com/fgrehm/vagrant-lxc/wiki) :)
39
35
 
40
- If you are on a Mac or Windows machine, you might want to have a look at this
41
- blog post for some ideas on how to set things up: http://the.taoofmac.com/space/HOWTO/Vagrant
42
- or use use the same [Ubuntu 12.10 VirtualBox machine I use for development](https://github.com/fgrehm/vagrant-lxc/wiki/Development#using-virtualbox-for-development).
36
+ If you are on a Mac or Windows machine, you might want to have a look at [this](http://the.taoofmac.com/space/HOWTO/Vagrant)
37
+ blog post for some ideas on how to set things up or check out [this other repo](https://github.com/fgrehm/vagrant-lxc-vbox-hosts)
38
+ for a set of Vagrant VirtualBox machines ready for vagrant-lxc usage.
43
39
 
44
40
 
45
41
  ## Installation
@@ -89,12 +85,11 @@ end
89
85
  ```
90
86
 
91
87
  vagrant-lxc will then write out `lxc.cgroup.memory.limit_in_bytes='1024M'` to the
92
- container config file (usually kept under `/var/lib/lxc/<container-name>/config`)
88
+ container config file (usually kept under `/var/lib/lxc/<container>/config`)
93
89
  prior to starting it.
94
90
 
95
91
  For other configuration options, please check the [lxc.conf manpages](http://manpages.ubuntu.com/manpages/quantal/man5/lxc.conf.5.html).
96
92
 
97
-
98
93
  ### Avoiding `sudo` passwords
99
94
 
100
95
  This plugin requires **a lot** of `sudo`ing since [user namespaces](https://wiki.ubuntu.com/UserNamespace)
@@ -106,13 +101,13 @@ to find out how to work around that specially if you are running an OS with sudo
106
101
 
107
102
  Please check [the wiki](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes)
108
103
  for a list of [pre built](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#available-boxes)
109
- base boxes and information on [how to build your own](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#building-your-own).
104
+ base boxes and have a look at [`BOXES.md`](https://github.com/fgrehm/vagrant-lxc/tree/master/BOXES.md)
105
+ for more information on building your own.
110
106
 
111
107
 
112
108
  ## More information
113
109
 
114
- Please refer the [wiki](https://github.com/fgrehm/vagrant-lxc/wiki) for more
115
- information.
110
+ Please refer the [wiki](https://github.com/fgrehm/vagrant-lxc/wiki).
116
111
 
117
112
 
118
113
  ## Problems / ideas?
@@ -120,13 +115,15 @@ information.
120
115
  Please review the [Troubleshooting](https://github.com/fgrehm/vagrant-lxc/wiki/Troubleshooting)
121
116
  wiki page + [known bugs](https://github.com/fgrehm/vagrant-lxc/issues?labels=bug&page=1&state=open)
122
117
  list if you have a problem and feel free to use the [issue tracker](https://github.com/fgrehm/vagrant-lxc/issues)
123
- to ask questions, propose new functionality and / or report bugs.
118
+ propose new functionality and / or report bugs.
119
+
124
120
 
121
+ ## Donating
125
122
 
126
- ## Similar projects
123
+ Support this project and [others by fgrehm](https://github.com/fgrehm)
124
+ via [gittip](https://www.gittip.com/fgrehm/).
127
125
 
128
- * [vagabond](https://github.com/chrisroberts/vagabond) - "a tool integrated with Chef to build local nodes easily"
129
- * [vagueant](https://github.com/neerolyte/vagueant) - "vaguely like Vagrant for linux containers (lxc)"
126
+ [![Support via Gittip](https://rawgithub.com/twolfson/gittip-badge/0.1.0/dist/gittip.png)](https://www.gittip.com/fgrehm/)
130
127
 
131
128
 
132
129
  ## Contributing
@@ -0,0 +1,167 @@
1
+ #!/bin/bash
2
+
3
+ # set -x
4
+ set -e
5
+
6
+ # Script used to build Debian base vagrant-lxc containers, currently limited to
7
+ # host's arch
8
+ #
9
+ # USAGE:
10
+ # $ cd boxes && sudo ./build-debian-box.sh DEBIAN_RELEASE
11
+ #
12
+ # To enable Chef or any other configuration management tool pass '1' to the
13
+ # corresponding env var:
14
+ # $ CHEF=1 sudo -E ./build-debian-box.sh DEBIAN_RELEASE
15
+ # $ PUPPET=1 sudo -E ./build-debian-box.sh DEBIAN_RELEASE
16
+ # $ SALT=1 sudo -E ./build-debian-box.sh DEBIAN_RELEASE
17
+ # $ BABUSHKA=1 sudo -E ./build-debian-box.sh DEBIAN_RELEASE
18
+
19
+ ##################################################################################
20
+ # 0 - Initial setup and sanity checks
21
+
22
+ TODAY=$(date -u +"%Y-%m-%d")
23
+ NOW=$(date -u)
24
+ RELEASE=${1:-"wheezy"}
25
+ ARCH=$(dpkg --print-architecture) # This is what the Debian template will use under the hood
26
+ PKG=vagrant-lxc-${RELEASE}-${ARCH}-${TODAY}.box
27
+ WORKING_DIR=/tmp/vagrant-lxc-${RELEASE}
28
+ VAGRANT_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
29
+ ROOTFS=/var/lib/lxc/${RELEASE}-base/rootfs
30
+
31
+ # Providing '1' will enable these tools
32
+ CHEF=${CHEF:-0}
33
+ PUPPET=${PUPPET:-0}
34
+ SALT=${SALT:-0}
35
+ BABUSHKA=${BABUSHKA:-0}
36
+
37
+ # Path to files bundled with the box
38
+ CWD=`readlink -f .`
39
+ LXC_TEMPLATE=${CWD}/common/lxc-template
40
+ LXC_CONF=${CWD}/common/lxc.conf
41
+ METATADA_JSON=${CWD}/common/metadata.json
42
+
43
+ # Set up a working dir
44
+ mkdir -p $WORKING_DIR
45
+
46
+ if [ -f "${WORKING_DIR}/${PKG}" ]; then
47
+ echo "Found a box on ${WORKING_DIR}/${PKG} already!"
48
+ exit 1
49
+ fi
50
+
51
+ ##################################################################################
52
+ # 1 - Create the base container
53
+
54
+ if $(lxc-ls | grep -q "${RELEASE}-base"); then
55
+ echo "Base container already exists, please remove it with \`lxc-destroy -n ${RELEASE}-base\`!"
56
+ exit 1
57
+ else
58
+ export SUITE=$RELEASE
59
+ lxc-create -n ${RELEASE}-base -t debian
60
+ fi
61
+
62
+
63
+ ######################################
64
+ # 2 - Fix some known issues
65
+
66
+ # Fixes some networking issues
67
+ # See https://github.com/fgrehm/vagrant-lxc/issues/91 for more info
68
+ sed -i -e "s/\(127.0.0.1\s\+localhost\)/\1\n127.0.1.1\t${RELEASE}-base\n/g" ${ROOTFS}/etc/hosts
69
+
70
+ # Ensures that `/tmp` does not get cleared on halt
71
+ # See https://github.com/fgrehm/vagrant-lxc/issues/68 for more info
72
+ chroot $ROOTFS /usr/sbin/update-rc.d -f checkroot-bootclean.sh remove
73
+ chroot $ROOTFS /usr/sbin/update-rc.d -f mountall-bootclean.sh remove
74
+ chroot $ROOTFS /usr/sbin/update-rc.d -f mountnfs-bootclean.sh remove
75
+
76
+ # Ensure locales are properly set, based on http://linux.livejournal.com/1880366.html
77
+ sed -i "s/^# en_US/en_US/" ${ROOTFS}/etc/locale.gen
78
+ chroot $ROOTFS /usr/sbin/locale-gen
79
+ chroot $ROOTFS update-locale LANG=en_US.UTF-8
80
+
81
+
82
+ ##################################################################################
83
+ # 3 - Prepare vagrant user
84
+ sudo chroot ${ROOTFS} useradd --create-home -s /bin/bash vagrant
85
+
86
+ echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
87
+
88
+
89
+ ##################################################################################
90
+ # 4 - Setup SSH access and passwordless sudo
91
+
92
+ # Configure SSH access
93
+ mkdir -p ${ROOTFS}/home/vagrant/.ssh
94
+ echo $VAGRANT_KEY > ${ROOTFS}/home/vagrant/.ssh/authorized_keys
95
+ chroot ${ROOTFS} chown -R vagrant: /home/vagrant/.ssh
96
+
97
+ chroot ${ROOTFS} apt-get install sudo -y --force-yes
98
+ chroot ${ROOTFS} adduser vagrant sudo
99
+
100
+ # Enable passwordless sudo for users under the "sudo" group
101
+ cp ${ROOTFS}/etc/sudoers{,.orig}
102
+ sed -i -e \
103
+ 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' \
104
+ ${ROOTFS}/etc/sudoers
105
+
106
+
107
+ ##################################################################################
108
+ # 5 - Add some goodies and update packages
109
+
110
+ PACKAGES=(vim curl wget man-db bash-completion ca-certificates)
111
+ chroot ${ROOTFS} apt-get install ${PACKAGES[*]} -y --force-yes
112
+ chroot ${ROOTFS} apt-get upgrade -y --force-yes
113
+
114
+
115
+ ##################################################################################
116
+ # 6 - Configuration management tools
117
+
118
+ if [ $CHEF = 1 ]; then
119
+ ./common/install-chef $ROOTFS
120
+ fi
121
+
122
+ if [ $PUPPET = 1 ]; then
123
+ ./common/install-puppet $ROOTFS
124
+ fi
125
+
126
+ if [ $SALT = 1 ]; then
127
+ ./common/install-salt $ROOTFS
128
+ fi
129
+
130
+ if [ $BABUSHKA = 1 ]; then
131
+ ./common/install-babushka $ROOTFS
132
+ fi
133
+
134
+
135
+ ##################################################################################
136
+ # 7 - Free up some disk space
137
+
138
+ rm -rf ${ROOTFS}/tmp/*
139
+ chroot ${ROOTFS} apt-get clean
140
+
141
+
142
+ ##################################################################################
143
+ # 8 - Build box package
144
+
145
+ # Compress container's rootfs
146
+ cd $(dirname $ROOTFS)
147
+ tar --numeric-owner -czf /tmp/vagrant-lxc-${RELEASE}/rootfs.tar.gz ./rootfs/*
148
+
149
+ # Prepare package contents
150
+ cd $WORKING_DIR
151
+ cp $LXC_TEMPLATE .
152
+ cp $LXC_CONF .
153
+ cp $METATADA_JSON .
154
+ chmod +x lxc-template
155
+ sed -i "s/<TODAY>/${NOW}/" metadata.json
156
+
157
+ # Vagrant box!
158
+ tar -czf $PKG ./*
159
+
160
+ chmod +rw ${WORKING_DIR}/${PKG}
161
+ mkdir -p ${CWD}/output
162
+ mv ${WORKING_DIR}/${PKG} ${CWD}/output
163
+
164
+ # Clean up after ourselves
165
+ rm -rf ${WORKING_DIR}
166
+
167
+ echo "The base box was built successfully to ${CWD}/output/${PKG}"
@@ -0,0 +1,151 @@
1
+ #!/bin/bash
2
+
3
+ # set -x
4
+ set -e
5
+
6
+ # Script used to build Ubuntu base vagrant-lxc containers
7
+ #
8
+ # USAGE:
9
+ # $ cd boxes && sudo ./build-ubuntu-box.sh UBUNTU_RELEASE BOX_ARCH
10
+ #
11
+ # To enable Chef or any other configuration management tool pass '1' to the
12
+ # corresponding env var:
13
+ # $ CHEF=1 sudo -E ./build-ubuntu-box.sh UBUNTU_RELEASE BOX_ARCH
14
+ # $ PUPPET=1 sudo -E ./build-ubuntu-box.sh UBUNTU_RELEASE BOX_ARCH
15
+ # $ SALT=1 sudo -E ./build-ubuntu-box.sh UBUNTU_RELEASE BOX_ARCH
16
+ # $ BABUSHKA=1 sudo -E ./build-ubuntu-box.sh UBUNTU_RELEASE BOX_ARCH
17
+
18
+ ##################################################################################
19
+ # 0 - Initial setup and sanity checks
20
+
21
+ TODAY=$(date -u +"%Y-%m-%d")
22
+ NOW=$(date -u)
23
+ RELEASE=${1:-"raring"}
24
+ ARCH=${2:-"amd64"}
25
+ PKG=vagrant-lxc-${RELEASE}-${ARCH}-${TODAY}.box
26
+ WORKING_DIR=/tmp/vagrant-lxc-${RELEASE}
27
+ VAGRANT_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
28
+ ROOTFS=/var/lib/lxc/${RELEASE}-base/rootfs
29
+
30
+ # Providing '1' will enable these tools
31
+ CHEF=${CHEF:-0}
32
+ PUPPET=${PUPPET:-0}
33
+ SALT=${SALT:-0}
34
+ BABUSHKA=${BABUSHKA:-0}
35
+
36
+ # Path to files bundled with the box
37
+ CWD=`readlink -f .`
38
+ LXC_TEMPLATE=${CWD}/common/lxc-template
39
+ LXC_CONF=${CWD}/common/lxc.conf
40
+ METATADA_JSON=${CWD}/common/metadata.json
41
+
42
+ # Set up a working dir
43
+ mkdir -p $WORKING_DIR
44
+
45
+ if [ -f "${WORKING_DIR}/${PKG}" ]; then
46
+ echo "Found a box on ${WORKING_DIR}/${PKG} already!"
47
+ exit 1
48
+ fi
49
+
50
+ ##################################################################################
51
+ # 1 - Create the base container
52
+
53
+ if $(lxc-ls | grep -q "${RELEASE}-base"); then
54
+ echo "Base container already exists, please remove it with \`lxc-destroy -n ${RELEASE}-base\`!"
55
+ exit 1
56
+ else
57
+ lxc-create -n ${RELEASE}-base -t ubuntu -- --release ${RELEASE} --arch ${ARCH}
58
+ fi
59
+
60
+ # Fixes some networking issues
61
+ # See https://github.com/fgrehm/vagrant-lxc/issues/91 for more info
62
+ echo 'ff02::3 ip6-allhosts' >> ${ROOTFS}/etc/hosts
63
+
64
+
65
+ ##################################################################################
66
+ # 2 - Prepare vagrant user
67
+
68
+ mv ${ROOTFS}/home/{ubuntu,vagrant}
69
+ chroot ${ROOTFS} usermod -l vagrant -d /home/vagrant ubuntu
70
+ chroot ${ROOTFS} groupmod -n vagrant ubuntu
71
+
72
+ echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
73
+
74
+
75
+ ##################################################################################
76
+ # 3 - Setup SSH access and passwordless sudo
77
+
78
+ # Configure SSH access
79
+ mkdir -p ${ROOTFS}/home/vagrant/.ssh
80
+ echo $VAGRANT_KEY > ${ROOTFS}/home/vagrant/.ssh/authorized_keys
81
+ chroot ${ROOTFS} chown -R vagrant: /home/vagrant/.ssh
82
+
83
+ # Enable passwordless sudo for users under the "sudo" group
84
+ cp ${ROOTFS}/etc/sudoers{,.orig}
85
+ sed -i -e \
86
+ 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' \
87
+ ${ROOTFS}/etc/sudoers
88
+
89
+
90
+ ##################################################################################
91
+ # 4 - Add some goodies and update packages
92
+
93
+ PACKAGES=(vim curl wget man-db bash-completion)
94
+ chroot ${ROOTFS} apt-get install ${PACKAGES[*]} -y --force-yes
95
+ chroot ${ROOTFS} apt-get upgrade -y --force-yes
96
+
97
+
98
+ ##################################################################################
99
+ # 5 - Configuration management tools
100
+
101
+ if [ $CHEF = 1 ]; then
102
+ ./common/install-chef $ROOTFS
103
+ fi
104
+
105
+ if [ $PUPPET = 1 ]; then
106
+ ./common/install-puppet $ROOTFS
107
+ fi
108
+
109
+ if [ $SALT = 1 ]; then
110
+ ./common/install-salt $ROOTFS
111
+ fi
112
+
113
+ if [ $BABUSHKA = 1 ]; then
114
+ ./common/install-babushka $ROOTFS
115
+ fi
116
+
117
+
118
+ ##################################################################################
119
+ # 6 - Free up some disk space
120
+
121
+ rm -rf ${ROOTFS}/tmp/*
122
+ chroot ${ROOTFS} apt-get clean
123
+
124
+
125
+ ##################################################################################
126
+ # 7 - Build box package
127
+
128
+ # Compress container's rootfs
129
+ cd $(dirname $ROOTFS)
130
+ tar --numeric-owner -czf /tmp/vagrant-lxc-${RELEASE}/rootfs.tar.gz ./rootfs/*
131
+
132
+ # Prepare package contents
133
+ cd $WORKING_DIR
134
+ cp $LXC_TEMPLATE .
135
+ cp $LXC_CONF .
136
+ cp $METATADA_JSON .
137
+ chmod +x lxc-template
138
+ sed -i "s/<TODAY>/${NOW}/" metadata.json
139
+
140
+ # Vagrant box!
141
+ tar -czf $PKG ./*
142
+
143
+ chmod +rw ${WORKING_DIR}/${PKG}
144
+ mkdir -p ${CWD}/output
145
+ mv ${WORKING_DIR}/${PKG} ${CWD}/output
146
+
147
+ # Clean up after ourselves
148
+ rm -rf ${WORKING_DIR}
149
+ lxc-destroy -n ${RELEASE}-base
150
+
151
+ echo "The base box was built successfully to ${CWD}/output/${PKG}"