Rake tasks for managing an application's Docker images
In your Gemfile
:
gem 'boathook', git: 'https://github.com/umd-lib/boathook', tag: 'main'
Then run bundle install
.
In your Rakefile
or *.rake
task file:
require 'boathook'
namespace :docker do
Boathook::DockerTasks.new do |t|
t.version = 'app-version'
t.image_specs = [
{
name: 'image-name',
dockerfile: 'path/to/Dockerfile', # defaults to 'Dockerfile'
context: 'path/to/context/dir' # defaults to '.'
}
# if your project has multiple Docker images to build, you can add
# additional image specs here
]
end
end
Now there are three tasks added to your project:
docker:tags
shows you the full Docker name:tag value for each image it will builddocker:build
builds the Docker imagesdocker:push
push the images to a remote repository
If the version
includes the string "dev", the tag will be "latest". Otherwise, it will be the value of version
.
In addition to tagging the image with the version, docker:build
also applies the following labels to the newly created image:
org.opencontainer.images.version
is the version as given in the constructor blockorg.opencontainer.images.revision
is the current git revision of the project, as determined by runninggit rev-parse HEAD
in the working directory
If you have jq installed, you can easily verify these labels by running:
docker image inspect image-name:tag | jq '.[].Config.Labels'
This library is built on top of Mattock, which itself is built on top of Rake. Combine these with the fact that Docker is heavily nautically themed, and you get: Boathook!
See the LICENSE file for license rights and limitations (Apache 2.0).