Pour Capistrano 3.0, j'utilise ce qui suit :
Dans mon Capfile
:
# Define a new SCM strategy, so we can deploy only a subdirectory of our repo.
module RemoteCacheWithProjectRootStrategy
def test
test! " [ -f #{repo_path}/HEAD ] "
end
def check
test! :git, :'ls-remote', repo_url
end
def clone
git :clone, '--mirror', repo_url, repo_path
end
def update
git :remote, :update
end
def release
git :archive, fetch(:branch), fetch(:project_root), '| tar -x -C', release_path, "--strip=#{fetch(:project_root).count('/')+1}"
end
end
Et dans mon deploy.rb
:
# Set up a strategy to deploy only a project directory (not the whole repo)
set :git_strategy, RemoteCacheWithProjectRootStrategy
set :project_root, 'relative/path/from/your/repo'
Tout le code important est dans la stratégie release
qui utilise la méthode git archive
pour archiver uniquement un sous-répertoire du repo, puis utilise la fonction --strip
argument pour tar
pour extraire l'archive au bon niveau.
UPDATE
À partir de Capistrano 3.3.3, vous pouvez désormais utiliser la fonction :repo_tree
ce qui rend cette réponse obsolète. Par exemple :
set :repo_url, 'https://example.com/your_repo.git'
set :repo_tree, 'relative/path/from/your/repo' # relative path to project root in repo
Voir http://capistranorb.com/documentation/getting-started/configuration .