Using project's .iex.exs with gigalixir ps:remote_console

Gigalixir lets us start a remote shell, similar to iex --remsh. The command is:

gigalixir ps:remote_console -a my-app

Does anyone know if there is a way to make this shell use my project’s .iex.exs. I want this because my .iex.exs contains lots of nice aliases. I get very tired of typing alias MyApp.SomeContext.SomeModule.

2 Likes

You can do this:

1 Like

This is a perfect workaround for my use case but I cannot mark it “solution” unless we are sure there is no way to use the project iex.exs in gigalixir remote_console.

Thanks very much for this simple brilliant idea. :+1:

Afaik releases don’t work with .iex.exs, but I’m not 100% sure about that.

I noticed than when building the release locally and connecting to it, it works:

myapp$ cat .iex.exs
IO.puts "it works"
# terminal 1
myapp$ _build/dev/rel/myapp/bin/myapp start

# terminal 2
myapp$ _build/dev/rel/myapp/bin/myapp remote
it works

However, if I start the release from another directory, it doesn’t work:

# terminal 1
_build/dev/rel/myapp$ bin/myapp start

# terminal 2
myapp$ _build/dev/rel/myapp/bin/myapp remote
(no output)

It seems it’s a matter of where you start your release from and whether that
directory contains the .iex.exs file and so you could change your :releases
Mix configuration to copy the file into appropriate location.

I did notice one thing that while executing code or setting up aliases in the
.iex.exs file work, autocomplete of these aliases does not so it’s seems
it’s not fully supported.

1 Like

Aha, that’s my problem. I was doing it with a monorepo where the .iex.exs was in a subdirectory. Thanks!

Sounds like one could create a release step bundling a local .iex.exs like config/releases.exs and editing remote_console, so it automatically loads from there.

What do you mean by "editing remote_console"?

Modifying this part in the created binary you call with bin/myapp remote, so it automatically loads the .iex.exs from wherever it is stored.

1 Like

OK so I moved from doing Mix releases to doing Elixir releases with clustering and I discovered that the .iex.exs simply is nowhere on the deployed instance:

connect to instance:

gigalixir ps:remote_console

search for .iex.exs:

System.cmd("find", ["/", "-name", ".iex.exs"]) 

returns:

{"", 0} 

so I guess the release doesn’t include the .iex.exs. I am starting to understand more now.

I have no idea how to do this with a gigalixir release.

Perhaps you can try adding the .iex.exs file as an overlay to get it included in the release. https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-options

2 Likes

aha! I will try this.

This is the solution! I just copied my project’s .iex.exs to rel/overlays/.iex.exs and re-deployed and YATA! it worked!

Thanks @jesse

2 Likes

I’ve said it before and I’ll say it again. This forum is sooo good. The advice people give is such high-quality. It’s like living next to the Mage’s Guild.

3 Likes

I did this but it appears not to work for using Distillery like in this guide: https://elixircasts.io/deploying-with-gigalixir-%28revised%29

Am I wrong about this or is there another way to do this with Distillery?

Ah yeah, distillery does overlays slightly differently from elixir releases. You’ll probably need to edit your rel/config.exs file. See https://hexdocs.pm/distillery/extensibility/overlays.html

1 Like

Thanks for this, I’m still not understanding how to use this to set the overlays to use the .iex.exs file in the rel/overlays/ directory.

Also, after we set this up in the config do we need to create another release or just deploy to gigalixir?

Basically, what’s happening is the Distillery packs up a bunch of stuff into a tarball, but it normally doesn’t include the .iex.exs file so when you remote console into production, the .iex.exs file isn’t there. Elixir releases, which is different from Distillery, will just pick up anything in the rel/overlays directory and include it in the tarball, but I don’t think distillery does that. You have to actually modify your rel/config.exs file and tell it which files you want to include with something like this (untested)

  set overlays: [
    {:copy, ".iex.exs", ".iex.exs"}
  ]

Once everything is configured correctly, just commit to git and re-deploy. Gigalixir automatically recreates the release for you.

1 Like

this worked for me, thanks!