db:migrate运行

时间:2017-11-25 03:52:21

标签: ruby-on-rails api deployment capistrano puma

我使用capistrano进行部署,但是创建了数据库,克隆了repo,创建了发布版但是当我运行迁移时,发生了以下错误。

任何帮助都会很棒,因为我试图将此错误修复3天。我附上了config / deploy.rb,Gemfile和Capifile

日志/ capistrano.log

" INFO [3e233a88]运行/ usr / local / rvm / bin / rvm默​​认执行bundle exec rake db:migrate as my_app_name@104.236.239.24  DEBUG [3e233a88]命令:cd / home / my_app_name / apps / my_app_name / releases / 20171125031326&& (export RAILS_ENV =" production&#34 ;; / usr / local / rvm / bin / rvm default do bundle exec rake db:migrate) DEBUG [3e233a88]耙子流产了! DEBUG [3e233a88] TypeError:不能复制NilClass /home/my_app_name/apps/my_app_name/shared/bundle/ruby/2.3.0/gems/redis-activesupport-5.0.4/lib/active_support/cache/redis_store.rb:46:in dup' /home/my_app_name/apps/my_app_name/shared/bundle/ruby/2.3.0/gems/redis-activesupport-5.0.4/lib/active_support/cache/redis_store.rb:46:in map&#39 ;"

的Gemfile 。 。

group :development do
    gem "listen", ">= 3.0.5", "< 3.2"
     # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
     gem "spring"
     gem "spring-watcher-listen", "~> 2.0.0"
     # Gem Capistrano for deployment
     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

Capifile

# Load DSL and Setup Up Stages
 require 'capistrano/setup'
 require 'capistrano/deploy'

 require 'capistrano/rails/migrations'
 require 'capistrano/bundler'
 require 'capistrano/rvm'
 require 'capistrano/puma'

 require "capistrano/scm/git"
 install_plugin Capistrano::SCM::Git

 install_plugin Capistrano::Puma

 # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
 Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }  

配置/ deploy.rb

server '104.236.239.24', user: 'deploy', roles: %w{app db web}

set :repo_url,        "https://XXXXXX:xxxxx@github.com/my-account-example/my-repo.git"
set :application,     "my_app_name"
set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { 
  forward_agent: true, 
  user: fetch(:user), 
  keys: %w(~/.ssh/id_rsa.pub), 
  port: 8022 
}
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord

set :linked_files, %w{config/database.yml}

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc 'Upload YAML files.'
  task :upload_yml do
    on roles(:app) do
      execute "mkdir #{shared_path}/config -p"
      upload! StringIO.new(File.read("config/database.yml")), "#{shared_path}/config/database.yml"
      upload! StringIO.new(File.read("config/secrets.yml")), "#{shared_path}/config/secrets.yml"
      upload!(".env.#{fetch(:stage)}", "#{deploy_to}/shared/.env")
    end
  end

  # desc "Make sure local git is in sync with remote."
  # task :check_revision do
  #   on roles(:app) do
  #     unless `git rev-parse HEAD` == `git rev-parse origin/master`
  #       puts "WARNING: HEAD is not the same as origin/master"
  #       puts "Run `git push` to sync changes."
  #       exit
  #     end
  #   end
  # end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  before :starting,     :upload_yml
  # before :starting,     :check_revision
  after  :finishing,    :cleanup
end

## Database tasks:
namespace :database do
  desc "Create database"
  task :create do
    on roles(:app) do
      within release_path do
        with rails_env: "#{fetch(:stage)}" do
          execute :rake, "db:create"
        end
      end
    end
  end

  desc "Invoke the db migration using the correct stage"
  task :migrate do
    on roles(:app) do
      within release_path do
        with rails_env: "#{fetch(:stage)}" do
          execute :rake, "db:migrate"
        end
      end
    end
  end
end

before "database:migrate", "database:create"

0 个答案:

没有答案