For whatever reason this appears to have stopped working for us on Gigalixir. Any ideas why this might be the case?
(Asking this here in case anyone else is experiencing this problem and stumbles across this thread)
While not an exact solution, but something that might work regardless of the deployment platform:
Move your imports / aliases from .iex.ex
to a help.ex
module, e.g.:
defmodule Help do
defmacro __using__ (_opts) do
quote do
import Ecto.Query, warn: false
# ...etc
end
end
end
and then in your .iex.ex
simply add one line:
use Help
Then whenever you are in the production console, simply type use Help
and it will import everything.
While in development, everything will be imported by default via .iex.ex
The benefit of iex.exs
is being able to print helpful reminder messages in a production/staging/dev shell.
Example:
is_staging = !!System.get_env("IS_STAGING")
mix_env =
case {System.get_env("MIX_ENV"), Application.get_env(:my_app, :env)} do
{"prod", :prod} -> :prod
{_, :test} -> :test
{_, :dev} -> :dev
_ -> :unknown
end
print_warning = fn message ->
IO.puts(IO.ANSI.red_background() <> message <> IO.ANSI.blink_rapid() <> IO.ANSI.reset())
end
print_info = fn message ->
IO.puts(IO.ANSI.cyan_background() <> message <> IO.ANSI.reset())
end
print_warning_if_prod = fn ->
case {mix_env, is_staging} do
{:prod, false} ->
for message <- ["⚠ REMINDER:", "👿 THIS IS THE PROD SHELL!", "🙇 PLEASE BE CAREFUL."] do
print_warning.(message)
end
{:prod, true} ->
print_warning.("👷 this is the staging shell")
{_, _} ->
print_info.("Welcome to MyApp, Dev 👽")
end
end
print_warning_if_prod.()
print_info.(" 🌎 Your region: " <> System.get_env("FLY_REGION", "local-dev"))
With the above (or similar) in the iex.exs
file, connecting to remote shells is safer. The developer is reminded of the environment.
1 Like