Rails app can't access environment database variable

Hi guys, I’m trying to setup my app for the first time and I’m having some problems with the deploy.

For some reason, my app can’t access the environment variable that I set with the database URL:

I have set this way:

aptible config:add --app house-staging DATABASE_URL=postgresql…

When I run the command to list all environment variables it’s present:

aptible config --app house-staging
DATABASE_URL=postgresql://XXXXXXXXXXX

I forced an error listing all environment variables during the deploy and I wasn’t able to locate the DATABASE_URL variable …

The error:

remote: all variables:
remote: {“HOSTNAME”=>“914cf42a3e15”, “HOME”=>"/root", “LIBSSL_MIN”=>“1.0.1f-1ubuntu2”, “RUBY_VERSION”=>“2.4.1”, “RUBY_SHA1SUM”=>“47909a0f77ea900573f027d27746960ad6d07d15”, “PATH”=>"/usr/lib/ruby/gems/2.4.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", “LIBC_MIN”=>“2.21-0ubuntu6”, “PWD”=>"/app", “BUNDLER_ORIG_PATH”=>"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", “BUNDLE_BIN_PATH”=>"/usr/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/exe/bundle", “BUNDLE_GEMFILE”=>"/app/Gemfile", “BUNDLER_VERSION”=>“1.14.6”, “RUBYOPT”=>"-rbundler/setup", “RUBYLIB”=>"/usr/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib", “GEM_PATH”=>"/usr/lib/ruby/gems/2.4.0:/root/.gem/ruby/2.4.0", “GEM_HOME”=>"/usr/lib/ruby/gems/2.4.0"}

Am I doing something wrong ?

Hi there @augusto,

Environment variables are not available during the Docker build (this can be viewed both as a best practice or a limitation in Docker itself); is that where you’re trying to access them?

If so, we do provide a workaround, documented here: https://www.aptible.com/support/topics/enclave/how-to-access-environment-variables-inside-dockerfile/

Cheers,

Hi @thomas, yes, that was exactly it!

Thanks a lot!

You’re welcome! :slight_smile: