nib 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 771f362ff201cb486408a2a30c12ceb58d4afda2
4
+ data.tar.gz: 22030812aaf1463371399e19bd9180e14afcd935
5
+ SHA512:
6
+ metadata.gz: a71124f98d3660fcd11968c54c5b0b4cd62e14a37930bb394ecb3ef4d7d02d7ee5d880458dd2bf52ef65efa1523e2ccbd1d1920782db35982700f30b23362c78
7
+ data.tar.gz: c4cb4ff1c894357b4bb7be1fdbf279587c171d91ffc8c06acce623869c254c72bd792052ff7b2ab3fae24486d8dce66812de89963edc5d5898facc22eb3db39d
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
data/bin/nib ADDED
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gli'
4
+ require 'nib'
5
+
6
+ include GLI::App
7
+
8
+ program_desc 'A docker-compose wrapper geared towards Ruby/Rails development'
9
+
10
+ version Nib::VERSION
11
+
12
+ subcommand_option_handling :normal
13
+ arguments :strict
14
+ autocomplete_commands false
15
+ preserve_argv true
16
+
17
+ GLI::Commands::Help.skips_post = false
18
+
19
+ pre do |global, command, options, args|
20
+ # Pre logic here
21
+ # Return true to proceed; false to abort and not call the
22
+ # chosen command
23
+ # Use skips_pre before a command to skip this block
24
+ # on that command only
25
+ true
26
+ end
27
+
28
+ post do |global, command, options, args|
29
+ # Post logic here
30
+ # Use skips_post before a command to skip this
31
+ # block on that command only
32
+ if command.is_a? GLI::Commands::Help
33
+ Nib::UnrecognizedHelp.execute(options, args)
34
+ Nib::CheckForUpdate.execute(options, args)
35
+ end
36
+ end
37
+
38
+ # return false to skip default error handling
39
+ on_error do |exception|
40
+ case exception
41
+ when GLI::UnknownCommand
42
+ # delegate unknown commands over to `docker-compose`
43
+ exec("docker-compose #{ARGV.join(' ')}")
44
+
45
+ false
46
+ else
47
+ true
48
+ end
49
+ end
50
+
51
+ desc 'Run bundle for the given service'
52
+ arg :service
53
+ arg :command, %i(optional multiple)
54
+ command :bundle do |c|
55
+ c.action do |global, options, args|
56
+ Nib::Run.execute(args.insert(1, :bundle), '--no-deps')
57
+ end
58
+ end
59
+
60
+ desc 'Run codeclimate checks on the given service'
61
+ arg :service
62
+ arg :command, %i(optional multiple)
63
+ command :codeclimate do |c|
64
+ c.action do |global, options, args|
65
+ Nib::CodeClimate.execute(args, '--no-deps')
66
+ end
67
+ end
68
+
69
+ desc 'Start a REPL session for the given service'
70
+ long_desc 'This command will try to detect the applications environment (ie. rails console or bundle console)
71
+ and start the most appropriate REPL possible. It\'s possible to directly override this behaviour by
72
+ supplying an executable file at $pwd/bin/console.'
73
+ arg :service
74
+ arg :command, %i(optional multiple)
75
+ command :console do |c|
76
+ c.action do |global, options, args|
77
+ Nib::Console.execute(args)
78
+ end
79
+ end
80
+
81
+ desc 'Connect to a running byebug server for a given service'
82
+ long_desc 'This command requires a little extra setup.
83
+
84
+ - The byebug server must be running inside of a web service
85
+ - The RUBY_DEBUG_PORT must be defined in docker-compose.yml for the service
86
+ - The debug port must be exposed by the service'
87
+ arg :service
88
+ command :debug do |c|
89
+ c.action do |global, options, args|
90
+ Nib::Debug.execute(args, '--no-deps')
91
+ end
92
+ end
93
+
94
+ desc 'Attach an interactive shell session to a running container'
95
+ arg :service
96
+ arg :command, %i(optional multiple)
97
+ command :exec do |c|
98
+ Nib::Options::Augmenter.augment(c)
99
+
100
+ c.action do |global, options, args|
101
+ Nib::Exec.execute(args, Nib::Options::Parser.parse(options))
102
+ end
103
+ end
104
+
105
+ desc 'Run the guard command for the given service'
106
+ arg :service
107
+ arg :command, %i(optional multiple)
108
+ command :guard do |c|
109
+ c.action do |global, options, args|
110
+ Nib::Run.execute(args.insert(1, :guard))
111
+ end
112
+ end
113
+
114
+ desc 'Run the rails command for the given service'
115
+ arg :service
116
+ arg :command, %i(optional multiple)
117
+ command :rails do |c|
118
+ c.action do |global, options, args|
119
+ Nib::Run.execute(args.insert(1, :rails))
120
+ end
121
+ end
122
+
123
+ desc 'Run the rake command for the given service'
124
+ arg :service
125
+ arg :command, %i(optional multiple)
126
+ command :rake do |c|
127
+ c.action do |global, options, args|
128
+ Nib::Run.execute(args.insert(1, :rake))
129
+ end
130
+ end
131
+
132
+ desc 'Runs the rspec command for the given service'
133
+ arg :service
134
+ arg :command, %i(optional multiple)
135
+ command :rspec do |c|
136
+ c.action do |global, options, args|
137
+ Nib::Run.execute(args.insert(1, :rspec))
138
+ end
139
+ end
140
+
141
+ desc 'Runs the rubocop command for the given service'
142
+ arg :service
143
+ arg :command, %i(optional multiple)
144
+ command :rubocop do |c|
145
+ c.action do |global, options, args|
146
+ Nib::Run.execute(args.insert(1, :rubocop), '--no-deps')
147
+ end
148
+ end
149
+
150
+ desc 'Wraps normal \'docker-compose run\' to ensure that --rm is always passed'
151
+ arg :service
152
+ arg :command, %i(optional multiple)
153
+ command :run do |c|
154
+ Nib::Options::Augmenter.augment(c)
155
+
156
+ c.action do |global, options, args|
157
+ Nib::Run.execute(args, Nib::Options::Parser.parse(options))
158
+ end
159
+ end
160
+
161
+ desc 'Runs application specific setup for the given service'
162
+ long_desc 'By default the setup command will execute \'bundle install && rake db:create db:migrate\'.
163
+
164
+ This behavior can be overriden by providing an executable file in the project at $pwd/bin/setup.
165
+ Additionally the setup process can be augmented by providing either $pwd/bin/setup.before or
166
+ $pwd/bin/setup.after. This allows for extending the default behavior without having to redefine it.'
167
+ arg :service
168
+ command :setup do |c|
169
+ c.action do |global, options, args|
170
+ Nib::Setup.execute(args)
171
+ end
172
+ end
173
+
174
+ desc 'Start a shell session in a one-off service container'
175
+ arg :service
176
+ arg :command, %i(optional multiple)
177
+ command :shell do |c|
178
+ c.action do |global, options, args|
179
+ Nib::Shell.execute(args)
180
+ end
181
+ end
182
+
183
+ desc 'Download the latest version of the nib tool'
184
+ command :update do |c|
185
+ c.action do |global, options, args|
186
+ Nib::Update.execute(args)
187
+ end
188
+ end
189
+
190
+ exit run(ARGV)
@@ -0,0 +1,113 @@
1
+ [
2
+ {
3
+ "name": "bundle",
4
+ "type": "wrap",
5
+ "short_description": "Run bundle for the given service",
6
+ "long_description": "",
7
+ "options": [],
8
+ "service_options": "--no-deps"
9
+ },
10
+ {
11
+ "name": "codeclimate",
12
+ "type": "custom",
13
+ "short_description": "Run codeclimate againt the current working directory",
14
+ "long_description": "",
15
+ "options": [],
16
+ "service_options": "--no-deps"
17
+ },
18
+ {
19
+ "name": "console",
20
+ "type": "custom",
21
+ "short_description": "Start a REPL session for the given service",
22
+ "long_description": "This command will try to detect the applications environment (ie. rails console or bundle console)\nand start the most appropriate REPL possible. It's possible to directly override this behaviour by\nsupplying an executable file at $pwd/bin/console.",
23
+ "options": [],
24
+ "service_options": ""
25
+ },
26
+ {
27
+ "name": "debug",
28
+ "type": "custom",
29
+ "short_description": "Connect to a running byebug server for a given service",
30
+ "long_description": "This command requires a little extra setup.\n\n- The byebug server must be running inside of a web service\n- The RUBY_DEBUG_PORT must be defined in docker-compose.yml for the service\n- The debug port must be exposed by the service",
31
+ "options": [],
32
+ "service_options": ""
33
+ },
34
+ {
35
+ "name": "exec",
36
+ "type": "custom",
37
+ "short_description": "Attach an interactive shell session to a running container",
38
+ "long_description": "",
39
+ "options": [],
40
+ "service_options": ""
41
+ },
42
+ {
43
+ "name": "guard",
44
+ "type": "wrap",
45
+ "short_description": "Run the guard command for the given service",
46
+ "long_description": "",
47
+ "options": [],
48
+ "service_options": ""
49
+ },
50
+ {
51
+ "name": "rails",
52
+ "type": "wrap",
53
+ "short_description": "Run the rails command for the given service",
54
+ "long_description": "",
55
+ "options": [],
56
+ "service_options": ""
57
+ },
58
+ {
59
+ "name": "rake",
60
+ "type": "wrap",
61
+ "short_description": "Run the rake command for the given service",
62
+ "long_description": "",
63
+ "options": [],
64
+ "service_options": ""
65
+ },
66
+ {
67
+ "name": "rspec",
68
+ "type": "wrap",
69
+ "short_description": "Runs the rspec command for the given service",
70
+ "long_description": "",
71
+ "options": [],
72
+ "service_options": ""
73
+ },
74
+ {
75
+ "name": "rubocop",
76
+ "type": "wrap",
77
+ "short_description": "Runs the rubocop command for the given service",
78
+ "long_description": "",
79
+ "options": [],
80
+ "service_options": "--no-deps"
81
+ },
82
+ {
83
+ "name": "run",
84
+ "type": "custom",
85
+ "short_description": "Wraps normal 'docker-compose run' to ensure that --rm is always passed",
86
+ "long_description": "",
87
+ "options": [],
88
+ "service_options": ""
89
+ },
90
+ {
91
+ "name": "setup",
92
+ "type": "custom",
93
+ "short_description": "Runs application specific setup for the given service",
94
+ "long_description": "By default the setup command will execute 'bundle install && rake db:create db:migrate'.\n\nThis behavior can be overriden by providing an executable file in the project at $pwd/bin/setup.\nAdditionally the setup process can be augmented by providing either $pwd/bin/setup.before or\n$pwd/bin/setup.after. This allows for extending the default behavior without having to redefine it.",
95
+ "options": []
96
+ },
97
+ {
98
+ "name": "shell",
99
+ "type": "custom",
100
+ "short_description": "Start a shell session in a one-off service container",
101
+ "long_description": "",
102
+ "options": [],
103
+ "service_options": ""
104
+ },
105
+ {
106
+ "name": "update",
107
+ "type": "custom",
108
+ "short_description": "Download the latest version of the nib tool",
109
+ "long_description": "",
110
+ "options": [],
111
+ "service_options": ""
112
+ }
113
+ ]
@@ -0,0 +1,12 @@
1
+ version: '2'
2
+
3
+ services:
4
+ codeclimate:
5
+ image: codeclimate/codeclimate
6
+ environment:
7
+ - CODECLIMATE_CODE=$PWD
8
+ volumes:
9
+ - $PWD:/code
10
+ - $PWD:$PWD
11
+ - /var/run/docker.sock:/var/run/docker.sock
12
+ - /tmp/cc:/tmp/cc
@@ -0,0 +1,118 @@
1
+ ---
2
+ - :names:
3
+ - :d
4
+ :type: :switch
5
+ :commands:
6
+ - :exec
7
+ - :run
8
+ :options:
9
+ :negatable: false
10
+ :desc: 'Detached mode: Run container in the background, print new container name.'
11
+ - :names:
12
+ - :no-deps
13
+ :type: :switch
14
+ :commands:
15
+ - :run
16
+ :options:
17
+ :negatable: false
18
+ :desc: Don't start linked services.
19
+ - :names:
20
+ - :service-ports
21
+ :type: :switch
22
+ :commands:
23
+ - :run
24
+ :options:
25
+ :negatable: false
26
+ :desc: Run command with the service's ports enabled and mapped to the host
27
+ - :names:
28
+ - :privileged
29
+ :type: :switch
30
+ :commands:
31
+ - :exec
32
+ :options:
33
+ :negatable: false
34
+ :desc: Give extended privileges to the process.
35
+ - :names:
36
+ - :T
37
+ :type: :switch
38
+ :commands:
39
+ - :exec
40
+ - :run
41
+ :options:
42
+ :negatable: false
43
+ :desc: Disable pseudo-tty allocation. By default `docker-compose run` allocates
44
+ a TTY.
45
+ - :names:
46
+ - :name
47
+ :type: :flag
48
+ :commands:
49
+ - :run
50
+ :options:
51
+ :arg_name: NAME
52
+ :desc: Assign a name to the container
53
+ :multiple: false
54
+ :type: &1 !ruby/class 'String'
55
+ - :names:
56
+ - :entrypoint
57
+ :type: :flag
58
+ :commands:
59
+ - :run
60
+ :options:
61
+ :arg_name: CMD
62
+ :desc: Override the entrypoint of the image.
63
+ :multiple: false
64
+ :type: *1
65
+ - :names:
66
+ - :e
67
+ :type: :flag
68
+ :commands:
69
+ - :run
70
+ :options:
71
+ :arg_name: KEY=VAL
72
+ :desc: Set an environment variable
73
+ :multiple: true
74
+ :type: *1
75
+ - :names:
76
+ - :u
77
+ - :user
78
+ :type: :flag
79
+ :commands:
80
+ - :exec
81
+ - :run
82
+ :options:
83
+ :arg_name: '""'
84
+ :desc: Run as specified username or uid
85
+ :multiple: false
86
+ :type: *1
87
+ - :names:
88
+ - :p
89
+ - :publish
90
+ :type: :flag
91
+ :commands:
92
+ - :run
93
+ :options:
94
+ :arg_name: "[]"
95
+ :desc: Publish a container's port(s) to the host
96
+ :multiple: false
97
+ :type: !ruby/class 'Array'
98
+ - :names:
99
+ - :workdir
100
+ :type: :flag
101
+ :commands:
102
+ - :run
103
+ :options:
104
+ :arg_name: '""'
105
+ :desc: Working directory inside the container
106
+ :multiple: false
107
+ :type: *1
108
+ - :names:
109
+ - :index
110
+ :type: :flag
111
+ :commands:
112
+ - :exec
113
+ :options:
114
+ :arg_name: index
115
+ :desc: 'index of the container if there are multiple instances of a service [default:
116
+ 1]'
117
+ :multiple: false
118
+ :type: *1
@@ -0,0 +1,9 @@
1
+ module CoreExtensions
2
+ module Hash
3
+ def symbolize_keys!
4
+ map { |k, v| [k.to_sym, v] }.to_h
5
+ end
6
+ end
7
+ end
8
+
9
+ Hash.include CoreExtensions::Hash
@@ -0,0 +1,29 @@
1
+ require 'nib/version'
2
+
3
+ require 'core_extensions/hash'
4
+
5
+ require 'nib/options'
6
+ require 'nib/options/augmenter'
7
+ require 'nib/options/parser'
8
+
9
+ require 'nib/command'
10
+ require 'nib/check_for_update'
11
+ require 'nib/unrecognized_help'
12
+ require 'nib/code_climate'
13
+ require 'nib/console'
14
+ require 'nib/debug'
15
+ require 'nib/exec'
16
+ require 'nib/run'
17
+ require 'nib/setup'
18
+ require 'nib/shell'
19
+ require 'nib/update'
20
+
21
+ module Nib
22
+ GEM_ROOT = File.expand_path('../..', __FILE__)
23
+
24
+ module_function
25
+
26
+ def load_config(command, file_name)
27
+ File.read("#{GEM_ROOT}/config/commands/#{command}/#{file_name}")
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ class Nib::CheckForUpdate
2
+ def self.execute(_, _)
3
+ return if installed == latest
4
+
5
+ puts <<~MESSAGE
6
+
7
+ An update is available for nib: #{latest}
8
+ Use 'nib update' to pull the latest version
9
+ MESSAGE
10
+ end
11
+
12
+ def self.installed
13
+ Nib::VERSION
14
+ end
15
+
16
+ def self.latest
17
+ `wget -qO- https://raw.githubusercontent.com/technekes/nib/latest/VERSION`
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ require 'tempfile'
2
+
3
+ class Nib::CodeClimate
4
+ include Nib::Command
5
+
6
+ def self.execute(args, options = '')
7
+ # Discard service name because codeclimate is run on local path
8
+ args.shift
9
+
10
+ new(nil, args.join(' '), options).execute
11
+ end
12
+
13
+ def script
14
+ @script ||= <<~SCRIPT
15
+ docker-compose \
16
+ -f #{compose_file.path} \
17
+ run \
18
+ --rm \
19
+ codeclimate \
20
+ #{command}
21
+ SCRIPT
22
+ end
23
+
24
+ private
25
+
26
+ def config
27
+ @config ||= Nib.load_config(:codeclimate, 'docker-compose.yml')
28
+ end
29
+
30
+ def compose_file
31
+ @compose_file ||= Tempfile.open('compose') do |file|
32
+ file.tap { |f| f.write(config) }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ module Nib::Command
2
+ def self.included(base)
3
+ base.instance_eval do
4
+ attr_reader :service, :command, :options
5
+
6
+ extend ClassMethods
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+ def execute(args, options = '')
12
+ new(args.shift, args.join(' '), options).execute
13
+ end
14
+ end
15
+
16
+ def initialize(service, command, options = '')
17
+ @service = service
18
+ @command = command
19
+ @options = options
20
+ end
21
+
22
+ def execute
23
+ exec(script)
24
+ end
25
+
26
+ def script
27
+ @script ||= <<~SCRIPT
28
+ docker-compose \
29
+ run \
30
+ --rm \
31
+ #{options} \
32
+ #{service} \
33
+ #{command}
34
+ SCRIPT
35
+ end
36
+ end
@@ -0,0 +1,67 @@
1
+ class Nib::Console
2
+ include Nib::Command
3
+
4
+ IRBRC = <<~'IRB'.freeze
5
+ require \"rubygems\"
6
+ require \"irb/completion\"
7
+ require \"irb/ext/save-history\"
8
+ # irb configuration
9
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
10
+ IRB.conf[:AUTO_INDENT] = true
11
+ # irb history
12
+ IRB.conf[:EVAL_HISTORY] = 10
13
+ IRB.conf[:SAVE_HISTORY] = 1000
14
+ IRB.conf[:HISTORY_FILE] = \"#{Dir.pwd}/tmp/irb_history\"
15
+ IRB
16
+
17
+ PRYRC = 'Pry.config.history.file = \"#{Dir.pwd}/tmp/irb_history\"'.freeze
18
+
19
+ SCRIPT = <<~SH.freeze
20
+ echo '#{IRBRC}' > /root/.irbrc
21
+ echo '#{PRYRC}' > /root/.pryrc
22
+ has_pry=false
23
+ has_boot=false
24
+ if hash pry 2>/dev/null ; then
25
+ has_pry=true
26
+ fi
27
+ if [ -f config/boot.rb ]; then
28
+ has_boot=true
29
+ fi
30
+ if [ -f bin/console ]; then
31
+ bin/console
32
+ elif [ -f bin/rails ]; then
33
+ rails console
34
+ elif [ \\$has_boot = true ] && [ \\$has_pry = true ]; then
35
+ pry -r ./config/boot
36
+ elif [ \\$has_boot = true ]; then
37
+ irb -r ./config/boot
38
+ elif [ \\$has_pry = true ]; then
39
+ bundle config console pry
40
+ bundle console
41
+ else
42
+ bundle console
43
+ fi
44
+ SH
45
+
46
+ def execute
47
+ system('mkdir', '-p', './tmp')
48
+ super
49
+ end
50
+
51
+ def script
52
+ @script ||= <<~SCRIPT
53
+ docker-compose \
54
+ run \
55
+ --rm \
56
+ -e HISTFILE=./tmp/shell_history \
57
+ #{service} \
58
+ #{command}
59
+ SCRIPT
60
+ end
61
+
62
+ private
63
+
64
+ def command
65
+ "/bin/sh -c \"#{SCRIPT}\""
66
+ end
67
+ end
@@ -0,0 +1,43 @@
1
+ require 'yaml'
2
+
3
+ class Nib::Debug
4
+ include Nib::Command
5
+
6
+ def execute
7
+ raise 'RUBY_DEBUG_PORT not specified. See "nib debug help"' unless port
8
+
9
+ puts "Connecting to server via:\n> #{command}"
10
+
11
+ super
12
+ end
13
+
14
+ private
15
+
16
+ def command
17
+ "byebug -R #{host}:#{port}"
18
+ end
19
+
20
+ def host
21
+ if ENV.key?('DOCKER_HOST_URL') && ENV['DOCKER_HOST_URL'] != ''
22
+ URI.parse(ENV['DOCKER_HOST_URL']).host
23
+ else
24
+ `ip route | awk 'NR==1 {print $3}'`.chomp
25
+ end
26
+ end
27
+
28
+ def compose_file
29
+ @compose_file ||= File.read('docker-compose.yml')
30
+ end
31
+
32
+ def port
33
+ regexp = /
34
+ #{service}: # start with the service key (web:)
35
+ (?:.|\n)*? # search through all characters including new lines
36
+ RUBY_DEBUG_PORT # target the env var we defined
37
+ \D* # expect non-numeric characters (':', ': ', '=', '="')
38
+ (?<port>\d+) # capture numeric value of the port
39
+ /x
40
+
41
+ compose_file.match(regexp)&.send(:[], :port)
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ class Nib::Exec
2
+ include Nib::Command
3
+
4
+ def script
5
+ @script ||= <<~SCRIPT
6
+ docker-compose \
7
+ exec \
8
+ #{options} \
9
+ #{service} \
10
+ /bin/sh -c "#{entrypoint}"
11
+ SCRIPT
12
+ end
13
+
14
+ def action
15
+ command.to_s.empty? ? '' : "-c '#{command}'"
16
+ end
17
+
18
+ def entrypoint
19
+ "
20
+ if hash bash 2>/dev/null ; then
21
+ bash #{action}
22
+ elif hash ash 2>/dev/null ; then
23
+ ash #{action}
24
+ else
25
+ sh #{action}
26
+ fi
27
+ "
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Nib::Options
2
+ module_function
3
+
4
+ def config
5
+ @config ||= YAML.load_file("#{Nib::GEM_ROOT}/config/options.yml")
6
+ end
7
+
8
+ def options_for(type, name)
9
+ config.select { |option| option[type].include?(name) }
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Nib::Options::Augmenter
2
+ module_function
3
+
4
+ def augment(command)
5
+ Nib::Options.options_for(:commands, command.name).each do |option|
6
+ command.send(
7
+ option[:type],
8
+ option[:names],
9
+ option[:options]
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Nib::Options::Parser
2
+ module_function
3
+
4
+ def parse(raw_options)
5
+ raw_options.symbolize_keys!.map do |name, value|
6
+ option = Nib::Options.options_for(:names, name).first
7
+
8
+ send("parse_#{option[:type]}", name, value)
9
+ end.compact.join(' ')
10
+ end
11
+
12
+ def parse_switch(name, enabled)
13
+ return unless enabled
14
+
15
+ flag_for(name)
16
+ end
17
+
18
+ def parse_flag(name, values)
19
+ Array(values).map do |value|
20
+ "#{flag_for(name)} #{value}"
21
+ end
22
+ end
23
+
24
+ def flag_for(name)
25
+ name.length == 1 ? "-#{name}" : "--#{name}"
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ class Nib::Run
2
+ include Nib::Command
3
+ end
@@ -0,0 +1,26 @@
1
+ class Nib::Setup
2
+ include Nib::Command
3
+
4
+ SCRIPT = <<~SH.freeze
5
+ if [ -f bin/setup.before ]; then
6
+ bin/setup.before
7
+ fi
8
+
9
+ if [ -f bin/setup ]; then
10
+ bin/setup
11
+ else
12
+ gem install bundler
13
+ bundle install --jobs 4
14
+ fi
15
+
16
+ if [ -f bin/setup.after ]; then
17
+ bin/setup.after
18
+ fi
19
+ SH
20
+
21
+ private
22
+
23
+ def command
24
+ "/bin/sh -c \"#{SCRIPT}\""
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ class Nib::Shell
2
+ include Nib::Command
3
+
4
+ SCRIPT = <<~SH.freeze
5
+ if hash bash 2>/dev/null ; then
6
+ bash
7
+ elif hash ash 2>/dev/null ; then
8
+ ash
9
+ else
10
+ sh
11
+ fi
12
+ SH
13
+
14
+ def execute
15
+ system('mkdir', '-p', './tmp')
16
+ super
17
+ end
18
+
19
+ def script
20
+ @script ||= <<~SCRIPT
21
+ docker-compose \
22
+ run \
23
+ --rm \
24
+ -e HISTFILE=./tmp/shell_history \
25
+ #{service} \
26
+ #{command}
27
+ SCRIPT
28
+ end
29
+
30
+ private
31
+
32
+ def command
33
+ "/bin/sh -c \"#{SCRIPT}\""
34
+ end
35
+ end
@@ -0,0 +1,12 @@
1
+ class Nib::UnrecognizedHelp
2
+ def self.execute(_, _)
3
+ puts <<~MESSAGE
4
+
5
+ Note:
6
+ Unrecognized commands will be delegated to docker-compose.
7
+ For example the following are equivalent:
8
+ nib start
9
+ docker-compose start
10
+ MESSAGE
11
+ end
12
+ end
@@ -0,0 +1,31 @@
1
+ require 'tempfile'
2
+
3
+ class Nib::Update
4
+ include Nib::Command
5
+
6
+ def script
7
+ @script ||= <<~SCRIPT
8
+ docker-compose \
9
+ -f #{compose_file.path} \
10
+ pull
11
+ SCRIPT
12
+ end
13
+
14
+ private
15
+
16
+ def config
17
+ <<~CONFIG
18
+ version: '2'
19
+
20
+ services:
21
+ nib:
22
+ image: technekes/nib:latest
23
+ CONFIG
24
+ end
25
+
26
+ def compose_file
27
+ @compose_file ||= Tempfile.open('compose') do |file|
28
+ file.tap { |f| f.write(config) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Nib
2
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).freeze
3
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nib
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Allen
8
+ - Zach Blankenship
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gli
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 2.14.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 2.14.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: pry
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: serverspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: guard
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: codeclimate-test-reporter
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: 'nib is a docker-compose wrapper geared towards Ruby/Rails development.
113
+
114
+ '
115
+ email:
116
+ - noreply@technekes.com
117
+ executables:
118
+ - nib
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - VERSION
123
+ - bin/nib
124
+ - config/commands.json
125
+ - config/commands/codeclimate/docker-compose.yml
126
+ - config/options.yml
127
+ - lib/core_extensions/hash.rb
128
+ - lib/nib.rb
129
+ - lib/nib/check_for_update.rb
130
+ - lib/nib/code_climate.rb
131
+ - lib/nib/command.rb
132
+ - lib/nib/console.rb
133
+ - lib/nib/debug.rb
134
+ - lib/nib/exec.rb
135
+ - lib/nib/options.rb
136
+ - lib/nib/options/augmenter.rb
137
+ - lib/nib/options/parser.rb
138
+ - lib/nib/run.rb
139
+ - lib/nib/setup.rb
140
+ - lib/nib/shell.rb
141
+ - lib/nib/unrecognized_help.rb
142
+ - lib/nib/update.rb
143
+ - lib/nib/version.rb
144
+ homepage: https://github.com/technekes/nib
145
+ licenses: []
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.6.8
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: The tip of the pen (compose)
168
+ test_files: []