I am trying to run symfony doctrine migrations on multiple servers using capifony but it appears that it only executes the migrations on one server only. for example: This is how i set my servers addresses:
role :web, "192.168.56.102","192.168.56.103" # Your HTTP server, Apache/etc
role :app, "192.168.56.102","192.168.56.103", :primary => true # This may be the same as your `Web` server
the migrations are only executed on the first server although the code deployment happens on both.
Here is My Deployment Script:
#### Basic Deploying Script Config ####
set :application, "eConnect"
###set :domain, "192.168.56.102"
set :user, "vagrant"
set :use_sudo, false
set :deploy_to, "/var/www/SchoolEconnectDeployment"
set :app_path, "app"
set :repository, "."
set :local_repository, "."
set :deploy_via, :copy
set :scm, :mercurial
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, or `none`
set :model_manager, "doctrine"
set :interactive_mode, false
# Or: `propel`
role :web, "192.168.56.102","192.168.56.103" # Your HTTP server, Apache/etc
role :app, "192.168.56.102","192.168.56.103", :primary => true # This may be the same as your `Web` server
set :copy_vendors, true
set :cache_warmup, false
set :keep_releases, 3
set :shared_children, %w()
#############################################################################################################################################
#### Created Custom Methods for Deployment ####
namespace :deploy do
task :create_release_dir, :except => {:no_release => true} do
run "mkdir -p #{fetch :releases_path}"
end
#### Copying the Latest release to any specified directory ####
task :move_latest_release, :roles => %w{app web db} do
run "mkdir -p /var/www/school_econnect"
run "yes | cp -rf #{ current_release }/* /var/www/school_econnect"
end
#### Econnect Migrations Custom Method ####
desc "Executes a Econnect migration to a specified version or the latest available version"
task :econnect_migrate, :roles => :app, :only => { :primary => true }, :except => { :no_release => true } do
currentVersion = nil
run "#{try_sudo} sh -c 'cd /var/www/school_econnect && #{php_bin} #{symfony_console} --no-ansi doctrine:migrations:status #{console_options}'", :once => true do |ch, stream, out|
if stream == :out and out =~ /Current Version:.+\(([\w]+)\)/
currentVersion = Regexp.last_match(1)
end
if stream == :out and out =~ /Current Version:\s*0\s*$/
currentVersion = 0
end
end
if currentVersion == nil
raise "Could not find current database migration version"
end
logger.info " Current database version: #{currentVersion}"
on_rollback {
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
run "#{try_sudo} sh -c 'cd /var/www/school_econnect && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} #{console_options} --no-interaction'", :once => true
end
}
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
run "#{try_sudo} sh -c ' cd /var/www/school_econnect && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{console_options} --no-interaction'", :once => true
end
end
#### View the status of the migrations available ####
desc "Views the status of a set of migrations"
task :econnect_migrate_status, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} sh -c 'cd /var/www/school_econnect && #{php_bin} #{symfony_console} doctrine:migrations:status #{console_options} '", :once => true
end
#### Econnect Migrations Rollback Custom Method ####
desc "Executes a Econnect migration Rollback to a specified version or the latest available version"
task :econnect_rollback_migrate, :roles => :app, :only => { :primary => true }, :except => { :no_release => true } do
currentVersion = nil
run "#{try_sudo} sh -c 'cd /var/www/school_econnect && #{php_bin} #{symfony_console} --no-ansi doctrine:migrations:status #{console_options}'", :once => true do |ch, stream, out|
if stream == :out and out =~ /Current Version:.+\(([\w]+)\)/
currentVersion = Regexp.last_match(1)
end
if stream == :out and out =~ /Current Version:\s*0\s*$/
currentVersion = 0
end
end
if currentVersion == nil
raise "Could not find current database migration version"
end
logger.info " Current database version: #{currentVersion}"
on_rollback {
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
run "#{try_sudo} sh -c 'cd /var/www/school_econnect && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} #{console_options} --no-interaction'", :once => true
end
}
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
run "#{try_sudo} sh -c ' cd /var/www/school_econnect && #{php_bin} #{symfony_console} doctrine:migrations:execute #{currentVersion} --down #{console_options} --no-interaction'", :once => true
end
end
end
####################################################################################################################
### Spinner Stuff ###
@spinner_running = false
@chars = ['|', '/', '-', '\\']
@spinner = Thread.new do
loop do
unless @spinner_running
Thread.stop
end
print @chars[0]
sleep(0.1)
print "\b"
@chars.push @chars.shift
end
end
def start_spinner
@spinner_running = true
@spinner.wakeup
end
# stops the spinner and backspaces over last displayed character
def stop_spinner
@spinner_running = false
print "\b"
end
###############################################################
STDOUT.sync
####### Custom Methods Hooks with Capifony's Deployment Methods #######
after "deploy", "deploy:cleanup"
after "deploy:setup", "deploy:create_release_dir"
before "deploy:move_latest_release" do
print " --> Moving the latest version to the correct Destination ........"
start_spinner()
end
after "deploy:move_latest_release" do
stop_spinner()
puts " Done.".green
end
after "deploy:rollback" do
print " --> Moving the latest version to the correct Destination ........"
start_spinner()
run "mkdir -p /var/www/school_econnect"
run "yes | cp -rf #{ previous_release }/* /var/www/school_econnect"
stop_spinner()
puts " Done.".green
end
after "deploy:cleanup", "deploy:move_latest_release"
after "deploy:move_latest_release", "deploy:econnect_migrate"
before "deploy:econnect_migrate" do
print " --> Running Migrations ......"
start_spinner()
end
after "deploy:econnect_migrate" do
stop_spinner()
puts " Done.".green
end
before "deploy:econnect_rollback_migrate" do
print " --> Rolling Back Latest Migration ......"
start_spinner()
end
after "deploy:econnect_rollback_migrate" do
stop_spinner()
puts " Done.".green
end
##############################################################################################################
# Be more verbose by uncommenting the following line
logger.level = Logger::MAX_LEVEL
As you can see i had to do my own migration function which is slightly different ( not so different hardcoded the path thats all).
I looked everywhere but i couldn't find anything related to my issue.
and if there is no solution, i would like to know how can i call a task in a loop and give it any kind of parameter i want written in the deployment script. i am pretty new to ruby so you know.
P.S: I also tried the multistage method but nothing worked for me. I would appreciate any kind of help. Thanks In-advance.
Edit:
I have been trying to find a workaround i have been trying with this:
before "deploy:move_latest_release" do
machine_info = ['192.168.56.102','192.168.56.103']
machine_info.each do |value|
role :db, "#{value}", :primary => true
puts "#{value}".red
deploy.econnect_migrate
end
print " --> Moving the latest version to the correct Destination ........"
start_spinner()
end
the loop works fine but the role :db doesn't change.
I Also tried this
cap HOSTS=192.168.56.102,192.168.56.103 deploy:econnect_migrate
Still the same issue.