mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.34k stars 491 forks source link

mina 1.2.4: Allow multiple deployments with different `RAILS_ENV` #713

Closed abhinavc closed 1 year ago

abhinavc commented 1 year ago

I am looking to deploy two instances of a Rails app on a VPS - one for production and one for sandbox (or staging / testing).

But it seems to me that mina wouldn't allow it.

In task rails:db_migrate, rails_env is hard-coded to production with no means to override it. And this rails_env then percolates down to bundle_prefix and thence to rake and rails etc.

Could a way be provided therefore to set :rails_env to something other than the default production?

Screenshot 2022-09-20 at 8 26 16 PM

lovro-bikic commented 1 year ago

You can override variables in your deploy.rb script.

If you set:

# config/deploy.rb
require 'mina/rails'

set :rails_env, 'staging'

it will set the rails_env variable to staging (or rather, the value staging will override the value production).

Regarding deploying to multiple environments, see this code sample, and let me know if it helps.

abhinavc commented 1 year ago

Thanks @lovro-bikic

I realized after I filed the issue that set :rails_env, 'staging' would work. I wrongly assumed that once set a value could not be changed - not realizing that if set is passed a block, then that block will be used by fetch to return the updated value.