nib
is a convenience wrapper fordocker-compose
- originally designed with Ruby/Rails developers in mind but has features that would be helpful for any developer
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:
- A Ruby gem that relies on gli for defining it's CLI interface following the naming convention
bin/nib-*
- It puts a file on the
LOAD_PATH
that ends with_plugin.rb
following the naming convention./lib/nib_*_plugin.rb
- Implements
#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
desc 'Say hello nib-ruby'
command :console 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
.
Opinionated secrets management.
- Create an encryption key for a project (directory) and push it to an S3 bucket
- Pull an encryption key from an S3 bucket for an existing project
- Convenience wrappers around encryption and decryption (uses
openssl
and before mentioned key)
COMMANDS
...
crypt-init - Initialize a project (create or pull secret key)
...
decrypt - Decrypt a file
encrypt - Encrypt a file
...
Integrates commands with Heroku
- Uses the directory name to infer a Heroku application name (following Technekes convention)
- Accepts an environment flag
- If non-development environment flag is specified will shell out to Heroku CLI to integrate a shell session or logs
COMMANDS
...
logs - Access logs for the speified service or Heroku application
...
shell - Start a shell session in a one-off service container
...
Let's create nib-ruby
!
# fire up a Ruby container
docker run --rm -it -v $PWD:$PWD -w $PWD ruby:alpine ash
# scaffold a new gem
bundle gem --test=none --mit --no-coc --bin nib-ruby
exit # container
cd nib-ruby
# edit the executable
mv exe/nib-ruby bin/
rm nib-ruby.gemspec
cp ../nib-ruby.gemspec .
vi bin/nib-ruby
# create plugin detection file
vi lib/nib_ruby_plugin.rb
# build the gem
docker run --rm -it -v $PWD:$PWD -w $PWD ruby:alpine rake build
# install the gem
gem install pkg/nib-ruby-0.1.0.gem
# does it work?! 🤞
nib help
nib hello