Openbox
The zero-configuration Ruby container entry-point.
Installation
Add this line to your application's Gemfile:
gem 'openbox'
And then execute:
$ bundle install
Usage
Create openbox
binstus to allow container use it as entrypoint
bundle binstubs openbox
Modify your Dockerfile
to use it as entrypoint
ENTRYPOINT ["bin/openbox"]
CMD ["server"]
Commands
The commands are pre-defined for the Rack and Rails applications.
Name | Enabled Condition | Description |
---|---|---|
server |
rails or rack |
Start application server |
rake |
rails or rake |
Run rake tasks |
console |
rails |
Start rails console |
migrate |
rails |
Run database migration |
seed |
rails |
Run database seed |
sidekiq |
sidekiq |
Run sidekiq server |
Customize Commands
When openbox
execute, the lib/openbox/commands/*/**.rb
will be scanned and require before started.
We can register new command by adding files to lib/openbox/commands
directory.
# lib/openbox/commands/daemon.rb
class Daemon < Openbox::Command
def execute
exec('bundle exec my-daemon')
end
end
Openbox::Entrypoint.register Daemon, :daemon, :daemon, 'Run a daemon'
The Rails are not loaded to speed up bootstrap, if you need Rails please load by yourself.
Environments
Name | Example | Description |
---|---|---|
AUTO_MIGRATION |
yes |
When present, the migrate will run before server started |
DATABASE_URL |
postgres://user:pass@postgres/dbname |
When pg or mysql2 gem present, Openbox will use it to ensure database connection |
SWARM_SECRETS |
app-env |
List the Docker Swarm secret names to load as environment file |
Environment Loader
To rotate secrets easier, we may not use Rails credentials but inject secrets via the environment variables.
Openbox provides a before hook before the command is executed and load the environments from a security source.
Docker Swarm
When use Docker Swarm, the secret will put into /run/secrets
directory, you can load these files via Dotenv.
# Docker Swarm Stack
services:
application:
environment:
- SWARM_SECRETS=sahred-secret,applicate-secret
# ...
Roadmap
-
config/openbox.rb
config - Customize command
- Database connection check
- PostgreSQL support
- MySQL support
- Run Web Server
-
rails server
-
rackup -o 0.0.0.0
-
- Rake Task support
- Sidekiq support
- Rails capability
-
openbox console
torails console
-
openbox migrate
torails db:migrate
-
openbox seed
torails db:seed
- Use
AUTO_MIGRATION
to run migration before server started
-
- Load Secrets as Environment
- AWS Secrets Manager
- Hashicorp Valut
- Docker Swarm Secrets
Development
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.
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 the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/openbox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Code of Conduct
Everyone interacting in the Openbox project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.