tenderloin 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/config/default.rb CHANGED
@@ -16,11 +16,9 @@ Tenderloin::Config.run do |config|
16
16
  config.package.name = 'tenderloin'
17
17
  config.package.extension = '.box'
18
18
 
19
- config.chef.enabled = false
20
- config.chef.cookbooks_path = "cookbooks"
21
- config.chef.provisioning_path = "/tmp/tenderloin-chef"
22
- config.chef.json = {
23
- :instance_role => "tenderloin",
24
- :recipes => ["tenderloin_main"]
25
- }
19
+ config.provisioning.script = nil
20
+ config.provisioning.command = nil
21
+
22
+ config.shared_folders.enabled = true
23
+ config.shared_folders.folders = []
26
24
  end
@@ -3,54 +3,25 @@ module Tenderloin
3
3
  module VM
4
4
  class Provision < Base
5
5
  def execute!
6
- chown_provisioning_folder
7
- setup_json
8
- setup_solo_config
9
- run_chef_solo
6
+ setup_script if Tenderloin.config.provisioning.script
7
+ run_command if Tenderloin.config.provisioning.command
10
8
  end
11
9
 
12
- def chown_provisioning_folder
13
- logger.info "Setting permissions on provisioning folder..."
14
- SSH.execute do |ssh|
15
- ssh.exec!("sudo chown #{Tenderloin.config.ssh.username} #{Tenderloin.config.chef.provisioning_path}")
16
- end
17
- end
18
-
19
- def setup_json
20
- logger.info "Generating JSON and uploading..."
21
-
22
- # Set up initial configuration
23
- data = {
24
- :config => Tenderloin.config,
25
- :directory => Tenderloin.config.vm.project_directory,
26
- }
27
-
28
- # And wrap it under the "tenderloin" namespace
29
- data = { :tenderloin => data }
30
-
31
- # Merge with the "extra data" which isn't put under the
32
- # tenderloin namespace by default
33
- data.merge!(Tenderloin.config.chef.json)
10
+ def setup_script
11
+ logger.info "Uploading provisioning script..."
34
12
 
35
- json = data.to_json
13
+ SSH.upload!(@runner.fusion_vm.ip, StringIO.new(Tenderloin.config.provisioning.script), File.join('/tmp', "tenderloin_provision.sh"))
36
14
 
37
- SSH.upload!(StringIO.new(json), File.join(Tenderloin.config.chef.provisioning_path, "dna.json"))
15
+ Tenderloin.config.provisioning.command = "/tmp/tenderloin_provision.sh"
38
16
  end
39
17
 
40
- def setup_solo_config
41
- solo_file = <<-solo
42
- file_cache_path "#{Tenderloin.config.chef.provisioning_path}"
43
- cookbook_path "#{cookbooks_path}"
44
- solo
45
-
46
- logger.info "Uploading chef-solo configuration script..."
47
- SSH.upload!(StringIO.new(solo_file), File.join(Tenderloin.config.chef.provisioning_path, "solo.rb"))
48
- end
49
-
50
- def run_chef_solo
51
- logger.info "Running chef recipes..."
52
- SSH.execute do |ssh|
53
- ssh.exec!("cd #{Tenderloin.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
18
+ def run_command
19
+ logger.info "Running Provisioning command..."
20
+ cmd = ""
21
+ cmd << "chmod +x /tmp/tenderloin_provision.sh && " if Tenderloin.config.provisioning.script
22
+ cmd << Tenderloin.config.provisioning.command
23
+ SSH.execute(@runner.fusion_vm.ip) do |ssh|
24
+ ssh.exec!(cmd) do |channel, data, stream|
54
25
  # TODO: Very verbose. It would be easier to save the data and only show it during
55
26
  # an error, or when verbosity level is set high
56
27
  logger.info("#{stream}: #{data}")
@@ -58,13 +29,6 @@ solo
58
29
  end
59
30
  end
60
31
 
61
- def cookbooks_path
62
- File.join(Tenderloin.config.chef.provisioning_path, "cookbooks")
63
- end
64
-
65
- def collect_shared_folders
66
- ["tenderloin-provisioning", File.expand_path(Tenderloin.config.chef.cookbooks_path, Env.root_path), cookbooks_path]
67
- end
68
32
  end
69
33
  end
70
34
  end
@@ -4,8 +4,8 @@ module Tenderloin
4
4
  class Reload < Base
5
5
  def prepare
6
6
  steps = [SharedFolders, Boot]
7
- steps.unshift(Halt) if @runner.vm.running?
8
- steps << Provision if Tenderloin.config.chef.enabled
7
+ steps.unshift(Halt) if @runner.fusion_vm.running?
8
+ steps << Provision if Tenderloin.config.provisioning.enabled
9
9
 
10
10
  steps.each do |action_klass|
11
11
  @runner.add_action(action_klass)
@@ -5,6 +5,8 @@ module Tenderloin
5
5
  def shared_folders
6
6
  shared_folders = @runner.invoke_callback(:collect_shared_folders)
7
7
 
8
+ shared_folders = shared_folders + Tenderloin.config.shared_folders.folders
9
+
8
10
  # Basic filtering of shared folders. Basically only verifies that
9
11
  # the result is an array of 3 elements. In the future this should
10
12
  # also verify that the host path exists, the name is valid,
@@ -15,7 +17,7 @@ module Tenderloin
15
17
  else
16
18
  nil
17
19
  end
18
- end.compact
20
+ end#.compact
19
21
  end
20
22
 
21
23
  def before_boot
@@ -23,20 +25,22 @@ module Tenderloin
23
25
  end
24
26
 
25
27
  def after_boot
26
- logger.info "Creating shared folders metadata..."
28
+ if Tenderloin.config.shared_folders.enabled
29
+ logger.info "Creating shared folders metadata..."
27
30
 
28
- shared_folders.each do |name, hostpath, guestpath|
29
- @runner.fusion_vm.share_folder(name, hostpath)
30
- @runner.fusion_vm.enable_shared_folders
31
- end
31
+ shared_folders.each do |name, hostpath, guestpath|
32
+ @runner.fusion_vm.share_folder(name, File.expand_path(hostpath))
33
+ @runner.fusion_vm.enable_shared_folders
34
+ end
32
35
 
33
- logger.info "Linking shared folders..."
36
+ logger.info "Linking shared folders..."
34
37
 
35
- Tenderloin::SSH.execute(@runner.fusion_vm.ip) do |ssh|
36
- shared_folders.each do |name, hostpath, guestpath|
37
- logger.info "-- #{name}: #{guestpath}"
38
- ssh.exec!("sudo ln -s /mnt/hgfs/#{name} #{guestpath}")
39
- ssh.exec!("sudo chown #{Tenderloin.config.ssh.username} #{guestpath}")
38
+ Tenderloin::SSH.execute(@runner.fusion_vm.ip) do |ssh|
39
+ shared_folders.each do |name, hostpath, guestpath|
40
+ logger.info "-- #{name}: #{guestpath}"
41
+ ssh.exec!("sudo ln -s /mnt/hgfs/#{name} #{guestpath}")
42
+ ssh.exec!("sudo chown #{Tenderloin.config.ssh.username} #{guestpath}")
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -17,7 +17,7 @@ msg
17
17
  # Up is a "meta-action" so it really just queues up a bunch
18
18
  # of other actions in its place:
19
19
  steps = [Import, SharedFolders, Boot]
20
- steps << Provision if Tenderloin.config.chef.enabled
20
+ steps << Provision if Tenderloin.config.provisioning.enabled
21
21
  steps.insert(0, MoveHardDrive) if Tenderloin.config.vm.hd_location
22
22
 
23
23
  steps.each do |action_klass|
@@ -49,6 +49,12 @@ module Tenderloin
49
49
  Tenderloin::Commands.reload
50
50
  end
51
51
 
52
+ desc "provision [--file <tenderfile>]", "Runs the provisioning script"
53
+ def provision()
54
+ setup
55
+ Tenderloin::Commands.provision
56
+ end
57
+
52
58
  desc "ssh [--file <tenderfile>]", "SSH's in to the VM"
53
59
  def ssh()
54
60
  setup
@@ -143,6 +143,13 @@ error
143
143
  box.destroy
144
144
  end
145
145
 
146
+ # Runs the provisioning script
147
+ def provision
148
+ Env.load!
149
+ Env.require_persisted_vm
150
+ Env.persisted_vm.execute!(Actions::VM::Provision)
151
+ end
152
+
146
153
  private
147
154
 
148
155
  def act_on_vm(&block)
@@ -86,25 +86,6 @@ module Tenderloin
86
86
  attr_accessor :extension
87
87
  end
88
88
 
89
- class ChefConfig < Base
90
- attr_accessor :cookbooks_path
91
- attr_accessor :provisioning_path
92
- attr_accessor :json
93
- attr_accessor :enabled
94
-
95
- def initialize
96
- @enabled = false
97
- end
98
-
99
- def to_json
100
- # Overridden so that the 'json' key could be removed, since its just
101
- # merged into the config anyways
102
- data = instance_variables_hash
103
- data.delete(:json)
104
- data.to_json
105
- end
106
- end
107
-
108
89
  class TenderloinConfig < Base
109
90
  attr_accessor :dotfile_name
110
91
  attr_accessor :log_output
@@ -115,19 +96,34 @@ module Tenderloin
115
96
  end
116
97
  end
117
98
 
99
+ class ProvisioningConfig
100
+ attr_accessor :script
101
+ attr_accessor :command
102
+ def enabled
103
+ script || command
104
+ end
105
+ end
106
+
107
+ class SharedFoldersConfig
108
+ attr_accessor :enabled
109
+ attr_accessor :folders
110
+ end
111
+
118
112
  class Top < Base
119
113
  attr_reader :package
120
114
  attr_reader :ssh
121
115
  attr_reader :vm
122
- attr_reader :chef
123
116
  attr_reader :tenderloin
117
+ attr_reader :provisioning
118
+ attr_reader :shared_folders
124
119
 
125
120
  def initialize
126
121
  @ssh = SSHConfig.new
127
122
  @vm = VMConfig.new
128
- @chef = ChefConfig.new
129
123
  @tenderloin = TenderloinConfig.new
130
124
  @package = PackageConfig.new
125
+ @provisioning = ProvisioningConfig.new
126
+ @shared_folders = SharedFoldersConfig.new
131
127
 
132
128
  @loaded = false
133
129
  end
@@ -63,6 +63,11 @@ module Tenderloin
63
63
  end
64
64
 
65
65
  def share_folder(name, hostpath)
66
+ # Try and clean up first, to handle path changes.
67
+ begin
68
+ run 'removeSharedFolder', "#{name}"
69
+ rescue
70
+ end
66
71
  run 'addSharedFolder', "#{name} #{hostpath}"
67
72
  end
68
73
 
@@ -18,8 +18,8 @@ module Tenderloin
18
18
  end
19
19
  end
20
20
 
21
- def upload!(from, to)
22
- execute do |ssh|
21
+ def upload!(ip, from, to)
22
+ execute(ip) do |ssh|
23
23
  scp = Net::SCP.new(ssh)
24
24
  scp.upload!(from, to)
25
25
  end
data/templates/Tenderfile CHANGED
@@ -5,4 +5,19 @@ Tenderloin::Config.run do |config|
5
5
 
6
6
  # Every Tenderloin virtual environment requires a box to build off of.
7
7
  config.vm.box = "base"
8
+
9
+ ## SSH username and password defaults to 'tenderloin'. You can change this.
10
+ # config.ssh.username = 'youruser'
11
+ # config.ssh.password = 'yourpass'
12
+
13
+ ## Provisioning can either provide a shell script, or a command to execute
14
+ # config.provisioning.script = <<EOF
15
+ # ls /usr
16
+ # EOF
17
+ # config.provisioning.command = "apt-get install -y ruby"
18
+
19
+ ## Shared folders are enabled by default, and the project dir is always shared
20
+ ## You can turn this off, or add additional folders
21
+ # config.shared_folders.enabled = false
22
+ # config.shared_folders.folders = [[["my-files", "src", "/mnt/src"], ["bin-files", "bin", "/mnt/bin"]
8
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenderloin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: