nanobox
nanobox copied to clipboard
Environmental variables at compile time not available
Image: Elixir
Code that fails the build:
config :my_app,
fcm_batch_size: "FCM_BATCH_SIZE" |> System.get_env() |> String.to_integer()
Error:
Compiling application :
✓ Starting docker container
✓ Preparing environment for compile
! Compiling code
- Cleaning up any previous releases...
- Copying code...
- Compiling mix dependencies :
** (ArgumentError) argument error
:erlang.binary_to_integer(nil)
(stdlib) erl_eval.erl:677: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:885: :erl_eval.expr_list/6
(stdlib) erl_eval.erl:240: :erl_eval.expr/5
(stdlib) erl_eval.erl:232: :erl_eval.expr/5
(stdlib) erl_eval.erl:233: :erl_eval.expr/5
(stdlib) erl_eval.erl:885: :erl_eval.expr_list/6
(stdlib) erl_eval.erl:408: :erl_eval.expr/5
! FAILED TO COMPILE APP !
Exit
1
Command
su - gonano -c "cd /opt/nanobox/engine/bin; export PATH=\"/data/sbin:/data/bin:/opt/gonano/sbin:/opt/gonano/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"; export CODE_DIR=\"/app\"; export DATA_DIR=\"/data\"; export APP_DIR=\"/mnt/app\"; export CACHE_DIR=\"/mnt/cache\"; export ETC_DIR=\"/data/etc\"; export ENV_DIR=\"/data/etc/env.d\"; export CONFIG_RUNTIME_TYPE=\"string\"; export CONFIG_RUNTIME_VALUE=\"'elixir-1.7'\"; export CONFIG_ERLANG_RUNTIME_TYPE=\"string\"; export CONFIG_ERLANG_RUNTIME_VALUE=\"'erlang-21'\"; export CONFIG_NODES=\"runtime,erlang_runtime\"; stdbuf -o0 /opt/nanobox/engine/bin/compile '{\"code_dir\":\"/app\",\"data_dir\":\"/data\",\"app_dir\":\"/mnt/app\",\"cache_dir\":\"/mnt/cache/app\",\"etc_dir\":\"/data/etc\",\"env_dir\":\"/data/etc/env.d\",\"config\":{\"erlang_runtime\":\"erlang-21\",\"runtime\":\"elixir-1.7\"}}'"
Output
- Compiling mix dependencies :
** (ArgumentError) argument error
:erlang.binary_to_integer(nil)
(stdlib) erl_eval.erl:677: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:885: :erl_eval.expr_list/6
(stdlib) erl_eval.erl:240: :erl_eval.expr/5
(stdlib) erl_eval.erl:232: :erl_eval.expr/5
(stdlib) erl_eval.erl:233: :erl_eval.expr/5
(stdlib) erl_eval.erl:885: :erl_eval.expr_list/6
(stdlib) erl_eval.erl:408: :erl_eval.expr/5
Error : failed to execute hook (compile) on a6cc6f1fd118eb708da7cc00e4b1311961b2dbc2178fdc3ae225db435ee13efe: util:Exec:/opt/nanobox/hooks/compile: bad exit code(1):
Context : failed to compile the code -> failed to run the (compile)compile hook
Is there a way to make env vars available at compile time?
No, partly because a compile isn't meant to be used in one exclusive environment, and partly because binaries should never be built with environment values hard coded into the compiled result - that misses the entire point of environment variables.
Instead, adjust your code/config to actually look up your environment variables at runtime. This will solve both issues - the one you're asking about and the underlying one.
So how can I use secret key base or external DB URL in my config files?
On Fri, 12 Oct 2018 at 07:00, Dan Hunsaker [email protected] wrote:
No, partly because a compile isn't meant to be used in one exclusive environment, and partly because binaries should never be built with environment values hard coded into the compiled result - that misses the entire point of environment variables.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nanobox-io/nanobox/issues/685#issuecomment-429204685, or mute the thread https://github.com/notifications/unsubscribe-auth/ADDRZdPaWCKUgIk4dbGuA-Yito4fl6gKks5ukCHbgaJpZM4XX9fn .
Same way. Especially for DB info/credentials, you want to pull those from the environment at runtime – even with only a single deploy environment, that information may change between compile and startup.
As to the exact approach you should use to ensure that happens correctly, that's highly language- and framework-dependent, so you're better asking about that in communities more familiar with those.
OK, that won't work in my case. Too bad, thanks.
I know Elixir supports it. I don't know how. Ask around.