vagrant-export 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48931115e8fd25527afc676c98ce1104281ab66d
4
- data.tar.gz: befa92a53e1fa97fc036d6d0f428c2c581f87c65
3
+ metadata.gz: 3ddbe360fa54bea73f25c2241a25154f40740a4a
4
+ data.tar.gz: 46c28c9124e22569ae174c8a90b1de86dfa57103
5
5
  SHA512:
6
- metadata.gz: dbb99ff418f44bd31f96c80f058a31ea62813118ba207f72c838a82d73d23383ac112d4cb276e25b3884e0df79176806e17c2c7c94b075cfb64ac1c64083b6ba
7
- data.tar.gz: 80d2fd744aa98f518d9cda978ed84f5942af921fb7ebdaed1872ed8a0b8f9197201bdecbaad228de0bd39867dba3f1b5638a0370680c85f805fa7fef3bc5674a
6
+ metadata.gz: cdf99b3412fbb5680e3b6c499c70c7af87f4590c1661f7609540954468cd3dfa36cacf4d2c9136c4d69daeda14661aebc5e38f780e76c693fafa551ba96b9b4d
7
+ data.tar.gz: 535bc6e78a326bc85e06d513e125c6a53f3b75abe94fd2c29931017e0a3a076e6613775207654d1e00618349756f4b9332c25699b9a5b5be8855afb046b5fbad
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.idea
2
2
  /.vagrant
3
3
  /Gemfile.lock
