Question

I want to deploy to production an app to my local server. i'm using capistrano 3.

this is my capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
#require 'capistrano/rails/migrations'
#require 'capistrano/rails/assets'


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

this is my deploy.rb

# config valid only for Capistrano 3.1
lock '3.1.0'

set :application, 'ImpresaZiliani'
set :repo_url, 'francesco@10.0.1.8:repos/impresaziliani.git'
set :branch, 'master'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/francesco/impresaziliani'

# Default value for :scm is :git
set :scm, :git
set :deploy_user, "francesco"
set :rails_env, "production"

set :keep_releases, 5

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart

  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

set :rvm_ruby_version, '2.1.1'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#                   {fetch(:rvm_ruby_version)} do bundle exec rake"

my database.yml is ok since if i run manually the migrations on the server it works, i have tried with uncommenting the line of capistrano/rails/migrations and assets but nothing changes: when i deploy it runs fine till the bundler install, then without any warning or error, skip to the asset precompiler and doesn't run migrations.

how can i fix this?

thank you

Was it helpful?

Solution 2

rake db:migrate is automatic per deploy in capistrano 3 you just need to uncomment #require 'capistrano/rails/migrations' in your Capfile

OTHER TIPS

You also need to make the user deploying has the role of db, such as:

server 'you_ip_address', user: 'user_name', roles: %w{web app db}

Both Jude Calimbas and hiveer's answers are more accurate than the accepted answer - the migration task is run automatically as part of the deploy task.

However, their answers do not explain the problem observed. The only thing that occurs to me is that the database.yml file is not explicitly linked in the deploy.rb file. So a line like

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

would have fixed it.

I know that this is an old question but it would be interesting to know more details from the OP regarding the problem and the fix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top