nib
is a docker-compose
wrapper geared towards Ruby/Rails development.
To install:
> gem install nib
If there is an update available it's a good idea to remove the current version before installing the new version. If you skip the uninstall then gem update nib
will install the new version along side the existing version.
> gem uninstall -ax nib && gem install nib
... or let nib
take care of that for your.
> nib update
nib
can be used as a replacement for docker-compose
any commands that it does not recognize will be delegated to docker-compose
.
The commands provided by nib
are intended to provide a convenient and practical workflow for development, for example:
> nib shell web
root@fd80bbc4ab5a:/usr/src/app#
nib
will start up a container for the web
service and drop you into an interactive shell session (bash
, ash
or sh
) depending on which shell is available.nib
will also hook up a history file for your shell session (relative to the current project). This means that you will be able to use the history (up arrow) in future shell sessions, something that is not available with vanilla docker/docker-compose!nib
will ensure that the container is removed after you finish with the shell sessionSome commands can have their behavior changed relative to a particular project. As an example - nib console
expects a Ruby like environment (rails console
or pry
etc) by default but it can be augmented by adding a custom script on the host system ($pwd/bin/console
)
Other commands like nib rake
or nib guard
behave as expected without the option to change the behavior.
For additional information and a list of supported commands review the help system.
> nib help
nib can help facilitate remote debugging of a running byebug server inside of a rails application. In order to make this work there are a couple of steps you'll need to take first.
Add the byebug
gem to your Gemfile if it's not already present.
# Gemfile
gem 'byebug'
Enable byebug server for development. This will default the port to 9005 but that can be overridden by setting the RUBY_DEBUG_PORT
environment variable (see below).
# config/envrionments/development.rb
require 'byebug/core'
Byebug.start_server '0.0.0.0', (ENV.fetch 'RUBY_DEBUG_PORT', 9005).to_i
Expose the desired port and specify the RUBY_DEBUG_PORT
environment variable (overrides the default).
# docker-compose.yml
web:
...
ports:
- "3001:3001"
environment:
- "RUBY_DEBUG_PORT=3001"
Once all of this is in place and the web service is up and running (nib up
) you can use the debug
command to attach to the remote debugger.
> nib debug web
nib is pluggable via additional gems. The plugin system is loosely based on that of minitest extensions. There are three requirements for a nib plugin:
bin/nib-*
LOAD_PATH
that ends with _plugin.rb
following the naming convention ./lib/nib_*_plugin.rb
#applies?
, which allows the plugin to "self-select" (ie. was this command run in what appears to be an applicable project)As an example let's define a plugin for nib that caters to Ruby developers.
# ./bin/nib-ruby
#!/usr/bin/env ruby
command :hello do |c|
c.action do |_global_options, _options, _args|
puts 'from nib-ruby'
end
end
# ./lib/nib_ruby_plugin.rb
module Nib
module Ruby
def self.applies?
!Dir.glob('Gemfile').empty?
end
end
end
# ./nib-ruby.gemspec
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
...
If nib-ruby has been installed and a nib command is run from a directory containing a Gemfile
nib will append gli commands from bin/nib-ruby
.
This project includes rspec and serverspec to help facilitate execution of automated tests. Running the tests is as simple as:
nib build # the first time (you are using `nib` right?)
nib rspec gem
If you have added a new command you will want to regenerate the commands document. The following command should get that done:
docker run \
--rm \
-v $PWD:/usr/src/app \
-w /usr/src/app \
ruby:3.3.0 bin/update_docs
nib
is work of several contributors. You're encouraged to submit pull requests, propose features and discuss issues.
See CONTRIBUTING.
MIT License. See LICENSE for details.