docker-builder 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/CODE_OF_CONDUCT.md +49 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/Rakefile +140 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/docker-builder.gemspec +36 -0
  10. data/examples/example-apps-php/.chef/knife.rb +6 -0
  11. data/examples/example-apps-php/config.rb +19 -0
  12. data/examples/example-apps-php/servers/apps-php/.chef/knife.rb +2 -0
  13. data/examples/example-apps-php/servers/apps-php/config.rb +69 -0
  14. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/README.md +1 -0
  15. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/metadata.rb +9 -0
  16. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/recipes/build.rb +43 -0
  17. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/recipes/install.rb +55 -0
  18. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/recipes/install_app.rb +27 -0
  19. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/recipes/install_host.rb +9 -0
  20. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/templates/index.html.erb +4 -0
  21. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/templates/nginx-sites/app.conf.erb +55 -0
  22. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/templates/nginx-sites/app.conf.erb.1 +55 -0
  23. data/examples/example-apps-php/servers/apps-php/cookbooks/apps-php/templates/nginx-sites/default.conf.erb +45 -0
  24. data/examples/example-apps-php/servers/apps-php/readme.md +0 -0
  25. data/examples/example-nginx/config.rb +19 -0
  26. data/examples/example-nginx/servers/nginx/.chef/knife.rb +8 -0
  27. data/examples/example-nginx/servers/nginx/config.rb +54 -0
  28. data/examples/example-nginx/servers/nginx/cookbooks/nginx/README.md +1 -0
  29. data/examples/example-nginx/servers/nginx/cookbooks/nginx/metadata.rb +9 -0
  30. data/examples/example-nginx/servers/nginx/cookbooks/nginx/recipes/build.rb +10 -0
  31. data/examples/example-nginx/servers/nginx/cookbooks/nginx/recipes/install.rb +28 -0
  32. data/examples/example-nginx/servers/nginx/cookbooks/nginx/recipes/install_host.rb +9 -0
  33. data/examples/example-nginx/servers/nginx/cookbooks/nginx/templates/index.html.erb +4 -0
  34. data/examples/example-nginx/servers/nginx/cookbooks/nginx/templates/nginx-sites/default.conf.erb +45 -0
  35. data/examples/example-nginx/servers/nginx/readme.md +0 -0
  36. data/examples/example-nginx/temp/ex_nginx.json +20 -0
  37. data/examples/example-nginx/temp/nginx.json +1 -0
  38. data/exe/docker-builder +20 -0
  39. data/install_local.sh +2 -0
  40. data/lib/docker_builder.rb +18 -0
  41. data/lib/docker_builder/chef/.chef/knife.rb +115 -0
  42. data/lib/docker_builder/chef/chef_build_image.copy0.rb +60 -0
  43. data/lib/docker_builder/chef/chef_destroy_image.copy0.rb +35 -0
  44. data/lib/docker_builder/cli.rb +346 -0
  45. data/lib/docker_builder/config.rb +199 -0
  46. data/lib/docker_builder/config/dsl.rb +48 -0
  47. data/lib/docker_builder/config/helpers.rb +99 -0
  48. data/lib/docker_builder/manager.rb +364 -0
  49. data/lib/docker_builder/server_settings.rb +286 -0
  50. data/lib/docker_builder/version.rb +3 -0
  51. data/lib/templates/example-chef/config.rb.erb +18 -0
  52. data/lib/templates/example-chef/servers/server1/.chef/knife.rb +8 -0
  53. data/lib/templates/example-chef/servers/server1/config.rb.erb +54 -0
  54. data/lib/templates/example-chef/servers/server1/cookbooks/server1/README.md +1 -0
  55. data/lib/templates/example-chef/servers/server1/cookbooks/server1/metadata.rb.erb +8 -0
  56. data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/build.rb +10 -0
  57. data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/install.rb +36 -0
  58. data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/install_host.rb +9 -0
  59. data/lib/templates/example-chef/servers/server1/cookbooks/server1/templates/index.html.erb +5 -0
  60. data/lib/templates/example-chef/servers/server1/cookbooks/server1/templates/nginx-sites/default.conf.erb +45 -0
  61. data/readme.md +233 -0
  62. data/readme_developers.md +54 -0
  63. data/temp.sh +21 -0
  64. data/temp/app-php.json +1 -0
  65. data/temp/build.sh +29 -0
  66. data/temp/chef_build_image.rb +37 -0
  67. data/temp/chef_destroy_image.rb +16 -0
  68. data/temp/cookbooks/temp1/README.md +1 -0
  69. data/temp/cookbooks/temp1/metadata.rb +9 -0
  70. data/temp/cookbooks/temp1/recipes/build.rb +42 -0
  71. data/temp/run.sh +2 -0
  72. metadata +157 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c7402bf36321129a23e0de870efa54e445c3876
4
+ data.tar.gz: cfeaa7e2a406d013dc88513079ab5d39775b29ba
5
+ SHA512:
6
+ metadata.gz: dd608f385811340691f81e0366751bcf9a832507caa68a9549d94eb12366c6d5321d6204b65146b22c959565d8c1a81ca957b423c79d4e0caf24d6bea91e72d1
7
+ data.tar.gz: f17bb38bed31308d94a9536063260a7a6b370a327f8c8d100ebb63c01ebfb5794687b49b548e4c0349e5a60b6b1b4a17571845b758580f1d981554749484d835
@@ -0,0 +1,11 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ log/*.log
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at max.ivak@galacticexchange.io. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docker-builder.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Max Ivak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,140 @@
1
+ require "bundler/gem_tasks"
2
+ #task :default => :spec
3
+
4
+ # global
5
+ SERVERS = %w(redis mysql elasticsearch phpmyadmin phpredisadmin apps-ruby nginx-front )
6
+
7
+
8
+ #
9
+ require_relative 'lib/docker_builder/server_settings'
10
+ require_relative 'lib/docker_builder/manager'
11
+
12
+
13
+
14
+ #
15
+ desc "Build image"
16
+ task :build, [:name] do |task, args|
17
+ #name = args[:name]
18
+ Manager.build_image(name)
19
+ #sh "sh build_#{name}.sh"
20
+ end
21
+
22
+ desc "Destroy image"
23
+ task :destroy_image, [:name] do |task, args|
24
+ name = args[:name]
25
+ Manager.destroy_image(name)
26
+ end
27
+
28
+
29
+ desc "Rebuild image. Destroy image and build again."
30
+ task :rebuild, [:name] do |task, args|
31
+ s = args[:name]
32
+ Rake::Task[:destroy_image].invoke(s)
33
+ Rake::Task[:build].invoke(s)
34
+ end
35
+
36
+
37
+
38
+
39
+ desc "Run container"
40
+ task :run, [:name] do |task, args|
41
+ name = args[:name]
42
+ Manager.run_container(name)
43
+ end
44
+
45
+
46
+ desc "Start container"
47
+ task :start, [:name] do |task, args|
48
+ name = args[:name]
49
+ Manager.start_container(name)
50
+ end
51
+
52
+ desc "Restart container"
53
+ task :restart, [:name] do |task, args|
54
+ puts "restart #{args[:name]}"
55
+ name = 'my-'+args[:name]
56
+ sh "docker restart #{name}"
57
+ end
58
+
59
+
60
+ desc "Destroy container"
61
+ task :destroy, [:name] do |task, args|
62
+ Manager.destroy_container(args[:name])
63
+ end
64
+
65
+ =begin
66
+ desc "Destroy container with Chef"
67
+ task :destroy_chef, [:name] do |task, args|
68
+ name = "my-"+args[:name]
69
+ sh "cd server-#{args[:name]} && chef-client -z -j config/config.json destroy.rb" rescue nil
70
+
71
+ sh "docker rm -f #{name}" rescue nil
72
+ sh "docker rm -f chef-converge.#{name}" rescue nil
73
+ end
74
+ =end
75
+
76
+
77
+ desc "Remove and run container"
78
+ task :rerun, [:name] do |task, args|
79
+ s = args[:name]
80
+ Rake::Task[:destroy].invoke(s)
81
+ Rake::Task[:run].invoke(s)
82
+ end
83
+
84
+
85
+ desc "Rebuild image and rerun container"
86
+ task :rerun_rebuild, [:name] do |task, args|
87
+ s = args[:name]
88
+ #
89
+ Rake::Task[:destroy].invoke(s)
90
+ Rake::Task[:destroy_image].invoke(s)
91
+
92
+ #
93
+ Rake::Task[:build].invoke(s)
94
+ Rake::Task[:run].invoke(s)
95
+ end
96
+
97
+ # Build all
98
+ desc "Build all images"
99
+ task :build_all do |task, args|
100
+ SERVERS.each do |s|
101
+ Rake::Task["build"].invoke(s)
102
+ end
103
+ end
104
+
105
+
106
+
107
+
108
+ desc 'Run all'
109
+ task :run_all do |task, args|
110
+ SERVERS.each do |s|
111
+ Rake::Task["run"].invoke(s)
112
+ end
113
+
114
+ end
115
+
116
+
117
+ desc 'Start all'
118
+ task :start_all do
119
+ SERVERS.each do |s|
120
+ puts "task start #{s}"
121
+ Rake::Task[:start].invoke(s)
122
+ Rake::Task[:start].reenable
123
+ end
124
+ end
125
+
126
+
127
+ desc 'Restart all'
128
+ task :restart_all do
129
+ SERVERS.each do |s|
130
+ Rake::Task[:restart].invoke(s)
131
+ Rake::Task[:restart].reenable
132
+ end
133
+ end
134
+
135
+
136
+ desc 'Exec task, run_test[name,recipe_name]'
137
+ task :exec, [:name, :recipe_name] do |task, args|
138
+ Manager.exec_task(args[:name], args[:recipe_name])
139
+
140
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "docker_builder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docker_builder/version'
5
+ #require File.expand_path('lib/docker_builder/version')
6
+
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "docker-builder"
10
+ spec.version = DockerBuilder::VERSION
11
+ spec.authors = ["Max Ivak"]
12
+ spec.email = ["max.ivak@galacticexchange.io"]
13
+
14
+ spec.summary = 'Docker builder'
15
+ spec.description = "Build Docker containers with Chef, Dockerfile and other tools"
16
+ spec.homepage = "https://github.com/maxivak/docker-builder"
17
+ spec.license = "MIT"
18
+
19
+
20
+
21
+ #spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+
30
+ #s.add_dependency 'httparty'
31
+ #s.add_dependency 'json'
32
+
33
+
34
+ #spec.add_dependency 'ostruct'
35
+ spec.add_dependency 'thor'
36
+ end
@@ -0,0 +1,6 @@
1
+ puts "cookbooks from server: #{cookbook_path}"
2
+
3
+ cookbook_path cookbook_path+[
4
+ '/work/chef-repo/cookbooks-common',
5
+ '/work/chef-repo/cookbooks',
6
+ ]
@@ -0,0 +1,19 @@
1
+ common({
2
+ 'prefix' => "example-",
3
+ 'image_prefix' => 'example-',
4
+ 'dir_data' => '/disk3/data/my-examples/',
5
+
6
+ })
7
+
8
+ servers({
9
+
10
+ 'apps-php'=>{
11
+ # some server options here
12
+ }
13
+
14
+ })
15
+
16
+
17
+ base({
18
+
19
+ })
@@ -0,0 +1,69 @@
1
+
2
+ add 'build', {
3
+ "image_name" => "apps-php",
4
+ 'build_type' => 'chef',
5
+
6
+ "base_image" => {
7
+ "name" => "my-nginx-php",
8
+ "repository" => "my-nginx-php",
9
+ "tag" => "latest"
10
+
11
+ },
12
+
13
+ }
14
+
15
+ add 'install', {
16
+ "host" => {
17
+ 'script_type' => 'chef_recipe',
18
+ 'script' => 'install_host',
19
+ },
20
+ "node" => {
21
+ 'script_type' => 'chef_recipe',
22
+ 'script' => 'install',
23
+ }
24
+
25
+
26
+ }
27
+
28
+
29
+ add 'docker', {
30
+ 'command' => "/sbin/my_init",
31
+ #"command"=> "",
32
+ 'ports' => [
33
+ [8080,80],
34
+ ],
35
+ 'volumes' => [
36
+ #['html', '/usr/share/nginx/html'],
37
+ ['html', '/var/www/html'],
38
+ #['app', '/usr/share/nginx/html/app'],
39
+ ['log/nginx', '/var/log/nginx/'],
40
+ ],
41
+ 'links' => [
42
+ ]
43
+ }
44
+
45
+
46
+
47
+ add 'attributes', {
48
+ 'nginx' =>{
49
+ "sitename" =>"mysite.local"
50
+ },
51
+ 'apps' =>{
52
+ 'app1'=>{
53
+ 'app_name' => 'app1',
54
+ 'app_env' => 'production',
55
+ 'app_domain' => 'app1.mmx.gex',
56
+ 'app_domain_aliases' => ['app1.mmx.local'],
57
+ },
58
+ 'app2'=>{
59
+ 'app_name' => 'app2',
60
+ 'app_env' => 'production',
61
+ 'app_domain' => 'app2.mmx.gex',
62
+ 'app_domain_aliases' => ['app2.mmx.local'],
63
+ }
64
+ }
65
+
66
+
67
+ }
68
+
69
+
@@ -0,0 +1,9 @@
1
+ name 'apps-php'
2
+ maintainer 'YOUR_COMPANY_NAME'
3
+ maintainer_email 'YOUR_EMAIL'
4
+ license 'All rights reserved'
5
+ description 'Nginx server with PHP applications'
6
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7
+ version '0.1.0'
8
+
9
+ #depends "apt"
@@ -0,0 +1,43 @@
1
+ # will be added to Docker image
2
+
3
+ #
4
+ ['/var/www/html', 'var/www/temp'].each do |d|
5
+ directory d do
6
+ recursive true
7
+ action :create
8
+ end
9
+
10
+ end
11
+
12
+
13
+ #
14
+
15
+
16
+
17
+ execute 'who' do
18
+ command 'echo $(whoami) > /tmp/1.txt'
19
+ end
20
+
21
+ =begin
22
+ #include_recipe 'apt'
23
+ execute 'apt-get update' do
24
+ command 'apt-get update'
25
+ end
26
+
27
+ ['git'].each do |p|
28
+ apt_package p
29
+ end
30
+ =end
31
+
32
+ =begin
33
+ # clean
34
+ execute 'apt-get clean' do
35
+ command 'apt-get clean'
36
+ end
37
+
38
+ execute 'remove temp' do
39
+ command 'rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*'
40
+ end
41
+
42
+
43
+ =end