【发布时间】:2023-12-08 09:26:01
【问题描述】:
我只想在舞台不是生产时才需要capistrano/postgresql。
但是,此 Capfile 始终需要 capistrano/postgresql,因为 fetch(:stage) 为空。
(puts fetch(:stage) || "no stage" 在 Capfile 中打印“无阶段”)
require 'capistrano/bundler'
require 'capistrano/npm'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/puma'
require 'capistrano/puma/nginx'
require 'capistrano/postgresql' unless fetch(:stage) == "production"
require 'capistrano/secrets_yml'
我应该把require 'capistrano/postgresql' 放在config/deploy/staging.rb 等中吗?(我不知道它是否有效)?
或者还有其他简洁的方法吗?
编辑
如果我把require 'capistrano/postgresql' 放在config/deploy/staging.rb 中,就会出现如下错误。
WARNING: load:defaults has already been invoked and can no longer be modified.
Check that you haven't loaded a Capistrano plugin in deploy.rb by mistake.
Plugins must be loaded in the Capfile to initialize properly.
(Backtrace restricted to imported tasks)
cap aborted!
can't modify frozen #<Class:#<Rake::Task:0x007fd8bcd22868>>
【问题讨论】:
-
我稍后可能有时间提供更全面的答案,但如果在此过程的后期不是生产,我建议尝试取消注册挂钩。 Capistrano 未在 Capfile 中完全启动。