Env variable is nil when passed through plug opts on runtime when using release

Hello, so I have few apps under an umbrella, lets say the names are linesdk, hibiki, and hibiki_web. So linesdk have a plug where you pass a secret key as the opts. hibiki_web is the app which runs the cowboy server and routes request to the linesdk plug. The secret key that needs to be passed is inside the :hibiki :channel_secret config. Here are some snippets

defmodule Hibiki.Config do
  def channel_secret, do: Application.fetch_env!(:hibiki, :channel_secret)

defmodule HibikiWeb.Router do
    to: LineSdk.Plug,
    init_opts: [
      channel_secret: Hibiki.Config.channel_secret(),
      handler: Hibiki.WebhookHandler

defmodule LineSdk.Plug do
  use Plug.Builder
  plug(:validate, builder_opts())
  def validate(
          assigns: %{raw_body: raw_body}
        } = conn,
      ) do
    with {:ok, signature} <- get_signature(conn),
         {:ok, _} <-
           ) do
      {:error, err} ->
        |> send_resp(400, "#{err}")
        |> halt

And the plug access the channel_secret using opts[:channel_secret].

Now, these piece of code is running fine in my local development. But when I build the release into a docker image and deploy it, somehow the opts[:channel_secret] became nil while the opts[:handler] is not changing.
The weider thing is when use the release binary remote command and run Hibiki.Config.channel_secret() it does returns the correct value.

This is after I refactor the plug from hibiki_web to linesdk. Before it was fine. But in both cases, it is still the hibiki_web app that calls the Hibiki.Config.channel_secret() but somehow when the released app is running it returns nil. Can anybody help me? Thank you very much!

Since you are using the function in your router’s post macro for init values, most likely the value is set at compile time (plug init calls are made at compile time). So check that the value is set correctly when you are compiling the release. Or if you only want to set the value on your target machine, you will need to refactor your code to grab it at runtime.

Ah, that makes sense. I tried to pass the &Mod.fun/ar instead and it works. It seems I have to find another way to pass the value. Thanks!