docker-builder 0.1.26 → 0.1.28

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: fb25008d4f2f9e81b4cb3838fa9aaf50836061fe
4
- data.tar.gz: 1a41a6e5f930d7b5904ff0104afabf11e546b776
3
+ metadata.gz: 960492c3b515b4715ff15e100ee08035c57329d1
4
+ data.tar.gz: e7ca4c753cea3e9edd071e903bece0b942063dc1
5
5
  SHA512:
6
- metadata.gz: af7cf7a928edc1de2fe7ea1c2e871c7b1ec2b1fdfa0f139553e8bc14f5c53e8464bb991a8acc69e8f57c17fa9928a3815926ad4cace66f5495197668a0f28f05
7
- data.tar.gz: f0f127dd2eb74cc3dcfd241a45285b1599fd17f4005385bcf17c97201eb89ef6d3a6862712c65304c2f7a73cc4c9cd3c0378c255e4de480aafde073fc711d1f1
6
+ metadata.gz: d6b7a4739370484ccad9bd2aad9bc090e7bd80595e076d5ed84e5dc0760d2e4d49b5f8a3f3d5efd25881f8f9bf5afa4e4a4b1f005b89da3b8f2a7e1e78893bfd
7
+ data.tar.gz: 026fd20d3d2b3781beb1afb2dd3df56456c825f1274f48c7226cf687f91c290b19956f2418f4494f67226f39f648485a67cc46c0328004fd98dac1a8969cc5ca
data/install_local.sh CHANGED
@@ -1,2 +1,2 @@
1
1
  gem build docker-builder.gemspec
2
- gem install ./docker-builder-0.1.26.gem
2
+ gem install ./docker-builder-0.1.27.gem
@@ -56,12 +56,21 @@ module DockerBuilder
56
56
 
57
57
  bi = settings.attributes['build']['base_image']
58
58
  base_image_name = "#{bi['name']}:#{bi['tag']}"
59
- res['builders'] << {
60
- pull: false,
61
- type: "docker",
62
- image: base_image_name,
63
- commit: true
64
- }
59
+ builder1 = {
60
+ pull: false,
61
+ type: "docker",
62
+ image: base_image_name,
63
+ commit: true
64
+ }
65
+
66
+ # changes
67
+ entrypoint = settings.attributes['build']['entrypoint']
68
+ if entrypoint
69
+ builder1['changes'] ||= []
70
+ builder1['changes'] << "ENTRYPOINT #{entrypoint}"
71
+ end
72
+
73
+ res['builders'] << builder1
65
74
 
66
75
  #
67
76
  recipe_name = settings['build']['packer']['recipe_name'] || 'build'
@@ -136,20 +136,34 @@ class Manager
136
136
  def self._run_container(settings)
137
137
  puts "run container ..."
138
138
 
139
- script_type = (settings['install']['node']['script_type'] rescue nil)
139
+ install_node_script_type = (settings['install']['node']['script_type'] rescue nil)
140
+ bootstrap_type = (settings['install']['bootstrap']['type'] rescue nil)
141
+
142
+ #
143
+ create_container(settings)
144
+
145
+ # before start
146
+ if bootstrap_type && bootstrap_type=='chef'
147
+ _bootstrap_container_prepare(settings)
148
+ end
149
+
150
+
151
+ # start
152
+ start_container(settings)
140
153
 
141
- puts "script type: #{script_type}"
142
154
 
155
+ # provision after start
143
156
 
144
- if script_type && script_type=='chef_recipe'
157
+ if install_node_script_type && install_node_script_type=='chef_recipe'
145
158
  # run container and provision with chef
146
- _run_container_chef(settings)
159
+ #_run_container_chef(settings)
147
160
 
148
161
  # ???
149
162
  #_provision_container_chef_recipe(settings)
150
- elsif script_type && script_type=='shell'
163
+
164
+ elsif install_node_script_type && install_node_script_type=='shell'
151
165
  # docker run
152
- create_and_run_container(settings)
166
+ #create_and_run_container(settings)
153
167
 
154
168
  # provision with shell script
155
169
  run_shell_script_in_container(settings, "install.sh")
@@ -159,14 +173,15 @@ class Manager
159
173
  #_run_container_docker(settings)
160
174
 
161
175
  # docker run
162
- create_and_run_container(settings)
176
+ #create_and_run_container(settings)
163
177
 
164
178
  end
165
179
 
180
+
166
181
  true
167
182
  end
168
183
 
169
- def self.create_and_run_container(settings)
184
+ def self.create_container(settings)
170
185
  #cmd %Q(docker run -d --name #{settings.container_name} #{settings.docker_ports_string} #{settings.docker_volumes_string} #{settings.docker_volumes_from_string} #{settings.docker_links_string} #{settings.run_extra_options_string} #{settings.run_env_variables_string} #{settings.image_name} #{settings['docker']['command']} #{settings['docker']['run_options']})
171
186
 
172
187
  # create
@@ -179,10 +194,20 @@ class Manager
179
194
  s_ip = "--ip #{ip}" if ip
