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

Latest release breaks production release #37

Closed
PaulOstazeski opened this issue Apr 20, 2020 · 11 comments
Closed

Latest release breaks production release #37

PaulOstazeski opened this issue Apr 20, 2020 · 11 comments
Assignees
Labels
question Further information is requested user-feedback

Comments

@PaulOstazeski
Copy link

Hi. In production runtimes (at least using MIX_ENV=prod mix release), Mix is not available. This causes the following error in v1.1.1(https://github.com/dwyl/elixir-auth-google/releases/tag/v1.1.1).
I believe this came from #36.

** (exit) an exception was raised:                                                                                                                                                                                       ** (UndefinedFunctionError) function Mix.env/0 is undefined (module Mix is not available)
Mix.env() 
(elixir_auth_google) lib/elixir_auth_google.ex:11: ElixirAuthGoogle.inject_poison/0
(elixir_auth_google) lib/elixir_auth_google.ex:72: ElixirAuthGoogle.get_token/2
@nelsonic
Copy link
Member

@PaulOstazeski Thanks for opening this issue. We are investigating this now. 🔍

nelsonic added a commit to dwyl/elixir-auth-google-demo that referenced this issue Apr 20, 2020
@nelsonic
Copy link
Member

@PaulOstazeski could you please give us a bit more detail about the target environment where you are running your app? We have a demo version of this app: https://github.com/dwyl/elixir-auth-google-demo
which is using the latest version of the package {:elixir_auth_google, "~> 1.2.0"}
And is working fine for us: https://elixir-auth-google-demo.herokuapp.com/

Works as expected:
image

When we attempt to run MIX_ENV=prod mix release on our localhost
(Mac 10.15.4 with Elixir 1.10.1 (compiled with Erlang/OTP 22))

We see the following output:

Generated phoenix app
==> app
Compiling 13 files (.ex)
Generated app app
* assembling app-1.2.0 on MIX_ENV=prod
* skipping runtime configuration (config/releases.exs not found)
* skipping elixir.bat for windows (bin/elixir.bat not found in the Elixir installation)
* skipping iex.bat for windows (bin/iex.bat not found in the Elixir installation)

Release created at _build/prod/rel/app!

    # To start your system
    _build/prod/rel/app/bin/app start

Once the release is running:

    # To connect to it remotely
    _build/prod/rel/app/bin/app remote

    # To stop it gracefully (you may also send SIGINT/SIGTERM)
    _build/prod/rel/app/bin/app stop

To list all commands:

    _build/prod/rel/app/bin/app

Then when we run _build/prod/rel/app/bin/app start to star the app, it works as expected.
We aren't seeing any errors relating to MIX_ENV not being set.
If you can give us more detail (as much as possible) we can help debug.

Thanks.

@nelsonic
Copy link
Member

@PaulOstazeski can you please try using {:elixir_auth_google, "~> 1.2.0"} thanks!

@PaulOstazeski
Copy link
Author

Sure, I've got a bare-bones reproduction here. This was extracted from the project where we saw the issue and is using the same build script. The actual app is hosted on render.com. The README in the repo I'm sharing contains the steps to trigger the error.

@PaulOstazeski
Copy link
Author

I've kept researching, and I've found some seemingly similar issues elsewhere (or at least cases where folks found that the Mix module wasn't/isn't available in production).

@nelsonic
Copy link
Member

Yeah, that's really annoying. I wouldn't have expected it to throw an exception... 😞
@PaulOstazeski did you try adding :mix to your extra_applications list?
The same way that you added :guardian in mix.exs:
https://github.com/PaulOstazeski/elixirauthgoogleissue37/blob/75a76e3b55fa923731860f876808427cd3d06449/mix.exs#L23
As suggested in: https://elixirforum.com/t/mix-env-in-production-no-longer-produces-nil-but-crashes-mix-state-genserver/16165/4
That appears to make it available in the release and thus it will return Mix.env() >> :prod

@nelsonic nelsonic added the question Further information is requested label Apr 22, 2020
@PaulOstazeski
Copy link
Author

Yes, that does work. Thanks.

@nelsonic
Copy link
Member

@PaulOstazeski thanks for confirming that adding :mix to your extra_applications worked. 👍

@jtormey
Copy link
Contributor

jtormey commented Jun 2, 2021

I just hit this issue as well, and can confirm the :extra_applications fix does work.

This seems like it's more of a workaround though, since it's not usually necessary to include mix in production releases. Instead, it's possible to store this information at compile time so that there's no opportunity for a runtime error:

@compile_env Mix.env()

def inject_poison() do
  @compile_env == :test && ElixirAuthGoogle.HTTPoisonMock || HTTPoison
end

Happy to validate and open a PR if you'd like!

@nelsonic
Copy link
Member

nelsonic commented Jun 2, 2021

@jtormey if you have time, please open a PR adding this to the README.md 🙏

@nelsonic
Copy link
Member

nelsonic commented Jun 6, 2021

https://hex.pm/packages/elixir_auth_google/1.4.0 contains the update made by @jtormey with compile-time checking. :shipit:

@SimonLab SimonLab mentioned this issue Oct 11, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested user-feedback
Projects
None yet
Development

No branches or pull requests

3 participants