docker-builder 0.1.55 → 0.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 900f989de3f0c47d40b6494a9e419acd6ca42324
4
- data.tar.gz: 491ee67ea44c3564aed1c1492b9f79198a69f9ef
3
+ metadata.gz: 73d503e285abeee2dde62729f89b3052a5378965
4
+ data.tar.gz: af9eb9163dc809a4046fed5e0b7999af09101583
5
5
  SHA512:
6
- metadata.gz: 9613b5f3f6800d10c304ce9684dba601eab390abf7eec04f33db24893b390910bd2a59b5335dba6940b0e58029dd9cbe0c750923b2fff58e36636daba161d19c
7
- data.tar.gz: 02022477d3b197ab3a17100fecffdda1542db020637af80b7b0d728bbbb86c1e21b0c9a6472f2a9b265876279a93128e28c7ba1a0c98f88e60b29ddb363985e6
6
+ metadata.gz: ccb9c7f00f642fc912baa4930a39f0a85fd096d836e2668ced36750b99edabdfe29d913cdfcbd4a28899e3162ab56cde8b9761d982df1f4e40a323a09cfbe6fd
7
+ data.tar.gz: fb0933c4429834b19dbfbb31b14a30c38e6f7511a6df1ed1338e27f11b007af869ef920362c53589198ff15316427a8b3886a53f21720aa2d3fa9b6b239c7a47
@@ -1,2 +1,2 @@
1
1
  gem build docker-builder.gemspec
2
- gem install ./docker-builder-0.1.54.gem
2
+ gem install ./docker-builder-0.1.57.gem
@@ -65,106 +65,94 @@ module DockerBuilder
65
65
 
66
66
  end
67
67
 
68
- def self._run_bootstrap_script(settings, script)
69
- puts "run BS script #{script}"
70
-
71
- if script['type']=='shell' && script['run_from']=='host'
72
- return _run_bootstrap_script_shell_from_host(settings, script)
73
- elsif script['type']=='shell' && (script['run_from'].nil? || script['run_from']=='')
74
- _run_bootstrap_script_shell_in_container(settings, script)
75
- elsif script['type']=='chef'
76
- # TODO: do it
77
- _run_bootstrap_script_chef(settings, script)
78
- end
79
68
 
80
- return nil
81
- end
82
69
 
83
70
 
84
71
  ### provision - setup
85
72
 
86
73
  def self._run_setup_script(settings, script)
87
74
  puts "run script #{script}"
75
+
88
76
  if script['type']=='shell'
89
- return _run_setup_script_shell_from_host(settings, script)
77
+ return _run_setup_script_on_host_shell(settings, script)
78
+ elsif script['type']=='chef'
79
+ return _run_setup_script_on_host_chef(settings, script)
90
80
  end
91
81
 
92
82
  return nil
93
83
  end
94
84
 
