我正在尝试使用capistrano学习部署。我想将代码部署在本地计算机上的单独文件夹中,并在部署后运行迁移。 项目中使用的capistrano宝石如下
capistrano (3.4.0)
capistrano-bundler (1.1.4)
capistrano-ext (1.2.1)
capistrano-rails (1.1.3)
该应用程序使用ruby 2.1和rails 4.1 部署文件如下
require 'capistrano/rails/migrations'
lock '3.4.0'
set :application, 'capistrano_study'
set :repo_url, 'https://github.com/xxxxxx/capistrano_study.git'
# config valid only for current version of Capistrano
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :user, "prajeesh"
after "deploy:updated", "deploy:migrate"
namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
staging.rb文件如下。
server 'xx.x.x.xxx', user: 'prajeesh', roles: %w{app db web}, my_property: :my_value
set :deploy_to, "/home/prajeesh/Desktop/projects/capistrano_staging"
的database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: cap_test_staging
pool: 5
username: root
password: xxxxx
# socket: /var/run/mysqld/mysqld.sock
staging:
adapter: mysql2
encoding: utf8
reconnect: false
database: cap_test_staging
pool: 5
username: root
password: xxxxx
当我运行命令 cap staging:deploy 时,部署工作正常。问题是部署后迁移未运行。
有谁知道如何解决这个问题?
编辑:
这是我得到的错误。
INFO [175f4b0b] Running /usr/bin/env rake db:migrate as
prajeesh@xx.x.x.xxx
DEBUG [175f4b0b] Command: cd /home/prajeesh/Desktop/projects/capistrano_staging/current && ( RAILS_ENV=development /usr/bin/env rake db:migrate )
DEBUG [175f4b0b] rake aborted!
DEBUG [175f4b0b]
cannot load such file -- bundler/setup
如果我直接从项目路径运行命令RAILS_ENV = development / usr / bin / env rake db:migrate,则迁移正在运行,但是通过capistrano它无法正常运行。
任何帮助都将不胜感激。
答案 0 :(得分:1)
嘿,你应该运行以下命令来运行命令:
cap deploy:migrate
要让它运行,您可以在此处看到documentation
已针对自动迁移进行了更新:
after "deploy:update_code", "deploy:migrate"
进入文件config/deploy.rb.
答案 1 :(得分:0)
如here中所述,您应该在Capfile中需要capistrano/rails/migrations
。它会做到这一点。
答案 2 :(得分:0)
如果你在Capistrano 3上,我做了
set :migration_role, :app
除了将require 'capistrano/rails/migrations'
添加到我的deploy.rb
文件中外。