kilhage / capistrano-symfony-doctrine

Capistrano extension for doctrine migrations & cache clearing
https://www.glooby.com
MIT License
3 stars 1 forks source link

Task not running #1

Open webdevilopers opened 8 years ago

webdevilopers commented 8 years ago

Capistrano Version: 3.4.0 (Rake Version: 10.4.2)

Capfile:

require 'capistrano/symfony'
require 'capistrano/symfony-doctrine'

My former integration for migrations:

namespace :tasks do
  task :migrate do
    invoke 'symfony:console', 'doctrine:migrations:migrate', '--verbose'
  end
end

namespace :deploy do
  after :updated, 'tasks:migrate'
end

Now I use:

namespace :deploy do
  after :updated, 'symfony:doctrine:migrations'
end

Not sure if the namespace loop is required and I can simply use:

before 'deploy:updated', 'symfony:doctrine:migrations'
#after 'deploy:updated', 'symfony:doctrine:migrations'

Anyways the migrations are no running. Currently all versions were migrated. Will the task then be skippend? Using my original code I at least got the interaction mode and was asked for migrating - even if no migration versions were to be migrated.

kilhage commented 8 years ago

Make sure that the Gemfile looks like this:

gem 'capistrano', '~> 3.1.0'
gem 'capistrano-symfony'
gem 'capistrano-symfony-doctrine'

And the Capfile looks like this:

require 'capistrano/symfony'
require 'capistrano/symfony-doctrine'

You also have to make sure that the task is executed after the deploy is made. The deploy.rb should look like this:

after  'deploy:updated', 'symfony:doctrine:migrations'

I've used this for quite some time now and it works great, I'm also using Capistrano 3.4.0.

The task will run on each deploy but will only run new migrations added in the latest deploy. You have to use the --no-interaction flag in order for the migrations to execute automatically without getting into interaction mode during the deploy.

kilhage commented 8 years ago

Sorry for the late reply but I think I've found your problem.

The server that you want to execute this script on must have the role db. The reason for this is because you might be having multiple web nodes but you only want to execute this on one of the nodes to avoid errors!

server 'node1.example.com', user: 'root', roles: %w{web db}
server 'node2.example.com', user: 'root', roles: %w{web}
server 'node3.example.com', user: 'root', roles: %w{web}

I'll make sure to add this to the readme

webdevilopers commented 7 years ago

I tried the following settings:

server 'stage.example.com', roles: %w{web db}, user: "example"

namespace :deploy do
  after  'deploy:updated', 'symfony:doctrine:migrations'
end

Cap aborts:

cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as example@example.com: cd '/var/www/vhosts/.../htdocs/releases/20160826130140'; app/console doctrine:migrations:migrate --no-interaction --no-debug exit status: 126 cd '/var/www/vhosts/.../htdocs/releases/20160826130140'; app/console doctrine:migrations:migrate --no-interaction --no-debug stdout: Nothing written cd '/var/www/vhosts/.../htdocs/releases/20160826130140'; app/console doctrine:migrations:migrate --no-interaction --no-debug stderr: bash: app/console: Keine Berechtigung /var/lib/gems/1.9.1/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in rescue in block (2 levels) in execute' /var/lib/gems/1.9.1/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:inblock (2 levels) in execute' SSHKit::Command::Failed: cd '/var/www/vhosts/.../htdocs/releases/20160826130140'; app/console doctrine:migrations:migrate --no-interaction --no-debug exit status: 126

kilhage commented 7 years ago

Make sure that you are using the latest version of doctrine migrations & the doctrine migration bundle. I know there have been issues regarding that in earlier versions