appengine-ruby icon indicating copy to clipboard operation
appengine-ruby copied to clipboard

env_variables cannot be used in deployment

Open nek023 opened this issue 6 years ago • 0 comments

Hi,

This is a issue about ruby25_app_builder rather than this gem. Sorry if it isn't the right place to ask.

I found that environment variables defined in app.yaml cannot be used in gcloud app deploy.

For example, my Rails app initializes an API client on launch. So I wrote an initializer that reads API key from environment variable:

config/initializers/sample_initializer.rb

api_key = ENV['SAMPLE_API_KEY']
raise 'sample_api_key is required' if api_key.blank?

SampleClient.config.api_key = api_key

Then I deploy this app with gcloud app deploy. During deploy, ruby25_app_builder automatically runs rails assets:precompile if public/assets does not exists. But this command fails due to missing env var.

Logs from Cloud Build:

Step #1 - "builder": [2019-12-15 09:59:24 INFO] => Checking for Rails sprockets
Step #1 - "builder": [2019-12-15 09:59:24 INFO] => Running Rails asset precompilation
Step #1 - "builder": [2019-12-15 09:59:24 INFO] ["bundle", "exec", "bin/rails", "assets:precompile"]
Step #1 - "builder": rails aborted!
Step #1 - "builder": sample_api_key is required

This can be avoided by running RAILS_ENV=production rails assets:precompile in advance. But I think this should be done by ruby25_app_builder. Are there any plans to fix this?

nek023 avatar Dec 15 '19 12:12 nek023