vagrant-lxc 0.8.0 → 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/BOXES.md +13 -21
  4. data/CHANGELOG.md +49 -0
  5. data/CONTRIBUTING.md +5 -2
  6. data/Gemfile +12 -13
  7. data/Gemfile.lock +66 -51
  8. data/README.md +39 -25
  9. data/development/Vagrantfile +0 -2
  10. data/lib/vagrant-backports/README.md +12 -0
  11. data/lib/vagrant-backports/action/handle_box.rb +1 -0
  12. data/lib/vagrant-backports/action/is_state.rb +34 -0
  13. data/lib/vagrant-backports/action/message.rb +20 -0
  14. data/lib/{vagrant-lxc → vagrant-backports}/action/wait_for_communicator.rb +6 -5
  15. data/lib/vagrant-backports/ui.rb +12 -0
  16. data/lib/vagrant-backports/utils.rb +27 -0
  17. data/lib/vagrant-lxc.rb +8 -0
  18. data/lib/vagrant-lxc/action.rb +81 -48
  19. data/lib/vagrant-lxc/action/boot.rb +2 -1
  20. data/lib/vagrant-lxc/action/fetch_ip_from_dnsmasq_leases.rb +1 -0
  21. data/lib/vagrant-lxc/action/handle_box_metadata.rb +36 -14
  22. data/lib/vagrant-lxc/action/message.rb +0 -23
  23. data/lib/vagrant-lxc/action/prepare_nfs_settings.rb +64 -0
  24. data/lib/vagrant-lxc/action/prepare_nfs_valid_ids.rb +19 -0
  25. data/lib/vagrant-lxc/action/setup_package_files.rb +6 -2
  26. data/lib/vagrant-lxc/{action → backports/action}/share_folders.rb +0 -0
  27. data/lib/vagrant-lxc/command/root.rb +58 -0
  28. data/lib/vagrant-lxc/command/sudoers.rb +87 -0
  29. data/lib/vagrant-lxc/driver.rb +21 -11
  30. data/lib/vagrant-lxc/plugin.rb +23 -5
  31. data/lib/vagrant-lxc/provider/cap/public_address.rb +17 -0
  32. data/lib/vagrant-lxc/synced_folder.rb +42 -0
  33. data/lib/vagrant-lxc/version.rb +1 -1
  34. data/locales/en.yml +6 -5
  35. data/scripts/lxc-template +165 -0
  36. data/spec/spec_helper.rb +9 -13
  37. data/spec/unit/action/clear_forwarded_ports_spec.rb +3 -3
  38. data/spec/unit/action/compress_rootfs_spec.rb +7 -5
  39. data/spec/unit/action/forward_ports_spec.rb +8 -8
  40. data/spec/unit/action/handle_box_metadata_spec.rb +71 -15
  41. data/spec/unit/action/setup_package_files_spec.rb +32 -8
  42. data/spec/unit/driver/cli_spec.rb +31 -30
  43. data/spec/unit/driver_spec.rb +35 -27
  44. data/spec/unit/support/unit_example_group.rb +6 -6
  45. data/spec/unit_helper.rb +4 -2
  46. data/tasks/spec.rake +18 -11
  47. data/vagrant-lxc.gemspec +7 -0
  48. data/vagrant-spec.config.rb +24 -0
  49. metadata +24 -36
  50. data/boxes/build-all.sh +0 -22
  51. data/boxes/build-debian-box.sh +0 -167
  52. data/boxes/build-openmandriva-box.sh +0 -159
  53. data/boxes/build-ubuntu-box.sh +0 -151
  54. data/boxes/common/cleanup +0 -7
  55. data/boxes/common/install-babushka +0 -16
  56. data/boxes/common/install-chef +0 -15
  57. data/boxes/common/install-puppet +0 -13
  58. data/boxes/common/install-salt +0 -12
  59. data/boxes/common/install-salt-debian +0 -28
  60. data/boxes/common/lxc-template +0 -226
  61. data/boxes/common/lxc-template-openmandriva +0 -225
  62. data/boxes/common/lxc.conf +0 -49
  63. data/boxes/common/metadata.json +0 -5
  64. data/lib/vagrant-lxc/action/check_created.rb +0 -21
  65. data/lib/vagrant-lxc/action/check_running.rb +0 -21
  66. data/lib/vagrant-lxc/action/created.rb +0 -20
  67. data/lib/vagrant-lxc/action/disconnect.rb +0 -18
  68. data/lib/vagrant-lxc/action/is_running.rb +0 -19
  69. data/spec/acceptance/sanity_check_spec.rb +0 -111
  70. data/spec/acceptance/support/acceptance_example_group.rb +0 -76
  71. data/spec/acceptance/support/machine_ext.rb +0 -12
  72. data/spec/acceptance/support/test_ui.rb +0 -22
  73. data/spec/acceptance_helper.rb +0 -21
