Capistrano::Container::Db Gem Version

Helps managing databases on local and remote stages, also on remote docker container for Capistrano 3.x.

This project is in an early stage but helps me alot dealing with my container deployments and keeps my code clean. It is not only ment for mysql, but at the moment there only supports mysql, feel free to contribute =)

This gem depends on capistrano-container.

Installation

Add this line to your application's Gemfile:

gem 'capistrano', '>= 3.0.0'
gem 'capistrano-container-db'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano-container-db

Dont forget to require the module in your Capfile:

require 'capistrano/container/db'

Usage

definition

To define and register a container do the following in your stage config or deploy.rb:

...

# for usage in conjunction with capistrano-container
server('www.example.com', user: 'root', roles: %w{web})

container 'db',  roles: %w{db},
                 container_id: 'website_company_beta_db',
                 server: ['www.example.com']

# here the capistrano-container-db config comes

set :db_is_container, true
set :db_user, 'wordpress'
set :db_pass, 'wordpress'
set :db_name, 'my_wordpress_db_inside_docker'

...

This configures the db access for the db container. If 'db_is_container' is true, the gem uses the capistrano-container extension to select the container by name 'fetch(:db_container_name)' (defaults to 'db').

If the stage name is equal ':local', the gem runs export/import on local host.

If the stage is unequal ':local' and the param ':db_is_container' is false, the export/import will run on remote host.

commandline tasks

cap db:export               # export a local, remote or remote container mysql db
cap db:import               # import a local, remote or remote container mysql db

default configuration

set :db_user, 'root'
set :db_pass, ''
set :db_name, ''
set :db_remote_dump, '/tmp/dump.sql'
set :db_local_dump, 'config/db/dump.sql'
set :db_is_container, false
set :db_container_name, 'db'
set :local_stage_name, :local
set :filter_on_import, lambda{ |sql_dump| return sql_dump }

TODO

  • Implement adapter pattern for other db engines.
  • Write tests.

Changes

Version 0.0.3

  • remove debug expression

Version 0.0.2

  • autodetect local and remote container

Version 0.0.1

  • Initial release

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request