Tom*_*Tom 5 ruby deployment capistrano webistrano
我们每天使用 capistrano (实际上是webistrano)进行 20 多次部署,我们遇到了一个问题,即我们服务器上的磁盘空间充满了旧的部署文件夹。
我时不时地运行deploy:cleanup
任务来清理所有部署(它保留最后一个:keep_releases
,当前设置为 30)。我想自动化清理。
一种解决方案是将以下内容添加到配方中,以便在每次部署后自动运行清理:
after "deploy", "deploy:cleanup"
Run Code Online (Sandbox Code Playgroud)
但是,我不想在每次部署后都执行此操作,我想将其限制为仅当之前的部署数量达到阈值(例如 70)时。有谁知道我该怎么做?
想法:
set :num_releases, <what-can-I-put-here-to-count-previous-deployments>
deploy:cleanup
以便它使用最小阈值,即如果< :max_releases
以前的部署(与:max_releases
不同:keep_releases
)则退出。except
使用关键字吗?即类似的东西:except => { :num_releases < 70}
。Capistrano 是否提供了一个变量来保存先前部署的数量?
是的,releases.length
有没有办法pimp部署:清理所以它使用最小阈值?
是的,这是一个私有命名空间的任务,只有在建立了一定数量的发布文件夹时才会触发正常的清理任务:
namespace :mystuff do
task :mycleanup, :except => { :no_release => true } do
thresh = fetch(:cleanup_threshold, 70).to_i
if releases.length > thresh
logger.info "Threshold of #{thresh} releases reached, runing deploy:cleanup."
deploy.cleanup
end
end
end
Run Code Online (Sandbox Code Playgroud)
要在部署后自动运行它,请将其放在配方的顶部:
after "deploy", "mystuff:mycleanup"
Run Code Online (Sandbox Code Playgroud)
这样做的好处是,before
设置after
的指令deploy:cleanup
会正常执行。例如我们需要以下内容:
before 'deploy:cleanup', 'mystuff:prepare_cleanup_permissions'
after 'deploy:cleanup', 'mystuff:restore_cleanup_permissions'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3381 次 |
最近记录: |