@@ -1,151 +0,0 @@
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}"
data/boxes/common/cleanup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
-
3
- cache=`readlink -f .`
4
- rootfs="${cache}/rootfs"
5
-
6
- rm -rf $rootfs/tmp/*
7
- chroot $rootfs apt-get clean
@@ -1,16 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- rootfs=$1
6
-
7
- echo "installing babushka"
8
- cat > $rootfs/tmp/install-babushka.sh << EOF
9
- #!/bin/sh
10
- curl https://babushka.me/up | sudo bash
11
-
12
- EOF
13
- chmod +x $rootfs/tmp/install-babushka.sh
14
- chroot $rootfs /tmp/install-babushka.sh
15
-
16
- rm -rf $rootfs/tmp/*
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- rootfs=$1
6
-
7
- echo "installing chef"
8
- cat > $rootfs/tmp/install-chef.sh << EOF
9
- #!/bin/sh
10
- curl -L https://www.opscode.com/chef/install.sh -k | sudo bash
11
- EOF
12
- chmod +x $rootfs/tmp/install-chef.sh
13
- chroot $rootfs /tmp/install-chef.sh
14
-
15
- rm -rf $rootfs/tmp/*
@@ -1,13 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- rootfs=$1
6
-
7
- echo "installing puppet"
8
- wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb -O "${rootfs}/tmp/puppetlabs-release-stable.deb"
9
- chroot $rootfs dpkg -i "/tmp/puppetlabs-release-stable.deb"
10
- chroot $rootfs apt-get update
11
- chroot $rootfs apt-get install puppet -y --force-yes
12
-
13
- rm -rf $rootfs/tmp/*
@@ -1,12 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- rootfs=$1
6
-
7
- echo "installing salt"
8
- chroot $rootfs apt-add-repository -y ppa:saltstack/salt
9
- chroot $rootfs apt-get update
10
- chroot $rootfs apt-get install salt-minion -y --force-yes
11
-
12
- rm -rf $rootfs/tmp/*
@@ -1,28 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- rootfs=$1
6
-
7
- echo "installing salt"
8
-
9
- if [ $SUITE == "squeeze" ]; then
10
- SALT_SOURCE="deb http://debian.saltstack.com/debian squeeze-saltstack main\ndeb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free"
11
- elif [ $SUITE == "sid" ]; then
12
- SALT_SOURCE="deb http://debian.saltstack.com/debian unstable main"
13
- else
14
- SALT_SOURCE="deb http://debian.saltstack.com/debian wheezy-saltstack main"
15
- fi
16
-
17
- cat > $rootfs/tmp/install-salt << EOF
18
- #!/bin/sh
19
- echo "$SALT_SOURCE" > /etc/apt/sources.list.d/saltstack.list
20
- wget -q -O- "http://debian.saltstack.com/debian-salt-team-joehealy.gpg.key" | apt-key add -
21
- apt-get update
22
- apt-get install -y salt-minion
23
- apt-get clean
24
- EOF
25
-
26
- chroot $rootfs sh /tmp/install-salt
27
-
28
- rm -rf $rootfs/tmp/*
@@ -1,226 +0,0 @@
1
- #!/bin/bash
2
-
3
- # This is a modified version of /usr/share/lxc/templates/lxc-ubuntu
4
- # that comes with Ubuntu 13.04 changed to suit vagrant-lxc needs
5
-
6
- #
7
- # template script for generating ubuntu container for LXC
8
- #
9
- # This script consolidates and extends the existing lxc ubuntu scripts
10
- #
11
-
12
- # Copyright © 2011 Serge Hallyn <serge.hallyn@canonical.com>
13
- # Copyright © 2010 Wilhelm Meier
14
- # Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
15
- #
16
- # This program is free software; you can redistribute it and/or modify
17
- # it under the terms of the GNU General Public License version 2, as
18
- # published by the Free Software Foundation.
19
-
20
- # This program is distributed in the hope that it will be useful,
21
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- # GNU General Public License for more details.
24
-
25
- # You should have received a copy of the GNU General Public License along
26
- # with this program; if not, write to the Free Software Foundation, Inc.,
27
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28
- #
29
-
30
- set -e
31
-
32
- if [ -r /etc/default/lxc ]; then
33
- . /etc/default/lxc
34
- fi
35
-
36
- extract_rootfs()
37
- {
38
- tarball=$1
39
- arch=$2
40
- rootfs=$3
41
-
42
- echo "Extracting $tarball ..."
43
- mkdir -p $rootfs
44
- (cd $rootfs && tar xfz $tarball --strip-components=2)
45
- return 0
46
- }
47
-
48
- install_ubuntu()
49
- {
50
- rootfs=$1
51
- release=$2
52
- tarball=$3
53
- mkdir -p /var/lock/subsys/
54
-
55
- (
56
- flock -x 200
57
- if [ $? -ne 0 ]; then
58
- echo "Cache repository is busy."
59
- return 1
60
- fi
61
-
62
- extract_rootfs $tarball $arch $rootfs
63
- if [ $? -ne 0 ]; then
64
- echo "Failed to copy rootfs"
65
- return 1
66
- fi
67
-
68
- return 0
69
-
70
- ) 200>/var/lock/subsys/lxc
71
-
72
- return $?
73
- }
74
-
75
- copy_configuration()
76
- {
77
- path=$1
78
- rootfs=$2
79
- name=$3
80
-
81
- grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
82
-
83
- # if there is exactly one veth network entry, make sure it has an
84
- # associated hwaddr.
85
- nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
86
- if [ $nics -eq 1 ]; then
87
- grep -q "^lxc.network.hwaddr" $path/config || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
88
- fi
89
-
90
- if [ $? -ne 0 ]; then
91
- echo "Failed to add configuration"
92
- return 1
93
- fi
94
-
95
- return 0
96
- }
97
-
98
- post_process()
99
- {
100
- rootfs=$1
101
-
102
- # rmdir /dev/shm for containers that have /run/shm
103
- # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
104
- # get bind mounted to the host's /run/shm. So try to rmdir
105
- # it, and in case that fails move it out of the way.
106
- if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
107
- mv $rootfs/dev/shm $rootfs/dev/shm.bak
108
- ln -s /run/shm $rootfs/dev/shm
109
- fi
110
- }
111
-
112
- usage()
113
- {
114
- cat <<EOF
115
- $1 -h|--help [-a|--arch] [--trim] [-d|--debug] [--rootfs <rootfs>] [-T|--tarball <rootfs-tarball>
116
- arch: the container architecture (e.g. amd64): defaults to host arch
117
- EOF
118
- return 0
119
- }
120
-
121
- options=$(getopt -o a:b:hp:r:xn:FS:d:C -l arch:,help,path:,release:,trim,name:,flush-cache,auth-key:,debug:,tarball:,rootfs: -- "$@")
122
- if [ $? -ne 0 ]; then
123
- usage $(basename $0)
124
- exit 1
125
- fi
126
- eval set -- "$options"
127
-
128
- release=precise # Default to the last Ubuntu LTS release for non-Ubuntu systems
129
- if [ -f /etc/lsb-release ]; then
130
- . /etc/lsb-release
131
- if [ "$DISTRIB_ID" = "Ubuntu" ]; then
132
- release=$DISTRIB_CODENAME
133
- fi
134
- fi
135
-
136
- arch=$(uname -m)
137
-
138
- # Code taken from debootstrap
139
- if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
140
- arch=`/usr/bin/dpkg --print-architecture`
141
- elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
142
- arch=`/usr/bin/udpkg --print-architecture`
143
- else
144
- arch=$(uname -m)
145
- if [ "$arch" = "i686" ]; then
146
- arch="i386"
147
- elif [ "$arch" = "x86_64" ]; then
148
- arch="amd64"
149
- elif [ "$arch" = "armv7l" ]; then
150
- arch="armel"
151
- fi
152
- fi
153
-
154
- debug=0
155
- trim_container=0
156
- hostarch=$arch
157
- while true
158
- do
159
- case "$1" in
160
- -h|--help) usage $0 && exit 0;;
161
- --rootfs) rootfs=$2; shift 2;;
162
- -p|--path) path=$2; shift 2;;
163
- -n|--name) name=$2; shift 2;;
164
- -T|--tarball) tarball=$2; shift 2;;
165
- -a|--arch) arch=$2; shift 2;;
166
- -S|--auth-key) auth_key=$2; shift 2;;
167
- -d|--debug) debug=1; shift 1;;
168
- --) shift 1; break ;;
169
- *) break ;;
170
- esac
171
- done
172
-
173
- if [ $debug -eq 1 ]; then
174
- set -x
175
- fi
176
-
177
- if [ "$arch" == "i686" ]; then
178
- arch=i386
179
- fi
180
-
181
- if [ $hostarch = "i386" -a $arch = "amd64" ]; then
182
- echo "can't create amd64 container on i386"
183
- exit 1
184
- fi
185
-
186
- if [ -z "$path" ]; then
187
- echo "'path' parameter is required"
188
- exit 1
189
- fi
190
-
191
- if [ "$(id -u)" != "0" ]; then
192
- echo "This script should be run as 'root'"
193
- exit 1
194
- fi
195
-
196
- # detect rootfs
197
- config="$path/config"
198
- # if $rootfs exists here, it was passed in with --rootfs
199
- if [ -z "$rootfs" ]; then
200
- if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
201
- rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
202
- else
203
- rootfs=$path/rootfs
204
- fi
205
- fi
206
-
207
- install_ubuntu $rootfs $release $tarball
208
- if [ $? -ne 0 ]; then
209
- echo "failed to install ubuntu $release"
210
- exit 1
211
- fi
212
-
213
- copy_configuration $path $rootfs $name $arch
214
- if [ $? -ne 0 ]; then
215
- echo "failed write configuration file"
216
- exit 1
217
- fi
218
-
219
- post_process $rootfs $release $trim_container
220
-
221
- echo ""
222
- echo "##"
223
- echo "# The default user is 'vagrant' with password 'vagrant'!"
224
- echo "# Use the 'sudo' command to run tasks as root in the container."
225
- echo "##"
226
- echo ""