docker-builder 0.1.8 → 0.1.11

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: 412cb451008bc9ef839d29b6abf7cf5f9cc93cd0
4
- data.tar.gz: a9c7a804eaeb5687ecbce90ae2d95a722960f0b1
3
+ metadata.gz: 85407e9452d3d1583bfc843e049e685916c2ff4a
4
+ data.tar.gz: 32eb773b8de175a3eaaf18103ab362f85ac4cc9d
5
5
  SHA512:
6
- metadata.gz: a3e664c540327c97127f2539bf0312002102230cbb9af8d5fde5a8f626c174e4aeea22461d155277e871b02806fd50430cef4faa2ea19d256fdea95d3751b19e
7
- data.tar.gz: caf998c7941bc0e8c8bff504f4bfa3c57f0b2c11bd3eaea4346efddad9fbbff62c5a6a7843b20b69beb7a89cb171fdf14bf91f75947a8910f52a138be1a1362c
6
+ metadata.gz: aba259c631e9de324450d780b5d3b4ed6c440e03ec7cc9d4f9e8a9f8a06407a2c14e5f40b21eb5f8e999ea3a9da542d08ffcb63cc1edcaf5aaef9cd7d42eb1cb
7
+ data.tar.gz: db0a3b37091c2ff3421df6a139e655f72b308802d4c533df5b969d9d9df7200a069997ee72f91297deaadce679cdb42f928d8fee6fc0c7a5df88ac40d59a9813
@@ -18,8 +18,9 @@ add 'install', {
18
18
  'script' => 'install_host',
19
19
  },
20
20
  "node" => {
21
- 'script_type' => 'chef_recipe',
22
- 'script' => 'install',
21
+ #'script_type' => 'chef_recipe',
22
+ 'script_type' => 'shell',
23
+ #'script' => 'install',
23
24
  }
24
25
 
25
26
 
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ echo '1' > /tmp/1.txt
@@ -40,7 +40,7 @@ class CLI < Thor
40
40
  puts "building..."
41
41
 
42
42
  opts = options
43
- #puts "opt from command line: #{options.inspect}"
43
+ puts "opt from command line: #{options.inspect}"
44
44
 
45
45
 
46
46
  warnings = false
@@ -56,7 +56,7 @@ class CLI < Thor
56
56
  #exit
57
57
 
58
58
  Config.servers.each do |name, opts|
59
- server_settings = Settings.load_settings_for_server(name, opts)
59
+ server_settings = Settings.load_settings_for_server(name)
60
60
 
61
61
  #puts "s: #{server_settings.inspect}"
62
62
  #exit
@@ -135,7 +135,7 @@ class CLI < Thor
135
135
  puts "config: #{Config.inspect}"
136
136
 
137
137
  Config.servers.each do |name, opts|
138
- server_settings = Settings.load_settings_for_server(name, opts)
138
+ server_settings = Settings.load_settings_for_server(name)
139
139
 
140
140
  puts "s: #{server_settings.inspect}"
141
141
  exit
@@ -198,7 +198,7 @@ class CLI < Thor
198
198
  Config.load(options)
199
199
 
200
200
  Config.servers.each do |name, opts|
201
- server_settings = Settings.load_settings_for_server(name, opts)
201
+ server_settings = Settings.load_settings_for_server(name)
202
202
 
203
203
  Manager.destroy_container(name, server_settings)
204
204
  Manager.run_container(name, server_settings)
@@ -258,7 +258,7 @@ class CLI < Thor
258
258
  Config.load(options)
259
259
 
260
260
  Config.servers.each do |name, opts|
261
- server_settings = Settings.load_settings_for_server(name, opts)
261
+ server_settings = Settings.load_settings_for_server(name)
262
262
 
263
263
  Manager.destroy_container(name, server_settings)
264
264
  end
@@ -274,6 +274,65 @@ class CLI < Thor
274
274
  end
275
275
 
276
276
 
277
+
278
+
279
+ ##
280
+ # [stop]
281
+ #
282
+ #
283
+ desc 'stop', 'Stop Docker container(s)'
284
+
285
+ long_desc <<-EOS.gsub(/^ +/, '')
286
+ Stop containers.
287
+ EOS
288
+
289
+ method_option :server,
290
+ :aliases => ['-s', '--server'],
291
+ :required => false,
292
+ :type => :string,
293
+ :desc => "Server name"
294
+
295
+ method_option :root_path,
296
+ :aliases => '-r',
297
+ :type => :string,
298
+ :default => '',
299
+ :desc => 'Root path to base all relative path on.'
300
+
301
+ method_option :config_file,
302
+ :aliases => '-c',
303
+ :type => :string,
304
+ :default => '',
305
+ :desc => 'Path to your config.rb file.'
306
+
307
+ def stop
308
+ puts "stopping..."
309
+
310
+ opts = options
311
+
312
+ warnings = false
313
+ errors = false
314
+
315
+
316
+ servers = nil
317
+ begin
318
+ Config.load(options)
319
+
320
+ Config.servers.each do |name, opts|
321
+ server_settings = Settings.load_settings_for_server(name)
322
+
323
+ Manager.stop_container(name, server_settings)
324
+ end
325
+
326
+ rescue Exception => err
327
+ puts "exception: #{err.inspect}"
328
+ raise err
329
+ exit(3)
330
+ end
331
+
332
+ exit(errors ? 2 : 1) if errors || warnings
333
+
334
+ end
335
+
277
336
  ### generators
278
337
 
279
338
  ##
@@ -36,8 +36,11 @@ module DockerBuilder
36
36
 
37
37
  # Loads the user's +config.rb+ and all model files.
38
38
  def load(opts = {})
39
+ puts "update opts from #{opts}"
39
40
  update(opts) # from the command line
40
41
 
42
+ puts "config file: #{config_file}"
43
+
41
44
  unless File.exist?(config_file)
42
45
  #raise Error, "Could not find configuration file: '#{config_file}'."
43
46
  raise "Could not find configuration file: '#{config_file}'."
@@ -132,8 +135,17 @@ module DockerBuilder
132
135
 
133
136
  # options
134
137
  opts.each do |name, v|
138
+ #puts "set var #{name} == #{v}"
135
139
  set_variable(name, v)
136
140
  end
141
+
142
+ # config file
143
+ set_path_variable("config_file", options['config_file'], DEFAULTS['config_file'], new_root)
144
+
145
+
146
+
147
+
148
+ puts "config == #{config_file}"
137
149
  end
138
150
 
139
151
  # Sets the @root_path to the given +path+ and returns it.
@@ -132,7 +132,15 @@ class Manager
132
132
 
133
133
  # ???
134
134
  #_provision_container_chef_recipe(settings)
135
+ elsif script_type && script_type=='shell'
136
+ # docker run
137
+ 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']})
138
+
139
+ # provision with shell script
140
+ run_shell_script_in_container(settings, "install.sh")
141
+
135
142
  else
143
+ # no script for provision
136
144
  #_run_container_docker(settings)
137
145
 
138
146
  # docker run
@@ -293,6 +301,20 @@ class Manager
293
301
  return true
294
302
  end
295
303
 
304
+
305
+ ### stop container
306
+
307
+ def self.stop_container(server_name, settings)
308
+ puts "stopping container #{server_name}..."
309
+
310
+ #
311
+ cmd %Q(docker stop #{settings.container_name} )
312
+
313
+ #
314
+ return true
315
+ end
316
+
317
+
296
318
  ### run task on running container
297
319
  def self.exec_task(server_name, recipe_name)
298
320
  #raise 'not implemented'
@@ -330,14 +352,28 @@ class Manager
330
352
  end
331
353
 
332
354
 
355
+ ### helpers - shell
356
+
357
+ def self.run_shell_script_in_container(settings, script_name)
358
+ script_path = settings.make_path_full("scripts/#{script_name}")
359
+
360
+ # copy
361
+ cmd %Q(cd #{Config.root_path} && docker cp #{script_path} #{settings.container_name}:/tmp/#{script_name} )
362
+
363
+ # exec
364
+ cmd %Q(docker exec #{settings.container_name} chmod +x /tmp/#{script_name} )
365
+ cmd %Q(docker exec #{settings.container_name} /tmp/#{script_name} )
366
+ end
367
+
368
+
333
369
  ### helpers - chef
334
370
 
335
371
  def self.run_chef_recipe(settings, recipe_rb)
336
- cmd %Q(cd #{Config.root_path} && SERVER_NAME=#{settings.name} SERVER_PATH=#{settings.dir_server_root} chef exec chef-client -z -N #{settings.image_name} -j #{settings.filename_config_json} -c #{chef_config_knife_path} #{chef_recipe_path(recipe_rb)} )
372
+ cmd %Q(cd #{Config.root_path} && SERVER_NAME=#{settings.name} SERVER_PATH=#{settings.dir_server_root} chef exec chef-client -z -N #{settings.container_name} -j #{settings.filename_config_json} -c #{chef_config_knife_path} #{chef_recipe_path(recipe_rb)} )
337
373
  end
338
374
 
339
375
  def self.run_chef_recipe_server_recipe(settings, server_recipe)
340
- cmd %Q(cd #{Config.root_path} && SERVER_NAME=#{settings.name} SERVER_PATH=#{settings.dir_server_root} chef exec chef-client -z -N #{settings.image_name} -c #{chef_config_knife_path} --override-runlist 'recipe[#{settings.name}::#{server_recipe}]' )
376
+ cmd %Q(cd #{Config.root_path} && SERVER_NAME=#{settings.name} SERVER_PATH=#{settings.dir_server_root} chef exec chef-client -z -N #{settings.container_name} -c #{chef_config_knife_path} --override-runlist 'recipe[#{settings.name}::#{server_recipe}]' )
341
377
  end
342
378
 
343
379
 
@@ -250,6 +250,11 @@ class ServerSettings
250
250
  File.expand_path("clients/#{image_name}.json", dir_server_root)
251
251
  end
252
252
 
253
+ ###
254
+
255
+ def make_path_full(path)
256
+ File.expand_path("#{path}", dir_server_root)
257
+ end
253
258
 
254
259
  end
255
260
 
@@ -1,3 +1,3 @@
1
1
  module DockerBuilder
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.11"
3
3
  end
data/readme.md CHANGED
@@ -1,32 +1,115 @@
1
1
  # Docker builder
2
2
 
3
- Tool to build and install Docker containers with Chef, Dockerfile and other tools.
3
+ Tool to build and install Docker containers with Chef, Dockerfile and other provisioning tools.
4
4
 
5
- Config files are in Ruby.
5
+ Features:
6
+ * Config files are in Ruby.
7
+ * Manage complexity of running Docker containers for your environment in one place.
8
+ * Manage multiple containers
6
9
 
7
- Manage complexity of running Docker containers for your environment in one place.
8
10
 
11
+ Other tools:
12
+ * docker-composer - with configs in yml
9
13
 
10
- # Basic usage
11
14
 
12
- ## Server with Chef provisioning
15
+
16
+ # Overview
17
+
18
+
19
+ Build Docker image:
20
+ * from Dockerfile
21
+ * Chef provisioning (machine_image)
22
+
23
+ Provision during installation container on the host machine by:
24
+ * running shell script inside container
25
+ * running Chef script inside container with Chef provisioning
26
+
27
+
28
+
29
+
30
+ # Quickstart
31
+
32
+ We will build and run a simple Docker container with Nginx server.
33
+
34
+ * install gem
35
+
36
+ ```
37
+ gem install docker-builder
38
+ ```
39
+
13
40
 
14
41
  * generate directory structure using generator
42
+
15
43
  ```
16
44
  docker-builder generate --name=nginx --type=chef
17
45
  ```
18
46
 
19
- it will create a folder `nginx`
47
+ it will create a folder `nginx` with necessary directory structure inside.
48
+
20
49
 
21
50
  * in the folder edit config file `config.rb` with common settings
22
51
 
23
52
  ```
53
+ common({
54
+ 'prefix' => "example-",
55
+ 'image_prefix' => 'example-',
56
+ 'dir_data' => '/disk3/data/my-examples/',
57
+
58
+ })
59
+
60
+ servers({
61
+ 'nginx'=>{
62
+ # some server options here
63
+ },
64
+
65
+
66
+ })
67
+
68
+
69
+ base({
70
+
71
+ })
72
+
24
73
 
25
74
  ```
26
75
 
27
76
  * edit custom settings for the server in file `servers/nginx/config.rb`
28
77
 
29
78
  ```
79
+
80
+ add 'build', {
81
+ "image_name" => "nginx",
82
+ 'build_type' => 'chef',
83
+ "base_image" => { "name" => "nginx", "repository" => "nginx", "tag" => "1.10" },
84
+
85
+ }
86
+
87
+ add 'install', {
88
+ "host" => { 'script_type' => 'chef_recipe', 'script' => 'install_host', },
89
+ "node" => { 'script_type' => 'chef_recipe', 'script' => 'install', }
90
+ }
91
+
92
+ add 'docker', {
93
+ "command"=> "nginx -g 'daemon off;'",
94
+ 'ports' => [
95
+ [8080,80],
96
+ ],
97
+ 'volumes' => [
98
+ ['html', '/usr/share/nginx/html'],
99
+ ['log/nginx', '/var/log/nginx/'],
100
+ ],
101
+ 'links' => [ ]
102
+ }
103
+
104
+ add 'attributes', {
105
+ 'nginx' =>{
106
+ "sitename" =>"mysite.local"
107
+ },
108
+
109
+
110
+ }
111
+
112
+
30
113
  ```
31
114
 
32
115
  * build Docker image
@@ -46,6 +129,14 @@ docker-builder up
46
129
  * check container is running
47
130
  ```
48
131
  docker ps
132
+
133
+ # see container named example-nginx
134
+ ```
135
+
136
+ * access container
137
+
138
+ ```
139
+ docker exec -ti example-nginx /bin/bash
49
140
  ```
50
141
 
51
142
  * access container from browser
@@ -56,7 +147,17 @@ http://localhost:8080
56
147
 
57
148
 
58
149
 
59
- # Overview
150
+
151
+
152
+
153
+ # Basic usage
154
+
155
+ # Provision wich shell script
156
+
157
+ * put scripts in `/path/to/project/ <<server_name>> / scripts / install.sh`
158
+
159
+
160
+ # Provisioning with Chef
60
161
 
61
162
  Process of building and running container on the host machine:
62
163
  * Build Docker image
@@ -78,22 +179,59 @@ Process of building and running container on the host machine:
78
179
  * Destroy image
79
180
 
80
181
 
182
+ ## Install server with Chef provisioning
183
+
184
+ * generate directory structure using generator
185
+ ```
186
+ docker-builder generate --name=nginx --type=chef
187
+ ```
81
188
 
82
- # Installation
189
+ it will create a folder `nginx`
190
+
191
+ * in the folder edit config file `config.rb` with common settings
192
+
193
+ ```
194
+
195
+ ```
196
+
197
+ * edit custom settings for the server in file `servers/nginx/config.rb`
198
+
199
+ ```
200
+ ```
201
+
202
+ * build Docker image
203
+
204
+ ```
205
+ # from the folder with project
206
+
207
+ docker-builder build
208
+ ```
83
209
 
84
- Add this line to your application's Gemfile:
210
+ * run container
85
211
 
86
- ```ruby
87
- gem 'docker-builder'
212
+ ```
213
+ docker-builder up
88
214
  ```
89
215
 
90
- And then execute:
216
+ * check container is running
217
+ ```
218
+ docker ps
219
+ ```
91
220
 
92
- $ bundle
221
+ * access container from browser
93
222
 
94
- Or install it yourself as:
223
+ ```
224
+ http://localhost:8080
225
+ ```
95
226
 
96
- $ gem install docker-builder
227
+
228
+ # Installation
229
+
230
+
231
+ Install gem:
232
+ ```
233
+ $ gem install docker-builder
234
+ ```
97
235
 
98
236
 
99
237
 
@@ -175,7 +313,7 @@ in folder with servers:
175
313
 
176
314
  cookbook_path cookbook_path+[
177
315
  '/path/to/my/cookbooks',
178
- '/path/to/my//other/cookbooks',
316
+ '/path/to/my/other/cookbooks',
179
317
  ]
180
318
 
181
319
  ```
@@ -254,3 +392,24 @@ data for nginx server:
254
392
  * packer - https://github.com/mitchellh/packer
255
393
 
256
394
  Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
395
+
396
+
397
+
398
+ # Docker options for running container
399
+
400
+ * additional options for docker run command
401
+ * hostname
402
+
403
+ ```
404
+ {
405
+ ..
406
+ servers({
407
+ 'zookeeper'=>{
408
+ ...
409
+ 'docker'=> {
410
+ ...
411
+ 'run_extra_options'=>'--hostname zookeeper'
412
+ }
413
+ }
414
+ ```
415
+
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.8
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Ivak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-29 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,6 +67,7 @@ files:
67
67
  - Rakefile
68
68
  - bin/console
69
69
  - bin/setup
70
+ - bootstrap_local.sh
70
71
  - docker-builder.gemspec
71
72
  - examples/example-apps-php/.chef/knife.rb
72
73
  - examples/example-apps-php/config.rb
@@ -103,13 +104,13 @@ files:
103
104
  - examples/example-nginx/servers/nginx/cookbooks/nginx/templates/index.html.erb
104
105
  - examples/example-nginx/servers/nginx/cookbooks/nginx/templates/nginx-sites/default.conf.erb
105
106
  - examples/example-nginx/servers/nginx/readme.md
107
+ - examples/example-nginx/servers/nginx/scripts/install.sh
106
108
  - examples/example-nginx/temp/ex_nginx.json
107
109
  - examples/example-nginx/temp/nginx.json
108
110
  - exe/docker-builder
109
111
  - install_local.sh
110
112
  - lib/docker_builder.rb
111
113
  - lib/docker_builder/chef/.chef/knife.rb
112
- - lib/docker_builder/chef/bootstrap_local.sh
113
114
  - lib/docker_builder/chef/chef_build_image.copy0.rb
114
115
  - lib/docker_builder/chef/chef_build_image.rb
115
116
  - lib/docker_builder/chef/chef_destroy_container.rb