Validating compile/runtime configuration - ERROR! the application :backend has a different value set for key :basic_auth during runtime

I’m struggling to understand an error I’m seeing when deploying an Elixir app with releases. The error looks like this:

remote:  !     Release command declared: '/app/bin/backend eval "Backend.Release.migrate()"'        
remote:        ERROR! the application :backend has a different value set for key :basic_auth during runtime compared to compile time. Since this application environment entry was marked as compile time, this difference can lead to different behaviour than expected:        
remote:          * Compile time value was not set        
remote:          * Runtime value was set to: [username: "admin", admin_password: "<snip>"]        
remote:        To fix this error, you might:        
remote:          * Make the runtime value match the compile time one        
remote:          * Recompile your project. If the misconfigured application is a dependency, you may need to run "mix deps.compile backend --force"        
remote:          * Alternatively, you can disable this check. If you are using releases, you can set :validate_compile_env to false in your release configuration. If you are using Mix to start your system, you can pass the --no-validate-compile-env flag        

In my releases.ex, I have the following:

admin_password =
  System.get_env("ADMIN_PASSWORD") ||
    raise """
    environment variable ADMIN_PASSWORD is missing.

config :backend, :basic_auth,
  username: "admin",
  admin_password: admin_password

The error seems to be that the compile-time and runtime configuration are different. I tried setting the same configuration with hardcoded test values in config.exs, but this gives the same issue since the hardcoded values are different from my actual production ADMIN_PASSWORD.

I couldn’t find much documentation on this – I know I can set validate_compile_env to false, but is this recommended? Can I resolve this error without disabling this feature?

1 Like

Could you show how :basic_auth app env is used in your codebase? Looks like you’re using Application.compile_env/3 with it which performs the extra checks. If the app env is supposed to be manipulated at runtime, use Application.get_env/3 instead.


Ach, that’s it! The fact that I was using compile_env just didn’t click. Thank you!

I’ve also run into this in Docker when doing a mix compile with only the mix.exs/mix.lock added. Had to add the config folder as well for compile time settings.