Skip to content

Instantly share code, notes, and snippets.

@mitio
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitio/73f02d8e8fd89cd4ed90 to your computer and use it in GitHub Desktop.
Save mitio/73f02d8e8fd89cd4ed90 to your computer and use it in GitHub Desktop.
A custom Capistrano 3.x strategy that allows deployment from a Git subfolder

You can use this strategy to deploy your Rails app properly when it's located in a subfolder in the main repo.

Supports Capistrano 3.x (tested on 3.2.1).

Usage

  1. Place this file in lib/capistrano/git_subfolder_strategy.rb

  2. Add this line to your Capfile: require_relative 'lib/capistrano/git_subfolder_strategy'

  3. In your deploy.rb, set the following:

    set :git_strategy,  Capistrano::GitSubfolderStrategy
    set :git_subfolder, '/subfolder/to/deploy/from'
require 'capistrano/git'
module Capistrano
module GitSubfolderStrategy
include Capistrano::Git::DefaultStrategy
def release
super
full_repo_contents_folder = context.releases_path + "#{context.release_timestamp}-full"
subfolder_to_deploy = File.join(full_repo_contents_folder, fetch(:git_subfolder))
context.execute :mv, release_path, full_repo_contents_folder
context.execute :mv, subfolder_to_deploy, release_path
context.execute :rm, '-rf', full_repo_contents_folder
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment