3
votes

I'm trying to make Capistrano deploy script.

In my Capfile I make sure all rake tasks are included

# Load tasks
Dir.glob('config/capistrano_tasks/*.rake').each { |r| import r }

Next I have a 'migrations.rake' containing:

namespace :fileservice do
    task :migrate do
        within release_path do
            info 'Doing migrations'

            execute :php, fetch(:symfony_console_path), 'doctrine:migrations:migrate', '--no-interaction', fetch(:symfony_console_flags)
        end
    end
end

In my deploy.rb I call the task at the very end with:

after 'deploy:publishing', 'fileservice:migrate'

For some reason I keep getting an error saying:

NoMethodError: undefined method `within' for main:Object

I have no idea where to look or what might be wrong... When googling I get a lot of "NoMethodError" hits but none about the 'within' method and most are general Ruby errors.

Where should "within" be defined? I dat a ruby on rails thing? Or capistrano?

Hopefully someone knows where to start looking or which library / script to include!

UPDATE: I just discovered that none of the methods work. When removing lines I got the same error for "info" and "execute".... So I guess somewhere, something is missing.....

2

2 Answers

4
votes

You need to tell Capistrano where (i.e. on what servers) to run your SSH commands. Do this using an on block, as follows:

namespace :fileservice do
  task :migrate do
    on roles(:db) do
      within release_path do
        info 'Doing migrations'
        execute :php, fetch(:symfony_console_path), 'doctrine:migrations:migrate', '--no-interaction', fetch(:symfony_console_flags)
      end
    end
  end
end

Replace roles(:db) as appropriate for your task, depending on where you want the commands to be run. The expression on roles(:all) do ... end, for example, will run the commands on all servers.


You can also follow the official documentation at http://capistranorb.com, or the Capistrano README, both of which show examples of the task/on/execute syntax.

0
votes

As you already got the answer but Let me put the bulb from basic.

SSHKit was actually developed and released with Capistrano 3, and it’s basically a lower-level tool that provides methods for connecting and interacting with remote servers; it does all the heavy lifting for Capistrano, in other words.

There are four main methods you need to know about.

on(): specifies the server to run on

within(): specifies the directory path to run in

as(): specifies the user to run as

with(): specifies the environment variables to run with

Typically, you’ll start a task by using an on() method to specify the server on which you want your commands to run. Then you can use any combination of as(), within(), and with() methods, which are repeatable and stackable in any order.

Hope this help you