gpt4 book ai didi

ruby - Capistrano 配方自动运行部署 :cleanup only when needed

转载 作者:数据小太阳 更新时间:2023-10-29 07:32:55 28 4
gpt4 key购买 nike

我们每天使用 capistrano(实际上是 webistrano)进行 20 多次部署,但我们遇到了一个问题,即我们服务器上的磁盘空间充满了旧的部署文件夹。

我时不时地运行 deploy:cleanup清除所有部署的任务(它保留最后一个 :keep_releases,当前设置为 30)。我想自动清理。

一种解决方案是将以下内容添加到配方中以在每次部署后自动运行清理:

after "deploy", "deploy:cleanup"

但是,我不想在每次 部署后执行此操作,我想将其限制为仅当先前部署的数量达到阈值时,例如70. 有谁知道我该怎么做?


想法:

  • Capistrano 是否提供了一个变量来保存以前部署的数量?
    • 如果不是,有没有人知道计算它的方法。即 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} 的东西.

最佳答案

Does Capistrano provide a variable that holds the number of previous deployments?

是的,releases.length

Is there a way to pimp deploy:cleanup so it uses a minimum threshold?

是的,这是一个私有(private)命名空间的任务,只有在建立了一定数量的发布文件夹时才会触发正常的清理任务:

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

要在部署后自动运行,请将其放在配方的顶部:

after "deploy", "mystuff:mycleanup"

这样做的好处是,在 deploy:cleanup 上设置的 beforeafter 指令会正常执行。例如,我们需要以下内容:

before 'deploy:cleanup', 'mystuff:prepare_cleanup_permissions'
after 'deploy:cleanup', 'mystuff:restore_cleanup_permissions'

关于ruby - Capistrano 配方自动运行部署 :cleanup only when needed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7008448/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com