:remote_cache_from_local for Capistrano 2
This gem allows you to deploy a project using Capistrano 2 directly from the local git repo to the deployment server, removing your reliance on a central, possibly-unavailable SCM service. It supports git submodules in the same way — your local checkouts of the project's submodules will be used to clone on the deployment server.
It piggybacks on the SSH connection that Capistrano sets up, so you do not need
to separately configure it. Besides cloning from the local checkout, it
otherwise behaves the same as Capistrano's built-in :remote_cache strategy.
Alternatives
Capistrano's :copy strategy can also deploy from the local working copy, at
the cost of re-copying the entire codebase from the local machine to the server
on every deploy. This strategy takes advantage of git to only transfer what has
changed.
Installation
Add this line to your application's Gemfile:
gem 'capistrano2-remote_cache_from_local', require: false
And then execute:
$ bundle
Or install it yourself as:
$ gem install capistrano2-remote_cache_from_local
Usage
In your deploy.rb, add this line:
require 'capistrano/remote_cache_from_local'
Remove anywhere you have a :repository, :scm, or :deploy_via variable
set. This strategy needs to specify those values for you.
# set :repository, 'git+shh://git.example.com/foo.git'
# set :scm, :git
# set :deploy_via, :remote_cache
Set any of the following variables if you need a value other than the defaults listed here:
# The path to the root of the local working copy, relative to this project's root.
set :local_repository, '.'
# The port used for the temporary git daemon.
set :git_tunnel_local_port, 50123
# The port used for the remote side of the temporary SSH tunnel used for cloning
set :git_tunnel_remote_port, 50123
# The PID file used to keep track of the git daemon.
set :git_daemon_pid_file, 'tmp/git-daemon.pid'
# To see the details of the git operations, make this true
set :scm_verbose, false
To enable submodules to be cloned from the local copies, you must also disable Capistrano's built-in submodule support:
# Disable built-in submodule support
set :git_enable_submodules, false
# Enable remote_cache_from_local's submodule support
set :git_local_enable_submodules, true
Security
In order to make the local repo available to clone from the server, the strategy
starts a temporary git-daemon. It listens only on localhost — connections
from the server are forwarded via an SSH tunnel — so it is not visible to the
network at large.
However, because connections to git-daemon are not authenticated, this temporary daemon is accessible to any process running on the deploying machine. A malicious process running as a different user could gain read access to the deployed application's source code. So don't use this if you don't trust the machine you are deploying from.
Development
After checking out the repo, run bundle install to install dependencies. Then,
run rake spec to run the tests.
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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/cdd/capistrano2-remote_cache_from_local.
License
The gem is available as open source under the terms of the MIT License.
Future work
- An alternate implementation for Capistrano 3.