Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic beanstalk Rails - defaults to production environment even if I set staging environment

I am trying to bring up a staging instance of rails applciation using elastic beanstalk. I followed the documentation and did the following :

eb init --environment staging
eb start --environment staging

After this, I checked that the .elasticbeanstalk/optionsettings still had 'production' as the environment. I manually updated this to staging, and tried the git aws.push command.

After sometime, everything was deployed, However, when I load the URL, the application still seems to be using all the production configs and not the staging. Am I missing any step ?

like image 701
ddb Avatar asked Dec 27 '22 14:12

ddb


2 Answers

The --environment switch in the eb CLI tool does not refer to the Rails environment, it refers to the Elastic Beanstalk environment which you are attempting to launch. The Elastic Beanstalk environment is a set of provisioned resources for a deployed application version. This is different from a Rails/Rack environment, which is simply a user defined context for application code to run in on an individual machine.

In order to set your Rails environment, you will want to set the RACK_ENV (or RAILS_ENV) environment variable inside of your .elasticbeanstalk/optionsettings file after an eb start and then call eb update to trigger an update of these environment variables. Or, you can edit your Elastic Beanstalk environment configuration through the Elastic Beanstalk console; click on "Environment details" on the correct environment, "Edit Configuration" in the Overview, and go to "Container" to adjust environment variables (in this case, you will edit the RACK_ENV field).

like image 111
Loren Segal Avatar answered Apr 28 '23 10:04

Loren Segal


While I'm using eb_deployer and not the eb commandline, during an attempt to deploy a RAILS_ENV: development I found that db:migrate etc ran in the development environment, but it still started up the server in production mode. To solve this, passing in both RACK_ENV and RAILS_ENV was necessary in the option_settings:

[{
   namespace: 'aws:elasticbeanstalk:application:environment',
   option_name: 'RACK_ENV',
   value: "development"
 },
 {
   namespace: 'aws:elasticbeanstalk:application:environment',
   option_name: 'RAILS_ENV',
   value: "development"
 }]
like image 22
kross Avatar answered Apr 28 '23 10:04

kross