如何为多个服务器依次执行capistrano任务?

时间:2018-07-24 04:22:57

标签: ruby-on-rails ruby deployment capistrano capistrano3

我在下面有多个服务器和capistrano任务

before 'deploy:starting',   'elb:deregister'
before 'deploy:finishing',  'elb:register'

after 'deploy:publishing', 'deploy:restart'
after 'deploy:failed',     'elb:deregister'

当我像下面这样部署时

  before 'deploy:starting',   'elb:deregister' -> server1
  before 'deploy:starting',   'elb:deregister' -> server1

  ...
  ...

如何按如下顺序部署

Server1

  before 'deploy:starting',   'elb:deregister'
  before 'deploy:finishing',  'elb:register'

  after 'deploy:publishing', 'deploy:restart'
  after 'deploy:failed',     'elb:deregister'  

Server2

  before 'deploy:starting',   'elb:deregister'
  before 'deploy:finishing',  'elb:register'

  after 'deploy:publishing', 'deploy:restart'
  after 'deploy:failed',     'elb:deregister'

1 个答案:

答案 0 :(得分:0)

您在这里有多个选择。

假设您有这样的上限配置:

 buildTypes {
        release {
            minifyEnabled false
            shrinkResources false  
            zipAlignEnabled true
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
}

手动进行。

您可以执行此操作;

  • 注释server_2行并运行server 'server_1', user: 'deploy', roles: %w[app db web] server 'server_2', user: 'deploy', roles: %w[app]
  • 还原server_2行并注释掉server_1行并运行cap production deploy

有用而又简单却很愚蠢。

使用其他部署环境。

您可以像生产2一样设置另一个部署环境并运行cap production deploy

使用其他部署角色。

赋予服务器不同的角色,并像这样更改您的任务和配置:

cap production deploy; cap production2 deploy