Jar*_*dom 65 git deployment capistrano ruby-on-rails
我的主分支布局是这样的:
/ < - 顶级
/ client < - 桌面客户端源文件
/ server < - Rails app
我想做的只是拉下我的/ server目录deploy.rb,但我似乎找不到任何办法./ client目录很大,因此设置一个钩子来复制/服务器到/将无法正常工作,它只需要拉下Rails应用程序.
tho*_*odg 77
没有任何脏的分叉动作,但更脏!
在我的config/deploy.rb中:
set :deploy_subdir, "project/subdir"
Run Code Online (Sandbox Code Playgroud)
然后我将这个新策略添加到我的Capfile中:
require 'capistrano/recipes/deploy/strategy/remote_cache'
class RemoteCacheSubdir < Capistrano::Deploy::Strategy::RemoteCache
private
def repository_cache_subdir
if configuration[:deploy_subdir] then
File.join(repository_cache, configuration[:deploy_subdir])
else
repository_cache
end
end
def copy_repository_cache
logger.trace "copying the cached version to #{configuration[:release_path]}"
if copy_exclude.empty?
run "cp -RPp #{repository_cache_subdir} #{configuration[:release_path]} && #{mark}"
else
exclusions = copy_exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ')
run "rsync -lrpt #{exclusions} #{repository_cache_subdir}/* #{configuration[:release_path]} && #{mark}"
end
end
end
set :strategy, RemoteCacheSubdir.new(self)
Run Code Online (Sandbox Code Playgroud)
小智 42
对于Capistrano 3.0,我使用以下内容:
在我的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
Run Code Online (Sandbox Code Playgroud)
在我的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'
Run Code Online (Sandbox Code Playgroud)
所有重要的代码都在策略release方法中,该方法git archive仅用于存档repo的子目录,然后使用该--strip参数tar在正确的级别提取存档.
UPDATE
从Capistrano 3.3.3开始,您现在可以使用:repo_tree配置变量,这使得这个答案过时了.例如:
set :repo_url, 'https://example.com/your_repo.git'
set :repo_tree, 'relative/path/from/your/repo' # relative path to project root in repo
Run Code Online (Sandbox Code Playgroud)
请参阅http://capistranorb.com/documentation/getting-started/configuration.
Tho*_*ser 10
我们还通过克隆整个存储库,删除未使用的文件和文件夹并在层次结构中向上移动所需的文件夹,与Capistrano一起执行此操作.
deploy.rb
set :repository, "git@github.com:name/project.git"
set :branch, "master"
set :subdir, "server"
after "deploy:update_code", "deploy:checkout_subdir"
namespace :deploy do
desc "Checkout subdirectory and delete all the other stuff"
task :checkout_subdir do
run "mv #{current_release}/#{subdir}/ /tmp && rm -rf #{current_release}/* && mv /tmp/#{subdir}/* #{current_release}"
end
end
Run Code Online (Sandbox Code Playgroud)
只要项目没有变得太大,这对我们来说非常有用,但是如果可以的话,为每个组件创建一个自己的存储库,并使用git子模块将它们组合在一起.