dru 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 452af962ffdb65caeb9f532ae055d0fc5980645f8705f2131da025797765dced
4
+ data.tar.gz: 784dd5cdace3cd50a0695631473fc4d975be639dbe2828c2994aba6a0c6212f5
5
+ SHA512:
6
+ metadata.gz: 12517a5b8a94c16a61ba5e7084ce2c90cd6f5b5c1bfbb596309bcdbd3b829c964481f70c0b7ef22099ec9859cc1fb7c106a111842fbcf4d21b9ffd3b56fc3bd1
7
+ data.tar.gz: 726ed77400c89bfb343b3460c4ec99aafdfb8598eff1dd8386ff15e234b643f23d5674167108e81a8c17182daaad86b3d6e5e74a0be57fe47da3ebd3cf90616d
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at christian.rimondi@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dru.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,124 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dru (0.1.0)
5
+ pastel (~> 0.7.2)
6
+ thor (~> 0.20.0)
7
+ tty-color (~> 0.4.2)
8
+ tty-command (~> 0.8.0)
9
+ tty-config (~> 0.2.0)
10
+ tty-cursor (~> 0.5.0)
11
+ tty-editor (~> 0.4.0)
12
+ tty-file (~> 0.6.0)
13
+ tty-font (~> 0.2.0)
14
+ tty-markdown (~> 0.4.0)
15
+ tty-pager (~> 0.11.0)
16
+ tty-platform (~> 0.1.0)
17
+ tty-progressbar (~> 0.15.0)
18
+ tty-prompt (~> 0.16.1)
19
+ tty-screen (~> 0.6.4)
20
+ tty-spinner (~> 0.8.0)
21
+ tty-table (~> 0.10.0)
22
+ tty-tree (~> 0.1.0)
23
+ tty-which (~> 0.3.0)
24
+
25
+ GEM
26
+ remote: https://rubygems.org/
27
+ specs:
28
+ diff-lcs (1.3)
29
+ equatable (0.5.0)
30
+ kramdown (1.16.2)
31
+ necromancer (0.4.0)
32
+ pastel (0.7.2)
33
+ equatable (~> 0.5.0)
34
+ tty-color (~> 0.4.0)
35
+ rake (10.5.0)
36
+ rake-compiler (1.0.5)
37
+ rake
38
+ rouge (3.1.1)
39
+ rspec (3.8.0)
40
+ rspec-core (~> 3.8.0)
41
+ rspec-expectations (~> 3.8.0)
42
+ rspec-mocks (~> 3.8.0)
43
+ rspec-core (3.8.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-expectations (3.8.2)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-mocks (3.8.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-support (3.8.0)
52
+ strings (0.1.4)
53
+ strings-ansi (~> 0.1.0)
54
+ unicode-display_width (~> 1.4.0)
55
+ unicode_utils (~> 1.4.0)
56
+ strings-ansi (0.1.0)
57
+ thor (0.20.3)
58
+ timers (4.2.0)
59
+ tty-color (0.4.3)
60
+ tty-command (0.8.2)
61
+ pastel (~> 0.7.0)
62
+ tty-config (0.2.0)
63
+ tty-cursor (0.5.0)
64
+ tty-editor (0.4.0)
65
+ tty-prompt (~> 0.16.0)
66
+ tty-which (~> 0.3.0)
67
+ tty-file (0.6.0)
68
+ diff-lcs (~> 1.3.0)
69
+ pastel (~> 0.7.2)
70
+ tty-prompt (~> 0.16.1)
71
+ tty-font (0.2.0)
72
+ tty-markdown (0.4.0)
73
+ kramdown (~> 1.16.2)
74
+ pastel (~> 0.7.2)
75
+ rouge (~> 3.1.0)
76
+ strings (~> 0.1.0)
77
+ tty-color (~> 0.4.2)
78
+ tty-screen (~> 0.6.4)
79
+ tty-pager (0.11.0)
80
+ strings (~> 0.1.0)
81
+ tty-screen (~> 0.6.4)
82
+ tty-which (~> 0.3.0)
83
+ tty-platform (0.1.0)
84
+ tty-progressbar (0.15.1)
85
+ tty-cursor (~> 0.5.0)
86
+ tty-screen (~> 0.6.4)
87
+ unicode-display_width (~> 1.3)
88
+ tty-prompt (0.16.1)
89
+ necromancer (~> 0.4.0)
90
+ pastel (~> 0.7.0)
91
+ timers (~> 4.0)
92
+ tty-cursor (~> 0.5.0)
93
+ tty-reader (~> 0.3.0)
94
+ tty-reader (0.3.0)
95
+ tty-cursor (~> 0.5.0)
96
+ tty-screen (~> 0.6.4)
97
+ wisper (~> 2.0.0)
98
+ tty-screen (0.6.5)
99
+ tty-spinner (0.8.0)
100
+ tty-cursor (>= 0.5.0)
101
+ tty-table (0.10.0)
102
+ equatable (~> 0.5.0)
103
+ necromancer (~> 0.4.0)
104
+ pastel (~> 0.7.2)
105
+ strings (~> 0.1.0)
106
+ tty-screen (~> 0.6.4)
107
+ tty-tree (0.1.0)
108
+ tty-which (0.3.0)
109
+ unicode-display_width (1.4.0)
110
+ unicode_utils (1.4.0)
111
+ wisper (2.0.0)
112
+
113
+ PLATFORMS
114
+ ruby
115
+
116
+ DEPENDENCIES
117
+ bundler (~> 1.16)
118
+ dru!
119
+ rake (~> 10.0)
120
+ rake-compiler
121
+ rspec (~> 3.0)
122
+
123
+ BUNDLED WITH
124
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Nebulab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Dru
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dru`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dru'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dru
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dru. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Dru project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dru/blob/master/CODE_OF_CONDUCT.md).
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2018 Nebulab. See [MIT License](LICENSE.txt) for further details.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rake/extensiontask"
7
+
8
+ task :build => :compile
9
+
10
+ Rake::ExtensionTask.new("dru") do |ext|
11
+ ext.lib_dir = "lib/dru"
12
+ end
13
+
14
+ task :default => [:clobber, :compile, :spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dru"
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(__FILE__)
data/bin/setup ADDED
@@ -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
data/dru.gemspec ADDED
@@ -0,0 +1,62 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dru/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dru"
8
+ spec.license = "MIT"
9
+ spec.version = Dru::VERSION
10
+ spec.authors = ["Christian Rimondi", "Alessio Rocco"]
11
+ spec.email = ["christianrimondi@nebulab.it", "alessiorocco@nebulab.it"]
12
+
13
+ spec.summary = %q{DRU - Docker Compose Run Utility}
14
+ spec.description = <<-EOS
15
+ A ruby tool to simplify the development workflow with Docker Compose and Docker.
16
+ EOS
17
+ spec.homepage = "https://github.com/nebulab/dru"
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+ spec.extensions = ["ext/dru/extconf.rb"]
37
+
38
+ spec.add_dependency "tty-color", "~> 0.4.2"
39
+ spec.add_dependency "tty-command", "~> 0.8.0"
40
+ spec.add_dependency "tty-config", "~> 0.2.0"
41
+ spec.add_dependency "tty-cursor", "~> 0.5.0"
42
+ spec.add_dependency "tty-editor", "~> 0.4.0"
43
+ spec.add_dependency "tty-file", "~> 0.6.0"
44
+ spec.add_dependency "tty-font", "~> 0.2.0"
45
+ spec.add_dependency "tty-markdown", "~> 0.4.0"
46
+ spec.add_dependency "tty-pager", "~> 0.11.0"
47
+ spec.add_dependency "tty-platform", "~> 0.1.0"
48
+ spec.add_dependency "tty-progressbar", "~> 0.15.0"
49
+ spec.add_dependency "tty-prompt", "~> 0.16.1"
50
+ spec.add_dependency "tty-screen", "~> 0.6.4"
51
+ spec.add_dependency "tty-spinner", "~> 0.8.0"
52
+ spec.add_dependency "tty-table", "~> 0.10.0"
53
+ spec.add_dependency "tty-tree", "~> 0.1.0"
54
+ spec.add_dependency "tty-which", "~> 0.3.0"
55
+ spec.add_dependency "pastel", "~> 0.7.2"
56
+ spec.add_dependency "thor", "~> 0.20.0"
57
+
58
+ spec.add_development_dependency "bundler", "~> 1.16"
59
+ spec.add_development_dependency "rake", "~> 10.0"
60
+ spec.add_development_dependency "rake-compiler"
61
+ spec.add_development_dependency "rspec", "~> 3.0"
62
+ end
data/exe/dru ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path('../lib', __dir__)
5
+ $:.unshift(lib_path) if !$:.include?(lib_path)
6
+ require 'dru'
7
+
8
+ Signal.trap('INT') do
9
+ warn("\n#{caller.join("\n")}: interrupted")
10
+ exit(1)
11
+ end
12
+
13
+ begin
14
+ Dru::CLI.start
15
+ rescue Dru::CLI::Error => err
16
+ puts "ERROR: #{err.message}"
17
+ exit 1
18
+ end
data/ext/dru/dru.c ADDED
@@ -0,0 +1,9 @@
1
+ #include "dru.h"
2
+
3
+ VALUE rb_mDru;
4
+
5
+ void
6
+ Init_dru(void)
7
+ {
8
+ rb_mDru = rb_define_module("Dru");
9
+ }
data/ext/dru/dru.h ADDED
@@ -0,0 +1,6 @@
1
+ #ifndef DRU_H
2
+ #define DRU_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* DRU_H */
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("dru/dru")
data/lib/dru/cli.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module Dru
6
+ # Handle the application command line parsing
7
+ # and the dispatch to various command objects
8
+ #
9
+ # @api public
10
+ class CLI < Thor
11
+ # Error raised by this runner
12
+ Error = Class.new(StandardError)
13
+
14
+ desc 'version', 'dru version'
15
+ def version
16
+ require_relative 'version'
17
+ puts "v#{Dru::VERSION}"
18
+ end
19
+ map %w(--version -v) => :version
20
+
21
+ desc 'up', 'Build, (re)create, start, and attach to default container'
22
+ method_option :help, aliases: '-h', type: :boolean,
23
+ desc: 'Display usage information'
24
+ method_option :detach, aliases: '-d', type: :boolean,
25
+ desc: 'Detached mode'
26
+ def up(*)
27
+ if options[:help]
28
+ invoke :help, ['up']
29
+ else
30
+ require_relative 'commands/up'
31
+ Dru::Commands::Up.new(options).execute
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Dru
6
+ class Command
7
+ extend Forwardable
8
+
9
+ DOCKER_COMPOSE_COMMAND = 'docker-compose'.freeze
10
+
11
+ attr_accessor :options
12
+
13
+ def_delegators :command, :run
14
+
15
+ # Execute this command
16
+ #
17
+ # @api public
18
+ def execute(*)
19
+ raise(
20
+ NotImplementedError,
21
+ "#{self.class}##{__method__} must be implemented"
22
+ )
23
+ end
24
+
25
+ # The external commands runner
26
+ #
27
+ # @see http://www.rubydoc.info/gems/tty-command
28
+ #
29
+ # @api public
30
+ def command(**options)
31
+ require 'tty-command'
32
+ TTY::Command.new({ printer: :quiet, uuid: false }.merge(options))
33
+ end
34
+
35
+ # The cursor movement
36
+ #
37
+ # @see http://www.rubydoc.info/gems/tty-cursor
38
+ #
39
+ # @api public
40
+ def cursor
41
+ require 'tty-cursor'
42
+ TTY::Cursor
43
+ end
44
+
45
+ # Open a file or text in the user's preferred editor
46
+ #
47
+ # @see http://www.rubydoc.info/gems/tty-editor
48
+ #
49
+ # @api public
50
+ def editor
51
+ require 'tty-editor'
52
+ TTY::Editor
53
+ end
54
+
55
+ # File manipulation utility methods
56
+ #
57
+ # @see http://www.rubydoc.info/gems/tty-file
58
+ #
59
+ # @api public
60
+ def generator
61
+ require 'tty-file'
62
+ TTY::File
63
+ end
64
+
65
+ # Terminal output paging
66
+ #
67
+ # @see http://www.rubydoc.info/gems/tty-pager
68
+ #
69
+ # @api public
70
+ def pager(**options)
71
+ require 'tty-pager'
72
+ TTY::Pager.new(options)
73
+ end
74
+
75
+ # Terminal platform and OS properties
76
+ #
77
+ # @see http://www.rubydoc.info/gems/tty-pager
78
+ #
79
+ # @api public
80
+ def platform
81
+ require 'tty-platform'
82
+ TTY::Platform.new
83
+ end
84
+
85
+ # The interactive prompt
86
+ #
87
+ # @see http://www.rubydoc.info/gems/tty-prompt
88
+ #
89
+ # @api public
90
+ def prompt(**options)
91
+ require 'tty-prompt'
92
+ TTY::Prompt.new(options)
93
+ end
94
+
95
+ # Get terminal screen properties
96
+ #
97
+ # @see http://www.rubydoc.info/gems/tty-screen
98
+ #
99
+ # @api public
100
+ def screen
101
+ require 'tty-screen'
102
+ TTY::Screen
103
+ end
104
+
105
+ # The unix which utility
106
+ #
107
+ # @see http://www.rubydoc.info/gems/tty-which
108
+ #
109
+ # @api public
110
+ def which(*args)
111
+ require 'tty-which'
112
+ TTY::Which.which(*args)
113
+ end
114
+
115
+ # Check if executable exists
116
+ #
117
+ # @see http://www.rubydoc.info/gems/tty-which
118
+ #
119
+ # @api public
120
+ def exec_exist?(*args)
121
+ require 'tty-which'
122
+ TTY::Which.exist?(*args)
123
+ end
124
+
125
+ def project_name
126
+ File.basename(Dir.pwd)
127
+ end
128
+
129
+ def environment
130
+ options && options[:environment]
131
+ end
132
+
133
+ def project_configuration_path
134
+ File.expand_path(project_name, Dru.config.docker_projects_folder)
135
+ end
136
+
137
+ def default_docker_compose
138
+ File.join(project_configuration_path, 'docker-compose.yml')
139
+ end
140
+
141
+ def environment_docker_compose
142
+ return unless environment
143
+
144
+ File.join(project_configuration_path, "docker-compose.#{environment}.yml")
145
+ end
146
+
147
+ def docker_compose_paths
148
+ docker_compose_default_path + docker_compose_environment_path
149
+ end
150
+
151
+ def run_docker_compose_command(*args, **options)
152
+ command(options).run(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args)
153
+ end
154
+
155
+ def container_name_to_id(container_name = 'app')
156
+ run_docker_compose_command('ps', '-q', container_name, printer: :null).first
157
+ end
158
+
159
+ private
160
+
161
+ def docker_compose_default_path
162
+ ['-f', default_docker_compose]
163
+ end
164
+
165
+ def docker_compose_environment_path
166
+ return [] unless environment_docker_compose
167
+
168
+ ['-f', environment_docker_compose]
169
+ end
170
+ end
171
+ end
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+
5
+ module Dru
6
+ module Commands
7
+ class Up < Dru::Command
8
+ DOCKER_ATTACH_COMMAND = 'docker attach --detach-keys="ctrl-d"'.freeze
9
+
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ def execute(input: $stdin, output: $stdout)
15
+ start_docker_compose
16
+ return if options[:detach]
17
+
18
+ stop_docker_compose if attach_to_default_container
19
+ end
20
+
21
+ private
22
+
23
+ def start_docker_compose
24
+ run_docker_compose_command('up', '-d')
25
+ end
26
+
27
+ def stop_docker_compose
28
+ run_docker_compose_command('down')
29
+ end
30
+
31
+ def attach_to_default_container(container_name = 'app')
32
+ system "#{DOCKER_ATTACH_COMMAND} #{container_name_to_id(container_name)}"
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/dru/config.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+ require 'forwardable'
4
+ require 'json'
5
+
6
+ module Dru
7
+ class Config
8
+ extend Forwardable
9
+ include Singleton
10
+
11
+ def_delegators :configs, :docker_projects_folder
12
+
13
+ DEFAULT = {
14
+ 'docker_projects_folder' => "~/.dru"
15
+ }.freeze
16
+
17
+ attr_reader :config_file_path
18
+
19
+ def config_file_path=(config_file_path)
20
+ @configs = nil
21
+ @config_file_path = config_file_path
22
+ end
23
+
24
+ private
25
+
26
+ def configs
27
+ @configs ||= JSON.parse(DEFAULT.merge(user_configs).to_json, object_class: OpenStruct)
28
+ end
29
+
30
+ def user_configs
31
+ return {} unless config_file_path && File.file?(config_file_path)
32
+ YAML.load_file(config_file_path) || {}
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,3 @@
1
+ module Dru
2
+ VERSION = "0.1.0"
3
+ end
data/lib/dru.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "dru/config"
2
+ require "dru/cli"
3
+
4
+ module Dru
5
+ DRUCONFIG = File.expand_path('~/.druconfig')
6
+
7
+ def self.config
8
+ Config.instance.tap { |instance| instance.config_file_path = DRUCONFIG }
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,397 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Rimondi
8
+ - Alessio Rocco
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2019-01-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tty-color
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.4.2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.4.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: tty-command
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.8.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: tty-config
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.2.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.2.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: tty-cursor
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.5.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.5.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: tty-editor
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.4.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.4.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: tty-file
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.6.0
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.6.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: tty-font
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.2.0
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.2.0
112
+ - !ruby/object:Gem::Dependency
113
+ name: tty-markdown
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.4.0
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 0.4.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: tty-pager
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 0.11.0
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 0.11.0
140
+ - !ruby/object:Gem::Dependency
141
+ name: tty-platform
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: 0.1.0
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: 0.1.0
154
+ - !ruby/object:Gem::Dependency
155
+ name: tty-progressbar
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: 0.15.0
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: 0.15.0
168
+ - !ruby/object:Gem::Dependency
169
+ name: tty-prompt
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: 0.16.1
175
+ type: :runtime
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: 0.16.1
182
+ - !ruby/object:Gem::Dependency
183
+ name: tty-screen
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: 0.6.4
189
+ type: :runtime
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: 0.6.4
196
+ - !ruby/object:Gem::Dependency
197
+ name: tty-spinner
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: 0.8.0
203
+ type: :runtime
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: 0.8.0
210
+ - !ruby/object:Gem::Dependency
211
+ name: tty-table
212
+ requirement: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - "~>"
215
+ - !ruby/object:Gem::Version
216
+ version: 0.10.0
217
+ type: :runtime
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - "~>"
222
+ - !ruby/object:Gem::Version
223
+ version: 0.10.0
224
+ - !ruby/object:Gem::Dependency
225
+ name: tty-tree
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - "~>"
229
+ - !ruby/object:Gem::Version
230
+ version: 0.1.0
231
+ type: :runtime
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - "~>"
236
+ - !ruby/object:Gem::Version
237
+ version: 0.1.0
238
+ - !ruby/object:Gem::Dependency
239
+ name: tty-which
240
+ requirement: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - "~>"
243
+ - !ruby/object:Gem::Version
244
+ version: 0.3.0
245
+ type: :runtime
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - "~>"
250
+ - !ruby/object:Gem::Version
251
+ version: 0.3.0
252
+ - !ruby/object:Gem::Dependency
253
+ name: pastel
254
+ requirement: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - "~>"
257
+ - !ruby/object:Gem::Version
258
+ version: 0.7.2
259
+ type: :runtime
260
+ prerelease: false
261
+ version_requirements: !ruby/object:Gem::Requirement
262
+ requirements:
263
+ - - "~>"
264
+ - !ruby/object:Gem::Version
265
+ version: 0.7.2
266
+ - !ruby/object:Gem::Dependency
267
+ name: thor
268
+ requirement: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - "~>"
271
+ - !ruby/object:Gem::Version
272
+ version: 0.20.0
273
+ type: :runtime
274
+ prerelease: false
275
+ version_requirements: !ruby/object:Gem::Requirement
276
+ requirements:
277
+ - - "~>"
278
+ - !ruby/object:Gem::Version
279
+ version: 0.20.0
280
+ - !ruby/object:Gem::Dependency
281
+ name: bundler
282
+ requirement: !ruby/object:Gem::Requirement
283
+ requirements:
284
+ - - "~>"
285
+ - !ruby/object:Gem::Version
286
+ version: '1.16'
287
+ type: :development
288
+ prerelease: false
289
+ version_requirements: !ruby/object:Gem::Requirement
290
+ requirements:
291
+ - - "~>"
292
+ - !ruby/object:Gem::Version
293
+ version: '1.16'
294
+ - !ruby/object:Gem::Dependency
295
+ name: rake
296
+ requirement: !ruby/object:Gem::Requirement
297
+ requirements:
298
+ - - "~>"
299
+ - !ruby/object:Gem::Version
300
+ version: '10.0'
301
+ type: :development
302
+ prerelease: false
303
+ version_requirements: !ruby/object:Gem::Requirement
304
+ requirements:
305
+ - - "~>"
306
+ - !ruby/object:Gem::Version
307
+ version: '10.0'
308
+ - !ruby/object:Gem::Dependency
309
+ name: rake-compiler
310
+ requirement: !ruby/object:Gem::Requirement
311
+ requirements:
312
+ - - ">="
313
+ - !ruby/object:Gem::Version
314
+ version: '0'
315
+ type: :development
316
+ prerelease: false
317
+ version_requirements: !ruby/object:Gem::Requirement
318
+ requirements:
319
+ - - ">="
320
+ - !ruby/object:Gem::Version
321
+ version: '0'
322
+ - !ruby/object:Gem::Dependency
323
+ name: rspec
324
+ requirement: !ruby/object:Gem::Requirement
325
+ requirements:
326
+ - - "~>"
327
+ - !ruby/object:Gem::Version
328
+ version: '3.0'
329
+ type: :development
330
+ prerelease: false
331
+ version_requirements: !ruby/object:Gem::Requirement
332
+ requirements:
333
+ - - "~>"
334
+ - !ruby/object:Gem::Version
335
+ version: '3.0'
336
+ description: " A ruby tool to simplify the development workflow with Docker Compose
337
+ and Docker.\n"
338
+ email:
339
+ - christianrimondi@nebulab.it
340
+ - alessiorocco@nebulab.it
341
+ executables:
342
+ - dru
343
+ extensions:
344
+ - ext/dru/extconf.rb
345
+ extra_rdoc_files: []
346
+ files:
347
+ - ".gitignore"
348
+ - ".rspec"
349
+ - ".travis.yml"
350
+ - CODE_OF_CONDUCT.md
351
+ - Gemfile
352
+ - Gemfile.lock
353
+ - LICENSE.txt
354
+ - README.md
355
+ - Rakefile
356
+ - bin/console
357
+ - bin/setup
358
+ - dru.gemspec
359
+ - exe/dru
360
+ - ext/dru/dru.c
361
+ - ext/dru/dru.h
362
+ - ext/dru/extconf.rb
363
+ - lib/dru.rb
364
+ - lib/dru/cli.rb
365
+ - lib/dru/command.rb
366
+ - lib/dru/commands/.gitkeep
367
+ - lib/dru/commands/up.rb
368
+ - lib/dru/config.rb
369
+ - lib/dru/templates/.gitkeep
370
+ - lib/dru/templates/up/.gitkeep
371
+ - lib/dru/version.rb
372
+ homepage: https://github.com/nebulab/dru
373
+ licenses:
374
+ - MIT
375
+ metadata:
376
+ allowed_push_host: https://rubygems.org
377
+ post_install_message:
378
+ rdoc_options: []
379
+ require_paths:
380
+ - lib
381
+ required_ruby_version: !ruby/object:Gem::Requirement
382
+ requirements:
383
+ - - ">="
384
+ - !ruby/object:Gem::Version
385
+ version: '0'
386
+ required_rubygems_version: !ruby/object:Gem::Requirement
387
+ requirements:
388
+ - - ">="
389
+ - !ruby/object:Gem::Version
390
+ version: '0'
391
+ requirements: []
392
+ rubyforge_project:
393
+ rubygems_version: 2.7.7
394
+ signing_key:
395
+ specification_version: 4
396
+ summary: DRU - Docker Compose Run Utility
397
+ test_files: []