Invoking docker-compose commands during deployment and on demand.
Uses a flat directory approach (no shared/releases folder) to be able to simply specify service directories to build without injecting variables for the release date or switching symlinks.
A git submodule install is executed after fetching and checking out the git repo.
To get started you need to have:
1. A project with existing docker-compose.yml file
2. A capistrano >= 3.3 version already hooked to your project
First - add the following line to your gemfile:
gem 'capistrano-docker', github: 'aCandidMind/capistrano-docker-compose'
Next, add the following to your Capfile:
require 'capistrano/docker-compose'
Optionally, specify the options in your config/stage/deploy.rb
file, however the defaults provided should work out-of-the-box.
set :docker_role - the name of the role which is used for Docker host, defaults to ':web'
set :docker_compose_project_name - prefix for the container names, defaults to nil, so it defaults to the directory name the project is at
set :docker_compose_remove_after_stop - should we remove the containers after stopping them, defaults to true
set :docker_compose_remove_volumes - should we remove associated volumes with containers during their removal (rm -v option), default: true
set :docker_compose_build_services - specify services which should be built / ran with docker-compose (ex. docker-compose build web), default: none
set :docker_pass_env - the list of the environment variables that should be passed over to the docker-compose commands from command line (they are validated wether they exists before they are used) (ex: PULL_REQUEST_ID=10 cap staging docker:compose:start )
This is how deployment is handled:
1. validate wether we passed over the environment variables described in "docker_pass_env"
2. it runs docker-compose up with project_name and detached options
By default containers are not stopped automatically. You can use the "docker:compose:stop" task to do that (just remember that this will remove any compose-created containers unless you change the "docker_compose_remove_after_stop" option).
Run
cap STAGE docker_compose:deploy # Perform a git checkout deploy, then build & (re)start through docker-compose
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.
- create the app directory on first deploy if it's not there.
The docker-compose task wrapping is heavily inspired by netguru/capistrano-docker and the flat directory approach copied almost completely from rossriley/capistrano-simplegit.
Both are great projects but on their own didn't work out for me in their current form. I will try to get in touch with the author of capistrano-docker whether he is interested in a flat directory approach.
Bug reports and pull requests are welcome on GitHub at https://github.com/aCandidMind/capistrano-docker-compose.
The gem is available as open source under the terms of the MIT License.