Đối Capistrano 3.0, tôi sử dụng như sau:
Trong tôi 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
Và trong tôi 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'
Tất cả các mã quan trọng là trong phương pháp chiến lược release
, sử dụng git archive
để chỉ lưu trữ một thư mục con của repo, sau đó sử dụng --strip
một rgument để tar
để trích xuất lưu trữ ở cấp độ phù hợp.
CẬP NHẬT
Tính đến Capistrano 3.3.3, bây giờ bạn có thể sử dụng các biến :repo_tree
cấu hình, mà làm cho câu trả lời này đã lỗi thời. Ví dụ:
set :repo_url, 'https://example.com/your_repo.git'
set :repo_tree, 'relative/path/from/your/repo' # relative path to project root in repo
Xem http://capistranorb.com/documentation/getting-started/configuration.
Nguồn
2014-01-25 00:26:39
Ồ, tôi ước gì tôi có thể gửi cho bạn một vài lon bia cooold. Cảm ơn bạn!! – Nazar
Hoàn hảo. Đúng thứ tôi cần. Cảm ơn! – Matt
NB. bất cứ ai đọc, điều này hoạt động nếu bạn đã sử dụng remote_cache như cơ chế: deploy_via của bạn (dựa trên truy cập SCM ở cuối máy chủ.) – jrg