docktor 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 749c40ad9a74da59aaa3a52c9ab9848bf52a10bd
4
+ data.tar.gz: 14bb492a1232e1ffd85c0eae9c99ae9e3f0e6b81
5
+ SHA512:
6
+ metadata.gz: c03b957271b5b1388354a52fb786a40a5bc5396fd94fbaf9bf3ee14434e42bbe367521f42d5e6defb8fa56dc38cafba259fd8da0ece623e9b88bf6f47c6a83ba
7
+ data.tar.gz: 429aa3be22d6ab039be4132fac9d8c9ab9038ef82248ee194ce940d59a9669c16bc90646041c8d90f47a6579148e21313316578a2516bd6ac5cda4f04479c481
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docktor.gemspec
4
+ gemspec
5
+
6
+ gem 'virtus'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Marcelo Munhoz Pélos
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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Docktor
2
+
3
+ Docktor is tool for defining and running multi-container applications with Docker, specific for development. This gem is under development.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'docktor'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install docktor
20
+
21
+ ## Usage
22
+
23
+ Create a file `docktor.yml` in application root, then run:
24
+
25
+ ```ruby
26
+ doc
27
+ ```
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "docktor"
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/doc ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler"
4
+ Bundler.setup
5
+ require "docktor"
6
+
7
+ include Docktor
8
+
9
+ Docktor::Runner.new.invoke
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/docktor.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docktor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "docktor"
8
+ spec.version = Docktor::VERSION
9
+ spec.authors = ["Marcelo Munhoz Pélos"]
10
+ spec.email = ["mpelos@gmail.com"]
11
+
12
+ spec.summary = %q{Docktor is tool for defining and running multi-container applications with Docker, specific for development. This gem is under development.}
13
+ spec.homepage = "https://github.com/mpelos/docktor"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "bin"
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec"
32
+ end
@@ -0,0 +1,23 @@
1
+ require "virtus"
2
+
3
+ module Docktor
4
+ class Container
5
+ include Virtus.value_object
6
+
7
+ OPTION_ATTRIBUTES = %i(volumes ports links environment)
8
+
9
+ values do
10
+ attribute :name, String
11
+ attribute :image, String
12
+ attribute :command, String
13
+ attribute :volumes, Array[String]
14
+ attribute :ports, Array[String]
15
+ attribute :links, Array[String]
16
+ attribute :environment, Hash[String, String]
17
+ end
18
+
19
+ def options
20
+ attributes.select { |key, value| (key != :name || key != :image) && !value.nil? && !value.empty? }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ module Docktor
2
+ class DockerClient
3
+ CONTAINER_NAME_PREFIX = "docktor_"
4
+
5
+ def container_exists?(container)
6
+ `docker ps -aqf name=#{container_name(container.name)}` != ""
7
+ end
8
+
9
+ def run(container)
10
+ puts "docker run -d --name #{container_name(container.name)} #{parse_options(container.options)} #{container.image} #{container.command}"
11
+ `docker run -d --name #{container_name(container.name)} #{parse_options(container.options)} #{container.image} #{container.command}`
12
+ end
13
+
14
+ def start(container)
15
+ `docker start #{container_name(container.name)}`
16
+ end
17
+
18
+ def parse_options(options)
19
+ options.map do |name, value|
20
+ case name
21
+ when :volumes then "-v #{value.join(" ")}"
22
+ when :ports then "-p #{value.join(" ")}"
23
+ when :links then "--link #{value.join(" ")}"
24
+ value.map { |v| "--link #{container_name(v)}" }.join(" ")
25
+ when :environment
26
+ "-e #{value.map { |k, v| %(#{k}="#{v}") }.join(" ")}"
27
+ end
28
+ end.join(" ").strip
29
+ end
30
+
31
+ def container_name(name)
32
+ CONTAINER_NAME_PREFIX + name
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require "docktor/yaml_parser"
2
+ require "docktor/docker_client"
3
+
4
+ module Docktor
5
+ class Runner
6
+ DEFAULT_YAML_PATH = "./docktor.yml"
7
+
8
+ def invoke(yaml_path: DEFAULT_YAML_PATH, parser: Docktor::YAMLParser.new, client: Docktor::DockerClient.new)
9
+ containers = parser.parse(yaml_path)
10
+
11
+ containers.each do |container|
12
+ if client.container_exists?(container)
13
+ client.start container
14
+ else
15
+ client.run container
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Docktor
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "yaml"
2
+ require "docktor/container"
3
+
4
+ module Docktor
5
+ class YAMLParser
6
+ def parse(yaml_path)
7
+ YAML.load_file(yaml_path).map do |container_name, options|
8
+ Container.new(
9
+ name: container_name,
10
+ image: options["image"],
11
+ volumes: options["volumes"],
12
+ ports: options["ports"],
13
+ links: options["links"],
14
+ command: options["command"],
15
+ environment: options["environment"]
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/docktor.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "docktor/version"
2
+ require "docktor/runner"
3
+
4
+ module Docktor
5
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docktor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Munhoz Pélos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - mpelos@gmail.com
58
+ executables:
59
+ - console
60
+ - doc
61
+ - setup
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/doc
73
+ - bin/setup
74
+ - docktor.gemspec
75
+ - lib/docktor.rb
76
+ - lib/docktor/container.rb
77
+ - lib/docktor/docker_client.rb
78
+ - lib/docktor/runner.rb
79
+ - lib/docktor/version.rb
80
+ - lib/docktor/yaml_parser.rb
81
+ homepage: https://github.com/mpelos/docktor
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ allowed_push_host: https://rubygems.org
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.5
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Docktor is tool for defining and running multi-container applications with
106
+ Docker, specific for development. This gem is under development.
107
+ test_files: []