Dockit
Dockit is an alternative composer for docker projects. Its (IMHO) advantage is that it is scriptable, and rather than a single yaml configuration file, each service has it's own configuration file (Dockit.yaml), as well as an optional Dockit.rb which can provide scriptable configuration (as Thor subcommands) for any phase of the build and deploy process.
Dockit is built on the Thor cli and the docker-api libraries.
Installation
$ gem install dockitUsage
- Create a top level deployment directory
- Create a sub-directory for each service
- Create a
Dockit.yamlfor each service (and optionally aDocit.rb.) - Optionally, create a top level
Dockit.rbsubcommand file to orchestrate the build and deployment of the services. - Run
dockitin the root directory for help.
Dockit.yaml
The sections of the config file map directly to the argument sent by the docker-api to the corresponding api endpoints (see docker api.)
The top level sections are:
buildcreaterun
At least one of the sections build or create are required. If their is no build section, the create section must specify an Image value. Note that most (all?) of the values specified in the run section can be specified in the create: HostConfig: instead.
Examples
Simple build
build:
t: my-imageExecuting dockit build in the directory containing the file above, will create an image from the Dockerfile in the same directory named my-image.
Then executing dockit start will create and run a container named my-image
Pre-generated (or docker hub) image
create:
Image: postgres
name: dbExecuting dockit build will do nothing. Executing dockit start will start run a container named db from the local (or docker hub postgresql image.
Using locals and environment variables
The yaml file is first processed by the ERB template library. The "bindings" passed to the template processor can be specified on the command line with the --locals (alias -l) option. Also, the command line option --env (alias -e) is passed as -<env> For example, given:
create:
Image: postgres
name: db<%= env %>
Env:
- MYVAR=<%= myval %>-
dockit startwill generate an error (myval not defined) -
dockit start -l myval:foowill start a container nameddbwith the environment variableMVARset tofoo. -
dockt start -l myval:foo -e testwill start a container nameddb-test
Dockit.rb
The dockit.rb file can be used to add new subcommands to the cli on a project-wide or per-service basis. For per-service subcommands, the defined class name should be the "classified" directory name, for the project-wide, it should be named All. If the class inherits from SubCommand instead of Thor, it will inherit two useful methods:
-
invoke_default(service)will run the same-named (or specified) dockit command on the specified service. -
invoke_service(service)will run the same-named (or specifed) subcommand from theDockit.rbfor the specified service. -
invoke_git(service)will run the same-name (or specifed) subcommand from theDockit.rbfor the specified service after checking out the git repository for the service as a gzip archive torepos.tar.tz. By default it used themasterbranch. Note that thereposkey must be set in the services yaml file.
For example:
class All < SubCommand
desc 'build', 'build all images'
def build
invoke_service 'app'
invoke_default 'db'
end
endWould run the build method from the file app/Dockit.rb and then create a second image using the options from db/Dockit.yaml.
DigitalOcean integration
If the droplet_kit gem is found at runtime, the do service be implemented. see dockit help do for available commands.
Running as a docker image
If you don't want to install ruby, etc., the docker image is also available rom docker hub as cybercode/dockit. You can create your own version of the docker image from the source code with docker build -t dockit . (or rake docker). The Dockerfile has dockit as the entrypoint, so you can pass dockit arguments on the command-line. e.g.:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:/app dockit helpThe Github boilerplate
Development
After checking out the repo, run bin/setup to install dependencies. Then, 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 to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
- Fork it ( https://github.com/cybercode/dockit/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am [comment]) - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request