4
- Vagrantfile
4
+ /Vagrantfile
5
+ /*.gem
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ GIT
2
+ remote: https://github.com/mitchellh/vagrant.git
3
+ revision: a8dcf92f14d8bb8828a43b91804334673508f467
4
+ specs:
5
+ vagrant (1.7.2)
6
+ bundler (>= 1.5.2, < 1.8.0)
7
+ childprocess (~> 0.5.0)
8
+ erubis (~> 2.7.0)
9
+ hashicorp-checkpoint (~> 0.1.1)
10
+ i18n (>= 0.6.0, <= 0.8.0)
11
+ listen (~> 2.8.0)
12
+ log4r (~> 1.1.9, < 1.1.11)
13
+ net-scp (~> 1.1.0)
14
+ net-sftp (~> 2.1)
15
+ net-ssh (>= 2.6.6, < 2.10.0)
16
+ nokogiri (= 1.6.3.1)
17
+ rb-kqueue (~> 0.2.0)
18
+ rest-client (>= 1.6.0, < 2.0)
19
+ wdm (~> 0.1.0)
20
+ winrm (~> 1.3)
21
+ winrm-fs (~> 0.1.0)
22
+
23
+ PATH
24
+ remote: .
25
+ specs:
26
+ vagrant-export (0.3.3)
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ builder (3.2.2)
32
+ celluloid (0.16.0)
33
+ timers (~> 4.0.0)
34
+ childprocess (0.5.5)
35
+ ffi (~> 1.0, >= 1.0.11)
36
+ erubis (2.7.0)
37
+ ffi (1.9.7)
38
+ gssapi (1.2.0)
39
+ ffi (>= 1.0.1)
40
+ gyoku (1.2.3)
41
+ builder (>= 2.1.2)
42
+ hashicorp-checkpoint (0.1.4)
43
+ hitimes (1.2.2)
44
+ httpclient (2.6.0.1)
45
+ i18n (0.7.0)
46
+ listen (2.8.6)
47
+ celluloid (>= 0.15.2)
48
+ rb-fsevent (>= 0.9.3)
49
+ rb-inotify (>= 0.9)
50
+ little-plugger (1.1.3)
51
+ log4r (1.1.10)
52
+ logging (1.8.2)
53
+ little-plugger (>= 1.1.3)
54
+ multi_json (>= 1.8.4)
55
+ mime-types (2.4.3)
56
+ mini_portile (0.6.0)
57
+ multi_json (1.11.0)
58
+ net-scp (1.1.2)
59
+ net-ssh (>= 2.6.5)
60
+ net-sftp (2.1.2)
61
+ net-ssh (>= 2.6.5)
62
+ net-ssh (2.9.2)
63
+ netrc (0.10.3)
64
+ nokogiri (1.6.3.1-x64-mingw32)
65
+ mini_portile (= 0.6.0)
66
+ nori (2.4.0)
67
+ rb-fsevent (0.9.4)
68
+ rb-inotify (0.9.5)
69
+ ffi (>= 0.5.0)
70
+ rb-kqueue (0.2.3)
71
+ ffi (>= 0.5.0)
72
+ rest-client (1.7.3-x64-mingw32)
73
+ ffi (~> 1.9)
74
+ mime-types (>= 1.16, < 3.0)
75
+ netrc (~> 0.7)
76
+ rubyntlm (0.4.0)
77
+ rubyzip (1.1.7)
78
+ timers (4.0.1)
79
+ hitimes
80
+ uuidtools (2.1.5)
81
+ wdm (0.1.0)
82
+ winrm (1.3.0)
83
+ builder (>= 2.1.2)
84
+ gssapi (~> 1.2)
85
+ gyoku (~> 1.0)
86
+ httpclient (~> 2.2, >= 2.2.0.2)
87
+ logging (~> 1.6, >= 1.6.1)
88
+ nori (~> 2.0)
89
+ rubyntlm (~> 0.4.0)
90
+ uuidtools (~> 2.1.2)
91
+ winrm-fs (0.1.0)
92
+ erubis (~> 2.7)
93
+ logging (~> 1.6, >= 1.6.1)
94
+ rubyzip (~> 1.1)
95
+ winrm (~> 1.3.0)
96
+
97
+ PLATFORMS
98
+ x64-mingw32
99
+
100
+ DEPENDENCIES
101
+ vagrant!
102
+ vagrant-export!
data/Vagrantfile ADDED
@@ -0,0 +1,3 @@
1
+ Vagrant.configure('2') do |config|
2
+ config.vm.box = 'hashicorp/precise32'
3
+ end
@@ -33,10 +33,16 @@ module VagrantPlugins
33
33
  return 1 unless argv
34
34
 
35
35
  require_relative 'exporter'
36
- ex = Exporter.new(@env, @logger)
37
36
 
38
37
  with_target_vms argv, reverse: true do |machine|
39
- ex.handle(machine, options[:fast], options[:bare])
38
+ ex = Exporter.new(@env, @logger, machine)
39
+
40
+ if File.file?(ex.target_box)
41
+ require_relative 'error'
42
+ raise BoxAlreadyExists
43
+ end
44
+
45
+ ex.handle(options[:fast], options[:bare])
40
46
  end
41
47
  0
42
48
  end
@@ -0,0 +1,18 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Export
8
+ class VirtualboxExportError < Vagrant::Errors::VagrantError
9
+ error_message('Cannot export Virtualbox machine to appliance')
10
+ end
11
+ class BoxAlreadyExists < Vagrant::Errors::VagrantError
12
+ error_message('A box file for this machine already exists')
13
+ end
14
+ class NotCreated < Vagrant::Errors::VagrantError
15
+ error_message('Cannot export a not created machine. Please make at least one vagrant up')
16
+ end
17
+ end
18
+ end
@@ -4,6 +4,7 @@
4
4
  # #
5
5
 
6
6
  require 'fileutils'
7
+ require_relative 'error'
7
8
 
8
9
  module VagrantPlugins
9
10
  module Export
@@ -11,39 +12,59 @@ module VagrantPlugins
11
12
 
12
13
  # @param env Vagrant::Environment
13
14
  # @param logger Log4r::Logger
14
- def initialize(env, logger)
15
+ # @param vm Vagrant::Machine
16
+ def initialize(env, logger, vm)
17
+ @vm = vm
15
18
  @env = env
16
19
  @logger = logger
17
20
  end
18
21
 
19
- # @param vm Vagrant::Machine
20
22
  # @param fast Boolean
21
23
  # @param bare Boolean
22
24
  # @return string
23
- def handle(vm, fast, bare)
24
- @vm = vm
25
- @did_run = false
25
+ def handle(fast, bare)
26
+ @did_run = false
27
+ @private_key = nil
28
+ @tmp_path = nil
29
+ @box_file_name = nil
30
+
31
+ if @vm.state.short_description == 'not created'
32
+ raise VagrantPlugins::Export::NotCreated
33
+ end
26
34
 
27
- unless fast
28
- if can_compress
29
- compress
30
- else
31
- @vm.ui.error('Cannot compress this type of machine')
32
- return 1
35
+ begin
36
+ ssh_info = vm.ssh_info
37
+ unless ssh_info == nil
38
+ @private_key = ssh_info[:private_key_path]
39
+ end
40
+
41
+ unless fast
42
+ if can_compress
43
+ compress
44
+ else
45
+ @vm.ui.error('Cannot compress this type of machine')
46
+ return 1
47
+ end
33
48
  end
34
- end
35
49
 
36
- return 1 unless export
37
- return 1 unless files(bare)
50
+ return 1 unless export
51
+ return 1 unless files(bare)
38
52
 
39
- finalize
53
+ finalize
54
+ ensure
55
+ FileUtils.rm_rf(@tmp_path) if Dir.exists?(@tmp_path)
56
+ FileUtils.rm_rf(@box_file_name) if File.file?(@box_file_name)
57
+ end
58
+ target_box
59
+ end
40
60
 
41
- @target_box
61
+ def target_box
62
+ box_name = @vm.box.name.gsub('/', '_')
63
+ File.join(@env.cwd, box_name + '.box')
42
64
  end
43
65
 
44
66
  protected
45
67
 
46
-
47
68
  def can_compress
48
69
  if @vm.state.short_description == 'running'
49
70
  @did_run = true
@@ -55,6 +76,12 @@ module VagrantPlugins
55
76
  compress_supported = false
56
77
 
57
78
  if @vm.config.vm.communicator != :winrm
79
+
80
+ ssh_info = vm.ssh_info
81
+ unless ssh_info == nil
82
+ @private_key = ssh_info[:private_key_path]
83
+ end
84
+
58
85
  @vm.communicate.execute('lsb_release -i -s', error_key: :ssh_bad_exit_status_muted) do |type, data|
59
86
  if type == :stdout && data.to_s =~ /mint|ubuntu|debian/i
60
87
  compress_supported = true
@@ -100,12 +127,19 @@ module VagrantPlugins
100
127
  # Shamelessly stolen from Vagrant::Action::General::Package
101
128
  def setup_private_key
102
129
 
103
- # If we don't have a generated private key, we do nothing
130
+ # Key generated by vagrant
104
131
  path = @vm.data_dir.join('private_key')
132
+
133
+ # Use a different generated key if configured
134
+ if @private_key != nil
135
+ path = File.new(@private_key.to_s, 'r') unless @private_key == Vagrant.source_root.join('keys', 'vagrant')
136
+ end
137
+
138
+ # If we don't have a generated private key, we do nothing
105
139
  return unless path.file?
106
140
 
107
141
  # Copy it into our box directory
108
- new_path = File.join(@tmp_path, 'vagrant_private_key')
142
+ new_path = File.join(@tmp_path, 'private_key')
109
143
  @logger.debug("Copy private key from #{path} to #{new_path}")
110
144
  FileUtils.cp(path, new_path)
111
145
 
@@ -135,12 +169,11 @@ module VagrantPlugins
135
169
  @logger.debug('No Vagrantfile found, create one')
136
170
  end
137
171
 
138
-
139
172
  File.open(vf_path, mode) do |f|
140
173
  f.binmode
141
174
  f.puts
142
175
  f.puts %Q[Vagrant.configure("2") do |config|]
143
- f.puts %Q[ config.ssh.private_key_path = File.expand_path("../vagrant_private_key", __FILE__)]
176
+ f.puts %Q[ config.ssh.private_key_path = File.expand_path("../private_key", __FILE__)]
144
177
  f.puts %Q[end]
145
178
  end
146
179
  end
@@ -192,12 +225,34 @@ module VagrantPlugins
192
225
  }
193
226
 
194
227
  else
195
- @vm.provider.driver.export File.join(exported_path, 'box.ovf') do |progress|
196
- @vm.ui.clear_line
197
- @vm.ui.report_progress(progress.percent, 100, false)
198
- end
228
+
229
+ ovf_file = File.join(exported_path, @vm.box.name.gsub(/[^a-zA-Z0-9]+/, '_')) + '.ovf'
230
+ vm_id = @vm.id.to_s
231
+
232
+ opts = {}
233
+ opts[:notify] = [:stdout, :stderr]
234
+
235
+ @logger.debug("Export #{vm_id} to #{ovf_file}")
236
+ @env.ui.info('0%', new_line: false)
237
+
238
+ Vagrant::Util::Subprocess.execute('VBoxManage', 'export', vm_id, '-o', ovf_file, opts) { |io, data|
239
+
240
+ d = data.to_s
241
+ @logger.debug(d)
242
+
243
+ unless io == :stdout
244
+ if /\d+%/ =~ d
245
+ @env.ui.clear_line
246
+ @env.ui.info(d.match(/\d+%/).to_a.pop, new_line: false)
247
+ else
248
+ @logger.error(d)
249
+ raise VirtualboxExportError
250
+ end
251
+ end
252
+ }
199
253
  end
200
254
 
255
+ @env.ui.clear_line
201
256
  @logger.debug("Exported VM to #{exported_path}")
202
257
  end
203
258
 
@@ -283,9 +338,41 @@ module VagrantPlugins
283
338
  @vm.ui.info('Packaging box file')
284
339
 
285
340
  Vagrant::Util::SafeChdir.safe_chdir(@tmp_path) do
341
+
286
342
  files = Dir.glob(File.join('.', '**', '*'))
287
343
  @logger.debug("Create box file #{@box_file_name} containing #{files}")
288
- Vagrant::Util::Subprocess.execute('bsdtar', '-czf', @box_file_name, *files)
344
+
345
+ if Vagrant::Util::Which.which('pv') != nil && Vagrant::Util::Which.which('tar') && Vagrant::Util::Which.which('gzip')
346
+ total_size = 0
347
+
348
+ logger.debug('Using custom packaging command to create progress output')
349
+ @env.ui.info('Starting compression')
350
+
351
+ files.each { |f|
352
+ total_size += File.size(f)
353
+ }
354
+
355
+ @logger.debug("Complete size of files is #{total_size} bytes")
356
+
357
+ opts = {}
358
+ opts[:notify] = [:stderr, :stdout]
359
+
360
+ Vagrant::Util::Subprocess.execute('tar', ' -cf - ', *files, ' | pv -n -s ', total_size, ' | gzip -c > ', @box_file_name) { |io, data|
361
+ d = data.to_s
362
+
363
+ if io == :stderr
364
+ @logger.error(d)
365
+ else
366
+ @env.ui.clear_line
367
+ @env.ui.info(d.match(/\d+/).to_a.pop.to_s + '%')
368
+ end
369
+ }
370
+
371
+ @env.ui.clear_line
372
+
373
+ else
374
+ Vagrant::Util::Subprocess.execute('bsdtar', '-czf', @box_file_name, *files)
375
+ end
289
376
  end
290
377
 
291
378
  0
@@ -294,15 +381,11 @@ module VagrantPlugins
294
381
  def finalize
295
382
  # Rename the box file
296
383
  if File.exist?(@box_file_name)
297
- box_name = @vm.box.name.gsub('/', '_')
298
- @target_box = File.join(@env.cwd, box_name + '.box')
299
- FileUtils.mv(@box_file_name, @target_box)
300
- @vm.ui.info('Created ' + @target_box)
384
+ target = target_box
385
+ FileUtils.mv(@box_file_name, target)
386
+ @vm.ui.info('Created ' + target)
301
387
  end
302
388
 
303
- # Remove the tmp files
304
- FileUtils.rm_rf(@tmp_path)
305
-
306
389
  # Resume the machine
307
390
  if @did_run
308
391
  @vm.ui.info('Bringing the machine back up')
@@ -5,6 +5,6 @@
5
5
 
6
6
  module VagrantPlugins
7
7
  module Export
8
- VERSION = '0.3.3'
8
+ VERSION = '0.3.4'
9
9
  end
10
10
  end
data/res/cleanup.sh CHANGED
@@ -15,7 +15,7 @@ done
15
15
 
16
16
  echo "Removing old kernel packages"
17
17
  apt-get -qq -y --purge remove $(dpkg --list | egrep '^rc' | awk '{print $2}')
18
- apt-get -qq -y --purge remove $(dpkg --list | egrep 'linux-(image(-extra)?|headers)-[0-9]' | awk '{print $3,$2}' | grep -v $(uname -r | sed -e s/-generic//g) | awk '{ print $2}')
18
+ apt-get -qq -y --purge remove $(dpkg --list | egrep '^i' | egrep 'linux-(image(-extra)?|headers)-[0-9]' | awk '{print $3,$2}' | grep -v $(uname -r | sed -e s/-generic//g) | awk '{print $2}')
19
19
 
20
20
  echo "Cleaning up apt"
21
21
  apt-get -qq -y --purge autoremove
@@ -27,6 +27,7 @@ echo "Cleaning up home"
27
27
  rm -rf $HOME/.cache
28
28
  rm -rf $HOME/.local
29
29
  rm -rf $HOME/.npm
30
+ rm -rf $HOME/.composer
30
31
  rm -rf $HOME/tmp
31
32
 
32
33
  if [[ -d /www ]]; then
@@ -37,41 +38,39 @@ else
37
38
  DOCROOT="/var/www"
38
39
  fi
39
40
 
40
- echo "Cleaning up document root $DOCROOT"
41
+ echo "Cleaning up document root ${DOCROOT}"
41
42
 
42
- if [[ -d $DOCROOT/typo3temp ]]; then
43
+ if [[ -d ${DOCROOT}/typo3temp ]]; then
43
44
  echo "Removing TYPO3 CMS temp files"
44
- find $DOCROOT/typo3temp -type f -exec rm -f {} \;
45
- find $DOCROOT/typo3temp -type d -iname "_processed_" -exec rm -rf {} \; > /dev/null 2>&1
45
+ find ${DOCROOT}/typo3temp -type f -exec rm -f {} \;
46
46
 
47
- if [[ -d $DOCROOT/fileadmin/_processed_ ]]; then
48
- rm -rf $DOCROOT/fileadmin/_processed_/* > /dev/null 2>&1
47
+ if [[ -d ${DOCROOT}/fileadmin/_processed_ ]]; then
48
+ rm -rf ${DOCROOT}/fileadmin/_processed_/* > /dev/null 2>&1
49
49
  fi
50
50
  fi
51
51
 
52
- if [[ -d $DOCROOT/Data/Temporary ]]; then
52
+ if [[ -d ${DOCROOT}/Data/Temporary ]]; then
53
53
  echo "Removing TYPO3 Flow temp files"
54
- rm -rf $DOCROOT/Data/Temporary/* > /dev/null 2>&1
54
+ rm -rf ${DOCROOT}/Data/Temporary/* > /dev/null 2>&1
55
55
  fi
56
56
 
57
57
  if [[ -d /var/www/var/cache ]]; then
58
58
  echo "Removing Magento temp files"
59
- rm -rf $DOCROOT/downloader/.cache/*
60
- rm -rf $DOCROOT/downloader/pearlib/cache/*
61
- rm -rf $DOCROOT/downloader/pearlib/download/*
62
- rm -rf $DOCROOT/var/cache/*
63
- rm -rf $DOCROOT/var/locks/*
64
- rm -rf $DOCROOT/var/log/*
65
- rm -rf $DOCROOT/var/report/*
66
- rm -rf $DOCROOT/var/session/*
67
- rm -rf $DOCROOT/var/tmp/*
59
+ rm -rf ${DOCROOT}/downloader/.cache/*
60
+ rm -rf ${DOCROOT}/downloader/pearlib/cache/*
61
+ rm -rf ${DOCROOT}/downloader/pearlib/download/*
62
+ rm -rf ${DOCROOT}/var/cache/*
63
+ rm -rf ${DOCROOT}/var/locks/*
64
+ rm -rf ${DOCROOT}/var/log/*
65
+ rm -rf ${DOCROOT}/var/report/*
66
+ rm -rf ${DOCROOT}/var/session/*
67
+ rm -rf ${DOCROOT}/var/tmp/*
68
68
  fi
69
69
 
70
70
  echo "Zeroing device to make space..."
71
- dd if=/dev/zero of=/EMPTY bs=1M > /dev/null 2>&1
71
+ dd if=/dev/zero of=/EMPTY bs=1M > /dev/null 2>&1
72
+ sync
72
73
  rm -f /EMPTY
73
-
74
- echo "Sync to disc"
75
74
  sync
76
75
 
77
76
  exit 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Grossberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-06-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Export boxes to .box files including the original Vagrantfile and some
14
14
  cleanups inside the VM
@@ -19,9 +19,12 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
21
  - Gemfile
22
+ - Gemfile.lock
22
23
  - README.md
24
+ - Vagrantfile
23
25
  - lib/vagrant-export.rb
24
26
  - lib/vagrant-export/command.rb
27
+ - lib/vagrant-export/error.rb
25
28
  - lib/vagrant-export/exporter.rb
26
29
  - lib/vagrant-export/plugin.rb
27
30
  - lib/vagrant-export/version.rb
@@ -47,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
50
  version: '0'
48
51
  requirements: []
49
52
  rubyforge_project:
50
- rubygems_version: 2.4.6
53
+ rubygems_version: 2.2.2
51
54
  signing_key:
52
55
  specification_version: 4
53
56
  summary: Export boxes to .box files including the original Vagrantfile and some cleanups