3

We are using Mina to deploy our Rails4 app after switching from Capistrano. On cap we could do cap production deploy:invoke task="namespace:taskname" where invoke task was a custom deploy task that took arguments to execute a specified rake task on a given environment.

How to pass arguments to mina to run specified rake tasks? So far the closest to argument passing in mina I have seen is mina deploy to=staging. I am looking for usage close to mina invoke namespace:taskname that would cd into app's /current directory and do a bundle exec rake namespace:taskname.

This seems simple enough, what am I missing?

Edit As per Guy Teube's suggestion in /config/deploy.rb I now have

set :task, ENV['TASK']
set :current, "#{deploy_to}/current"

desc "Invokes a raketask"
task :invoke => :environment do
  queue "cd #{current} && bundle exec rake #{task}"
end

Running mina invoke TASK=old:votes --simulate does not work yet, outputs "cd /home/deployer/apps/manabalss/current && bundle exec rake" (Notice the string terminating without TASK environmental variable not having been taken into account.

Epigene
  • 3,634
  • 1
  • 26
  • 31

4 Answers4

4

As it dawned on me here, mina is essentially rake and it is possible to simply:

rake mytask var=foo
p ENV['var'] # => "foo"

Then there is no need for a set: line, just use the environmental variable as-is. This mina task expects an environmental variable "task".

desc "Invokes a raketask"
task :invoke => :environment do
  queue! "cd #{current}"
  queue! "bundle exec rake #{ENV['task']} RAILS_ENV=production"
end

Then just call it with:

mina invoke task=namespace:taskname

If specifying the deployment environment is needed, modify the task to

queue! "bundle exec rake #{ENV['task']} RAILS_ENV=#{ENV['to']}"

And call with

mina invoke task=namespace:taskname to=staging
Community
  • 1
  • 1
Epigene
  • 3,634
  • 1
  • 26
  • 31
3

Long time, but I will leave my cent.

Maybe simply creating one mina task for each rails task you need on the server. In my case I needed to provide the team with something as simple as:

mina deploy_prod
and 
mina deploy_beta

To do this I`ve created these tasks outside deploy block:

task :deploy_prod => :environment do
  set :rails_env, 'production'
  set :branch, 'master'
  set :deploy_to, '/var/www/site'
  @command_valid = true
  invoke :deploy
end

task :deploy_beta => :environment do
  set :rails_env, 'development'
  set :branch, 'dev'
  set :deploy_to, '/var/www/site_beta'
  @command_valid = true
  invoke :deploy
end

And this inside deploy block, to make sure everyone will choose among above tasks:

to :before_hook do
  unless @command_valid
    puts "usage: mina [deploy_prod|deploy_beta] [-v]"
    exit 1
  end
end
Tom Lobato
  • 136
  • 2
  • 4
2

You could use an environment variable you use when you call mina in your terminal. You could do:

$ mina deploy TASK=namespace:taskname

Of course you need to edit your deploy.rb to get and the TASK param with ENV['TASK'].

By example, I can specifiy a branch and a domain to mina when I deploy with this command :

$ mina deploy DOMAIN=1.2.3.4 BRANCH=my_specific_branch

With in my deploy.rb :

set :user, 'my_app'
set :domain, ENV['DOMAIN']
set :identity_file, ENV['IDENTITY_FILE']

set :deploy_to, '/home/app'
set :repository, 'git@github.com:foo/bar.git'
set :branch, ENV['BRANCH'] || 'master'
lulalala
  • 17,572
  • 15
  • 110
  • 169
yutu
  • 109
  • 1
  • 5
0

if the requirement is to deploy to different environments then have a look at https://github.com/endoze/mina-multistage multi-stage plugin for mina

alex
  • 646
  • 9
  • 19