Capistrano tasks for docker build
on remote server.
These tasks depends on Git. And so remote server must have git command.
Add this line to your application's Gemfile:
gem 'capistrano-dockerbuild'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capistrano-dockerbuild
Add require
and install_plugin
to Capfile.
require 'capistrano/dockerbuild'
install_plugin Capistrano::Dockerbuild
Use common variables
- repo_url
- branch
name | required | default | desc |
---|---|---|---|
docker_build_server_host | yes | nil | Build server hostname or SSH::Host object |
docker_build_base_dir | yes | nil | Repository clone to here, and execute build command here |
docker_registry | no | nil | Docker registry hostname. if use DockerHub, keep nil |
docker_build_cmd | no | -> { [:docker, "build", "-t", fetch(:docker_tag_full), "."] } |
Execute command for image building |
docker_repository_name | no | -> { fetch(:application) } |
Use by docker tag {{docker_repository_name}}:tag |
docker_tag | no | -> { fetch(:branch) } |
Use by docker tag repository:{{docker_tag}} |
docker_tag_full | no | -> { #{fetch(:docker_repository_name)}:#{fetch(:docker_tag)}" } |
Use by docker tag {{docker_tag_full}} |
docker_remote_repository_name | no | -> { fetch(:docker_repository_name) } |
Use by docker push docker_registry/{{docker_remote_repository_name}}:docker_remote_tag |
docker_remote_tag | no | -> { fetch(:docker_tag) } |
Use by docker push docker_registry/docker_remote_repository_name:{{docker_remote_tag}} |
docker_remote_tag_full | no | -> { "#{fetch(:docker_registry) &.+ "/"}#{fetch(:docker_remote_repository_name)}:#{fetch(:docker_remote_tag)}" } |
Use by docker push {{docker_remote_tag_full}} |
keep_docker_image_count | no | 10 | |
git_http_username | no | nil | See below |
git_http_password | no | nil | See below |
If you want to use GitHub Apps installation access token or something to authorize repository access using HTTPS protocol. You can set variables in your config/deploy.rb:
set :git_http_username, -> { ENV["GIT_HTTP_USERNAME"] }
set :git_http_password, -> { ENV["GIT_HTTP_PASSWORD"] }
set :repo_url, -> do
if fetch(:git_http_username) && fetch(:git_http_password)
"https://github.com/owner/repo.git"
else
"git@github.com:owner/repo.git"
end
end
Update remote URL always if you set proper value to all of repo_url
, git_http_username
, and git_http_password
.
- Ensure
#{docker_build_base_dir}
- Ensure git reachable
- Clone repo to
#{docker_build_base_dir}
as mirror
- git remote update
#{docker_build_base_dir}
- Create
#{branch}
worktree to#{docker_tag}-#{timestamp}
- With in worktree dir, execute
#{docker_build_cmd}
- Clear worktree
- docker tag
#{docker_tag_full}
#{docker_remote_tag_full}
- docker push
#{docker_remote_tag_full}
- Remove docker images
- Leave
keep_docker_image_count
images - Remove from the oldest image
docker:push => docker:build => docker:update_mirror => docker:clone => docker:check
After checking out the repo, run bin/setup
to install dependencies. 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 tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/reproio/capistrano-dockerbuild.
The gem is available as open source under the terms of the MIT License.