我有一个rails 5.2 app。我正在尝试使用Capistrano进行部署。
该应用程序有一个gem依赖子模块,其中包含此项目所需的所有模型和迁移。这个子模块取决于它的.gemspec
中的其他宝石。
因此,我需要在子模块根目录中运行rails db:migrate
,而不是父项目根目录。
我已将以下内容添加到deploy.rb
:
desc 'Runs rake db:migrate if migrations are set'
task :migrate => [:set_rails_env] do
on primary fetch(:migration_role) do
within "#{release_path}/PATH/TO/SUBMODULE" do
with rails_env: fetch(:rails_env) do
execute :rake, "db:migrate"
end
end
end
end
before :starting, :migrate
的Gemfile:
gem 'dependency', path: 'PATH/TO/SUBMODULE'
gem 'capistrano-git-with-submodules', '~> 2.0'
group :development do
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma', require: false
end
当我尝试运行此任务时,收到一条错误消息:
DEBUG [b4c1cf18] [31mCould not find aasm-5.0.2 in any of the sources[0m
DEBUG [b4c1cf18]
DEBUG [b4c1cf18] [33mRun `bundle install` to install missing gems.[0m
DEBUG [b4c1cf18]
在部署父项目时使用的gem集(包含所有父模块和子模块gems)似乎不在路径中,或者在运行此任务时不可用。
我可以在没有迁移的情况下运行父项目,因此我知道父项目正在运行时加载所有正确的gem集。只是没有在这个任务期间。
我不太确定Capistrano是如何工作的,我怎么能确保这些宝石在运行时可用于此任务?