180
195
  cmd %Q(docker network connect #{s_ip} #{network2['net']} #{settings.container_name})
181
196
  end
197
+ end
182
198
 
199
+ def self.start_container(settings)
183
200
  # start
184
201
  cmd %Q(docker start #{settings.container_name})
185
202
 
203
+ # setup
204
+ setup_container_after_start(settings)
205
+ end
206
+
207
+ def self.setup_container_after_start(settings)
208
+ # second network
209
+ network2 = settings['docker']['network_secondary']
210
+
186
211
  # fixes
187
212
  if network2
188
213
  gateway = network2['gateway']
@@ -195,10 +220,8 @@ class Manager
195
220
  end
196
221
 
197
222
  # fix hosts
198
- puts "fix hosts"
199
223
  container_hosts = settings['docker']['hosts'] || []
200
224
  container_hosts.each do |r|
201
- puts "fix host #{r[0]} #{r[1]}"
202
225
  #cmd %Q(docker exec #{settings.container_name} bash -c 'echo "#{r[0]} #{r[1]}" >> /etc/hosts')
203
226
  cmd %Q(docker exec #{settings.container_name} sh -c 'echo "#{r[0]} #{r[1]}" >> /etc/hosts')
204
227
  end
@@ -229,6 +252,14 @@ class Manager
229
252
 
230
253
  ### provision
231
254
 
255
+ def self._bootstrap_container_prepare(settings)
256
+ require_relative '../../lib/docker_builder/provisioner/provisioner_chef'
257
+
258
+ provisioner = DockerBuilder::Provisioner::ProvisionerChef.new(settings)
259
+ provisioner.copy_config_file
260
+
261
+ end
262
+
232
263
  def self._provision_container_chef_recipe(settings)
233
264
  puts "provisioning container #{settings.container_name}"
234
265
 
@@ -334,14 +365,6 @@ class Manager
334
365
  end
335
366
 
336
367
 
337
- def self.start_container(server_name)
338
- settings = load_settings(server_name)
339
-
340
- #
341
- cmd %Q(docker start #{settings.container_name} )
342
-
343
- return true
344
- end
345
368
 
346
369
 
347
370
  ### stop container
@@ -0,0 +1,68 @@
1
+ module DockerBuilder
2
+ module Provisioner
3
+ class ProvisionerChef
4
+
5
+ attr_accessor :server
6
+
7
+ def server=(v)
8
+ @server = v
9
+ @server
10
+ end
11
+
12
+ def server
13
+ @server
14
+ end
15
+
16
+ def settings
17
+ server
18
+ end
19
+
20
+
21
+ def initialize(_settings)
22
+ self.server = _settings
23
+
24
+ end
25
+
26
+ ###
27
+
28
+ def copy_config_file
29
+ # config json
30
+ save_config
31
+
32
+ # copy to container
33
+ DockerBuilder::Command.cmd %Q(docker cp #{filename_config} #{settings.container_name}:/opt/bootstrap/config.json)
34
+
35
+ end
36
+
37
+ # helpers
38
+ def save_config
39
+ require 'json'
40
+ filename = filename_config
41
+ FileUtils.mkdir_p(File.dirname(filename))
42
+ File.open(filename,"w+") do |f|
43
+ f.write(build_config.to_json)
44
+ end
45
+
46
+ true
47
+ end
48
+
49
+ def filename_config
50
+ File.join(Config.root_path, 'temp', "bootstrap-#{settings.name}.json")
51
+ end
52
+
53
+ def build_config
54
+ res = {}
55
+
56
+ attr = settings.attributes['attributes']
57
+ res = attr
58
+
59
+ #res = settings.all_attributes
60
+
61
+ res
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+
68
+
@@ -1,3 +1,3 @@
1
1
  module DockerBuilder
2
- VERSION = "0.1.26"
2
+ VERSION = "0.1.28"
3
3
  end
data/readme.md CHANGED
@@ -566,3 +566,21 @@ my-test-redis
566
566
 
567
567
 
568
568
 
569
+
570
+ # Bootstrap
571
+
572
+ * first provision of container
573
+
574
+
575
+ ## Provision with chef
576
+
577
+ docker-builder up -s server_name
578
+
579
+ Process:
580
+ * docker create with docker options
581
+ * entrypoint: /etc/bootstrap
582
+ * generate config with node attributes for chef and save it to temp/boostrap-__server__.json
583
+ * copy config file to container to /opt/bootstrap/config.json
584
+ * docker start
585
+ * when container starts it runs /etc/boostrap which
586
+ * runs chef-client to provision server first time
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.26
4
+ version: 0.1.28
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-01-30 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,6 +152,7 @@ files:
152
152
  - lib/docker_builder/cookbooks/docker-builder/resources/mycontainer.rb
153
153
  - lib/docker_builder/manager.rb
154
154
  - lib/docker_builder/manager_swarm.rb
155
+ - lib/docker_builder/provisioner/provisioner_chef.rb
155
156
  - lib/docker_builder/server_settings.rb
156
157
  - lib/docker_builder/version.rb
157
158
  - lib/templates/example-chef/.chef/knife.rb