Para Capistrano 3.0, utilizo el siguiente:
En mi 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
Y en mi 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'
Todo el código importante está en el método de la estrategia release
, que usa git archive
para archivar solo un subdirectorio del repositorio, luego usa el --strip
a rgument al tar
para extraer el archivo en el nivel correcto.
ACTUALIZACIÓN
A partir de Capistrano 3.3.3, ahora se puede utilizar la variable de configuración :repo_tree
, lo que hace que esta respuesta obsoleta. Por ejemplo:
set :repo_url, 'https://example.com/your_repo.git'
set :repo_tree, 'relative/path/from/your/repo' # relative path to project root in repo
Ver http://capistranorb.com/documentation/getting-started/configuration.
¡Oh, cómo me gustaría poder enviarte unas pintas de cerveza fresca! ¡¡Gracias!! – Nazar
Perfecto. Justo lo que necesitaba. ¡Gracias! – Matt
NB. Alguien leyendo, esto funciona si ya está utilizando remote_cache como su mecanismo: deploy_via (que se basa en el acceso SCM en el extremo del servidor). – jrg