95
- def self._run_setup_script_shell_from_host(settings, script)
85
+ def self._run_setup_script_on_host_shell(settings, script)
96
86
  cmd %Q(cd #{settings.dir_server_root} && #{script['script']} )
97
87
  end
98
88
 
89
+ def self._run_setup_script_on_host_chef(settings, script)
90
+ raise 'NOT implemented'
99
91
 
100
- def self._provision_container_chef_recipe(settings)
101
- puts "provisioning container #{settings.container_name}"
102
-
103
- #cmd %Q(SERVER_NAME=#{settings.name} chef-client -z -N #{settings.name} #{settings.name}/cookbooks/#{settings.name}/ )
104
- end
92
+ # run script on host machine
93
+ script_name = settings['install']['host']['script'] || 'install_host'
105
94
 
95
+ # check script exists
96
+ #script_path = "#{settings.name}/cookbooks/#{settings.name}/recipes/#{script_name}.rb"
97
+ #f = File.expand_path('.', script_path)
106
98
 
99
+ #if !File.exists?(f)
100
+ # puts "script not found: #{f}. Skipping"
101
+ # return false
102
+ #end
107
103
 
108
- ### provision - bootstrap
104
+ #puts "pwd= #{Dir.pwd}"
105
+ #puts "root = #{Config.root_path}"
106
+ #exit
109
107
 
110
- def self._run_bootstrap_script_shell_from_host(settings, script)
111
- cmd %Q(cd #{settings.dir_server_root} && #{script['script']} )
108
+ #
112
109
 
110
+ return true
113
111
  end
114
112
 
115
113
 
116
- def self._run_bootstrap_script_shell_in_container(settings, script)
117
- script_path = script['script']
118
- # exec
119
- cmd %Q(docker exec #{settings.container_name} #{script_path} )
120
- end
121
114
 
122
- =begin
123
- def self._install_container_provision_host(settings)
124
- script_type = (settings['install']['host']['script_type'] rescue nil)
125
- return true unless script_type
126
115
 
127
- # run provision script on the host machine
128
- if script_type=='chef_recipe'
129
- return _install_container_provision_host_chef_recipe(settings)
130
- else
131
- # do nothing
116
+ ### provision - bootstrap
117
+
118
+ def self._run_bootstrap_script(settings, script)
119
+ puts "run BS script #{script}"
120
+
121
+ if script['type']=='shell' && script['run_from']=='host'
122
+ return _run_bootstrap_script_on_host_shell(settings, script)
123
+ elsif script['type']=='shell' && (script['run_from'].nil? || script['run_from']=='')
124
+ _run_bootstrap_script_in_container_shell(settings, script)
125
+ elsif script['type']=='chef'
126
+ _run_bootstrap_script_in_container_chef(settings, script)
127
+ end
128
+
129
+ return nil
132
130
  end
133
131
 
134
- true
135
- end
136
132
 
137
- #
138
- def self._install_container_provision_host_chef_recipe(settings)
139
- # run script on host machine
140
- script_name = settings['install']['host']['script'] || 'install_host'
133
+ def self._run_bootstrap_script_on_host_shell(settings, script)
134
+ cmd %Q(cd #{settings.dir_server_root} && #{script['script']} )
141
135
 
142
- # check script exists
143
- #script_path = "#{settings.name}/cookbooks/#{settings.name}/recipes/#{script_name}.rb"
144
- #f = File.expand_path('.', script_path)
136
+ end
145
137
 
146
- #if !File.exists?(f)
147
- # puts "script not found: #{f}. Skipping"
148
- # return false
149
- #end
150
138
 
151
- #puts "pwd= #{Dir.pwd}"
152
- #puts "root = #{Config.root_path}"
153
- #exit
139
+ def self._run_bootstrap_script_in_container_shell(settings, script)
140
+ script_path = script['script']
154
141
 
155
- #
156
- res_chef = run_chef_recipe_server_recipe(settings, script_name)
157
- #cmd %Q(SERVER_NAME=#{settings.name} chef-client -z -N #{settings.name} --override-runlist 'recipe[#{settings.name}::#{script_name}]' )
142
+ # exec
143
+ cmd %Q(docker exec #{settings.container_name} #{script_path} )
144
+ end
158
145
 
159
- return true
160
- end
146
+ def self._run_bootstrap_script_in_container_chef(settings, script)
147
+ req = DockerBuilder::Provisioner::Chef.new(settings)
148
+ return req.run_recipe_in_container script['dir_base'], script['recipe_name']
149
+ end
161
150
 
162
151
 
163
- =end
164
152
 
165
153
  ### helpers - shell
166
154
 
167
- def self.run_shell_script_in_container(settings, script_name)
155
+ def self.run_script_in_container_shell(settings, script_name)
168
156
  script_path = settings.make_path_full("scripts/#{script_name}")
169
157
 
170
158
  # copy
@@ -176,6 +164,9 @@ def self._install_container_provision_host(settings)
176
164
  end
177
165
 
178
166
 
167
+
168
+
169
+
179
170
  ###
180
171
  def self.cmd(s)
181
172
  Command.cmd(s)
@@ -30,11 +30,10 @@ module DockerBuilder
30
30
  save_config
31
31
 
32
32
  # copy to container
33
- DockerBuilder::Command.cmd %Q(docker cp #{filename_config} #{settings.container_name}:/opt/bootstrap/config.json)
33
+ DockerBuilder::Command.cmd %Q(docker cp #{filename_config} #{settings.container_name}:#{docker_filename_config})
34
34
 
35
35
  end
36
36
 
37
- # helpers
38
37
  def save_config
39
38
  require 'json'
40
39
  filename = filename_config
@@ -50,6 +49,10 @@ module DockerBuilder
50
49
  File.join(Config.root_path, 'temp', "bootstrap-#{settings.name}.json")
51
50
  end
52
51
 
52
+ def docker_filename_config
53
+ "/opt/bootstrap/config.json"
54
+ end
55
+
53
56
  def build_config
54
57
  res = {}
55
58
 
@@ -63,7 +66,25 @@ module DockerBuilder
63
66
 
64
67
 
65
68
  ### run recipes
69
+ def run_recipe_in_container(dir_base, recipe_name)
70
+
71
+ recipe_name ||= "server::bootstrap"
72
+
73
+ # generate config
74
+ copy_config_file
75
+
66
76
 
77
+ #
78
+ q = %Q(cd #{dir_base} && chef-client -z -j #{docker_filename_config} --override-runlist "recipe[#{recipe_name}]" )
79
+
80
+ # exec
81
+ docker_run_cmd q
82
+ end
83
+
84
+ ###
85
+ def docker_run_cmd(s)
86
+ DockerBuilder::Command.cmd %Q(docker exec #{settings.container_name} bash -c '#{s}')
87
+ end
67
88
 
68
89
  end
69
90
  end
@@ -1,3 +1,3 @@
1
1
  module DockerBuilder
2
- VERSION = "0.1.55"
2
+ VERSION = "0.1.57"
3
3
  end
data/readme.md CHANGED
@@ -195,7 +195,7 @@ Process:
195
195
  {
196
196
  'provision'=>{
197
197
  'setup' => [
198
- {type: 'host', ..},
198
+ {type: 'shell', ..},
199
199
  ..
200
200
  ]
201
201
  ...
@@ -357,6 +357,8 @@ docker exec -ti container_name /bin/bash
357
357
 
358
358
  # Provision
359
359
 
360
+
361
+
360
362
  ## Run provision after start
361
363
 
362
364
  ### Run provision from host machine
@@ -375,6 +377,27 @@ Run from outside container
375
377
  it will run script `name=myserver ruby myprovision1.rb` from the host machine.
376
378
 
377
379
 
380
+ ### Provision with Chef
381
+
382
+ * in config file
383
+ ```
384
+ 'provision' => {
385
+ "bootstrap" => [
386
+ {'type' => 'chef', "script"=>"", "dir_base"=>"/opt/bootstrap", "recipe"=>"server::bootstrap" },
387
+ ]
388
+ },
389
+ ```
390
+
391
+ it will run chef provisioning:
392
+ ```
393
+ cd /opt/bootstrap/ && chef-client -z -j /opt/bootstrap/config.json --override-runlist "recipe[server::bootstrap]"
394
+
395
+ ```
396
+
397
+ config file with attributes (`/opt/bootstrap/config.json`) for chef-client is generated automatically.
398
+
399
+
400
+
378
401
  ## Development
379
402
 
380
403
  After checking out the repo, run `bin/setup` to install dependencies.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.55
4
+ version: 0.1.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Ivak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-24 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler