docker-app 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-app.gemspec +36 -0
- data/exe/docker-app +20 -0
- data/lib/docker_app.rb +23 -0
- data/lib/docker_app/builder/packer.rb +105 -0
- data/lib/docker_app/chef/.chef/knife.rb +118 -0
- data/lib/docker_app/chef/chef_build_image.rb +55 -0
- data/lib/docker_app/chef/chef_destroy_container.rb +13 -0
- data/lib/docker_app/chef/chef_destroy_image.rb +17 -0
- data/lib/docker_app/chef/chef_exec_container.rb +16 -0
- data/lib/docker_app/chef/chef_run_container.rb +64 -0
- data/lib/docker_app/chef/install_container_service.rb +14 -0
- data/lib/docker_app/cli.rb +502 -0
- data/lib/docker_app/command.rb +16 -0
- data/lib/docker_app/config.rb +249 -0
- data/lib/docker_app/config/dsl.rb +64 -0
- data/lib/docker_app/config/helpers.rb +99 -0
- data/lib/docker_app/manager_container.rb +376 -0
- data/lib/docker_app/manager_image.rb +119 -0
- data/lib/docker_app/manager_swarm.rb +66 -0
- data/lib/docker_app/provisioner/base.rb +179 -0
- data/lib/docker_app/provisioner/chef.rb +93 -0
- data/lib/docker_app/server_settings.rb +361 -0
- data/lib/docker_app/version.rb +3 -0
- data/lib/templates/example-chef/.chef/knife.rb +5 -0
- data/lib/templates/example-chef/config.rb.erb +18 -0
- data/lib/templates/example-chef/servers/server1/.chef/knife.rb +8 -0
- data/lib/templates/example-chef/servers/server1/config.rb.erb +54 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/README.md +1 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/metadata.rb.erb +8 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/build.rb +10 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/install.rb +36 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/recipes/install_host.rb +9 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/templates/index.html.erb +5 -0
- data/lib/templates/example-chef/servers/server1/cookbooks/server1/templates/nginx-sites/default.conf.erb +45 -0
- data/readme.md +853 -0
- data/readme_developers.md +54 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b94ddc0babcbbed29c5565edfe0381e573cc8aa1
|
4
|
+
data.tar.gz: 403e6ec1bfc0ba1f9e31a20bc1beba17c831188e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd355705b85e9d50a2de278d64e631a2eb41bf8b9ff27f639c9acbdf4955af101364f83ecf5fbc99276c3341bc5183b751fdce04ea079e840e9286491ad78a50
|
7
|
+
data.tar.gz: 4b61d2d2c3741ca33fe1142680552685bc8e3c9881c5d583fa29de799be3a877b3e84b30fbee9fea2618688ef10391cacb63c09006fd2f92a5f416126f8095c8
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/LICENSE.txt
ADDED
@@ -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.
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "docker_app"
|
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
|
data/bin/setup
ADDED
data/docker-app.gemspec
ADDED
@@ -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_app/version'
|
5
|
+
#require File.expand_path('lib/docker_app/version')
|
6
|
+
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "docker-app"
|
10
|
+
spec.version = DockerApp::VERSION
|
11
|
+
spec.authors = ["Max Ivak"]
|
12
|
+
spec.email = ["max.ivak@gmail.com"]
|
13
|
+
|
14
|
+
spec.summary = 'Docker application installer'
|
15
|
+
spec.description = "Install Docker containers with Chef, Dockerfile and other tools"
|
16
|
+
spec.homepage = "https://github.com/maxivak/docker-app"
|
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
|
data/exe/docker-app
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
lib = File.expand_path(File.dirname(__FILE__) + 'lib')
|
5
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require File.expand_path("../../lib/docker_app", __FILE__)
|
8
|
+
#require "docker_app"
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
puts "Docker app v.#{DockerApp::VERSION}"
|
13
|
+
|
14
|
+
# input
|
15
|
+
#args = ARGV.dup
|
16
|
+
#ARGV.clear
|
17
|
+
#command = args.shift.strip rescue 'help'
|
18
|
+
|
19
|
+
|
20
|
+
DockerApp::CLI.start
|
data/lib/docker_app.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "docker_app/version"
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
LIBRARY_PATH = File.join(File.dirname(__FILE__), 'docker_app')
|
6
|
+
|
7
|
+
module DockerApp
|
8
|
+
|
9
|
+
|
10
|
+
##
|
11
|
+
# Require base files
|
12
|
+
%w{
|
13
|
+
config
|
14
|
+
command
|
15
|
+
cli
|
16
|
+
server_settings
|
17
|
+
manager_image
|
18
|
+
manager_container
|
19
|
+
manager_swarm
|
20
|
+
provisioner/base
|
21
|
+
provisioner/chef
|
22
|
+
}.each {|lib| require File.join(LIBRARY_PATH, lib) }
|
23
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module DockerApp
|
2
|
+
module Builder
|
3
|
+
class Packer
|
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
|
+
def build
|
27
|
+
# config json
|
28
|
+
save_packer_config
|
29
|
+
|
30
|
+
DockerApp::Command.cmd %Q(packer build #{filename_config} )
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
# helpers
|
35
|
+
def save_packer_config
|
36
|
+
require 'json'
|
37
|
+
filename = filename_config
|
38
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
39
|
+
File.open(filename,"w+") do |f|
|
40
|
+
f.write(build_packer_config.to_json)
|
41
|
+
end
|
42
|
+
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def filename_config
|
47
|
+
File.join(Config.root_path, 'temp', "packer-#{settings.name}.json")
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_packer_config
|
51
|
+
res = {}
|
52
|
+
|
53
|
+
res['variables'] = {}
|
54
|
+
|
55
|
+
res['builders'] = []
|
56
|
+
|
57
|
+
bi = settings.properties['build']['base_image']
|
58
|
+
base_image_name = "#{bi['name']}:#{bi['tag']}"
|
59
|
+
builder1 = {
|
60
|
+
pull: false,
|
61
|
+
type: "docker",
|
62
|
+
image: base_image_name,
|
63
|
+
commit: true
|
64
|
+
}
|
65
|
+
|
66
|
+
# changes
|
67
|
+
entrypoint = settings.properties['build']['entrypoint']
|
68
|
+
if entrypoint
|
69
|
+
builder1['changes'] ||= []
|
70
|
+
builder1['changes'] << "ENTRYPOINT #{entrypoint}"
|
71
|
+
end
|
72
|
+
|
73
|
+
res['builders'] << builder1
|
74
|
+
|
75
|
+
#
|
76
|
+
recipe_name = settings['build']['packer']['recipe_name'] || 'build'
|
77
|
+
cookbook_paths = settings['build']['packer']['cookbook_paths'] || []
|
78
|
+
cookbook_paths << settings.dir_cookbooks
|
79
|
+
|
80
|
+
res["provisioners"] = [
|
81
|
+
{
|
82
|
+
type: "chef-solo",
|
83
|
+
prevent_sudo: true,
|
84
|
+
cookbook_paths: cookbook_paths,
|
85
|
+
json: settings.properties['attributes'],
|
86
|
+
run_list: ["recipe[#{settings.name}::#{recipe_name}]"]
|
87
|
+
},
|
88
|
+
]
|
89
|
+
|
90
|
+
# tag image
|
91
|
+
res["post-processors"] = [
|
92
|
+
{
|
93
|
+
repository: "#{settings.image_name}",
|
94
|
+
type: "docker-tag"
|
95
|
+
}
|
96
|
+
]
|
97
|
+
|
98
|
+
res
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# settings
|
2
|
+
local_mode true
|
3
|
+
|
4
|
+
#
|
5
|
+
#log_level :debug
|
6
|
+
log_level :info
|
7
|
+
|
8
|
+
|
9
|
+
#
|
10
|
+
root = File.absolute_path(File.dirname(__FILE__))
|
11
|
+
current_dir = File.dirname(__FILE__)
|
12
|
+
|
13
|
+
#puts "***** current dir =#{current_dir}"
|
14
|
+
#puts "***** SERVER root dir =#{ENV['SERVER_PATH']}"
|
15
|
+
#exit
|
16
|
+
|
17
|
+
#
|
18
|
+
my_server_name = ENV["NODE_NAME"] || ENV["SERVER_NAME"]
|
19
|
+
node_name my_server_name
|
20
|
+
|
21
|
+
knife[:chef_node_name] = my_server_name
|
22
|
+
|
23
|
+
server_base_dir = ENV['SERVER_PATH']
|
24
|
+
|
25
|
+
#client_key "#{current_dir}/dummy.pem"
|
26
|
+
#validation_client_name "validator"
|
27
|
+
|
28
|
+
### cookbooks
|
29
|
+
|
30
|
+
server_cookbooks_path = File.expand_path('cookbooks', server_base_dir)
|
31
|
+
|
32
|
+
cookbooks_paths = [
|
33
|
+
server_cookbooks_path,
|
34
|
+
|
35
|
+
#File.expand_path('../temp-cookbooks', root),
|
36
|
+
#File.join(root, '../cookbooks'),
|
37
|
+
#File.join(root, '../', node_name, 'cookbooks'),
|
38
|
+
|
39
|
+
#'/work/chef-repo/cookbooks-common',
|
40
|
+
#'/work/chef-repo/cookbooks',
|
41
|
+
|
42
|
+
]
|
43
|
+
|
44
|
+
cookbooks_paths.reject!{|f| !Dir.exists?(f)}
|
45
|
+
|
46
|
+
#puts "cookbooks: #{cookbooks_paths.inspect}"
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
# load another knife file
|
52
|
+
knife_custom_files = []
|
53
|
+
|
54
|
+
if server_base_dir
|
55
|
+
knife_custom_files = [
|
56
|
+
File.expand_path(".chef/knife.rb", server_base_dir),
|
57
|
+
File.expand_path("../../.chef/knife.rb", server_base_dir),
|
58
|
+
]
|
59
|
+
end
|
60
|
+
|
61
|
+
#File.expand_path("../../examples/example-nginx/servers/#{my_server_name}/.chef/knife.rb", __FILE__)
|
62
|
+
|
63
|
+
knife_custom_files.each do |file_knife_custom|
|
64
|
+
if ::File.exist?(file_knife_custom)
|
65
|
+
Chef::Config.from_file(file_knife_custom)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
cookbook_path cookbook_path+cookbooks_paths
|
71
|
+
|
72
|
+
#puts "FINAL cookbooks: #{cookbook_path}"
|
73
|
+
|
74
|
+
# node name
|
75
|
+
knife[:force] = true
|
76
|
+
|
77
|
+
|
78
|
+
# ssh
|
79
|
+
knife[:ssh_attribute] = "knife_zero.host"
|
80
|
+
|
81
|
+
|
82
|
+
#knife[:ssh_user] = 'mmx'
|
83
|
+
#knife[:ssh_password] = 'pwd'
|
84
|
+
|
85
|
+
#knife[:use_sudo] = true
|
86
|
+
|
87
|
+
#--no-host-key-verify
|
88
|
+
knife[:host_key_verify] = false
|
89
|
+
#--use-sudo-password
|
90
|
+
#knife[:use_sudo_password] = true
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
# ssl
|
95
|
+
|
96
|
+
ssl_verify_mode :verify_none
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
## Attributes of node objects will be saved to json file.
|
102
|
+
## the automatic_attribute_whitelist option limits the attributes to be saved.
|
103
|
+
knife[:automatic_attribute_whitelist] = %w[
|
104
|
+
fqdn
|
105
|
+
os
|
106
|
+
os_version
|
107
|
+
hostname
|
108
|
+
ipaddress
|
109
|
+
roles
|
110
|
+
recipes
|
111
|
+
ipaddress
|
112
|
+
platform
|
113
|
+
platform_version
|
114
|
+
platform_version
|
115
|
+
cloud
|
116
|
+
cloud_v2
|
117
|
+
chef_packages
|
118
|
+
]
|
@@ -0,0 +1,55 @@
|
|
1
|
+
base_dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
#puts "dir=#{base_dir}"
|
4
|
+
|
5
|
+
#
|
6
|
+
require 'chef/provisioning'
|
7
|
+
|
8
|
+
#
|
9
|
+
server_name = ENV['SERVER_NAME']
|
10
|
+
|
11
|
+
# settings
|
12
|
+
docker_options = {
|
13
|
+
base_image: node['build']['base_image'],
|
14
|
+
privileged: true,
|
15
|
+
command: node['docker']['command'] || '',
|
16
|
+
}
|
17
|
+
|
18
|
+
#puts "server: #{server_name}"
|
19
|
+
#puts "node base = #{node['base']}"
|
20
|
+
#puts "image = #{node['base']['image_name']}"
|
21
|
+
#puts "node attr: #{node['attributes']}"
|
22
|
+
#puts "docker opt = #{docker_options}"
|
23
|
+
#exit
|
24
|
+
|
25
|
+
image_name = node['base']['image_name']
|
26
|
+
#image_name = 'example-my'
|
27
|
+
|
28
|
+
### docker image
|
29
|
+
with_driver 'docker'
|
30
|
+
#machine_image node['base']['image_name'] do
|
31
|
+
machine_image image_name do
|
32
|
+
action :create
|
33
|
+
|
34
|
+
#tag '0.1'
|
35
|
+
|
36
|
+
recipe "#{server_name}::build"
|
37
|
+
|
38
|
+
# attributes
|
39
|
+
#node.keys.each do |k|
|
40
|
+
# attribute k, node[k]
|
41
|
+
#end
|
42
|
+
|
43
|
+
# attributes
|
44
|
+
node['attributes'].keys.each do |k|
|
45
|
+
attribute k, node['attributes'][k]
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
machine_options docker_options: docker_options
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|