Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environmental variables at compile time not available #685

Open
KamilLelonek opened this issue Oct 11, 2018 · 5 comments
Open

Environmental variables at compile time not available #685

KamilLelonek opened this issue Oct 11, 2018 · 5 comments

Comments

@KamilLelonek
Copy link

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?

@danhunsaker
Copy link
Contributor

danhunsaker commented Oct 12, 2018

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.

@KamilLelonek
Copy link
Author

KamilLelonek commented Oct 12, 2018 via email

@danhunsaker
Copy link
Contributor

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.

@KamilLelonek
Copy link
Author

OK, that won't work in my case. Too bad, thanks.

@danhunsaker
Copy link
Contributor

I know Elixir supports it. I don't know how. Ask around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants