Inside the default runner Docker image provided by Phoenix Elixir is not available, so we can’t execute something like
elixir priv/script.exs
. But we can load the file usingCode.load_file/1
.Here’s how it’s done.
# SSH into the machinefly ssh console # on Fly.iokamal app exec --reuse -i bash # on Kamal# Connect via a remote shellbin/my_app remote# Execute the scriptiex> Code.load_file(Path.join([:code.priv_dir(:my_app), "script.exs"]))Note that Mix is not available inside releases, so you won’t be able to install dependencies using
Mix.install/1
. Instead, you’ll have to include them in yourmix.exs
file or avoid using them entirely.To keep this in your terminal’s history, you could SSH into the machine and execute the script all in one step:
# on Fly.iofly ssh console \-C "bin/my_app rpc 'Code.load_file(Path.join([:code.priv_dir(:my_app), \"script.exs\"]))'"# on Kamalkamal app exec --reuse \-i "bin/my_app rpc 'Code.load_file(Path.join([:code.priv_dir(:my_app), \"script.exs\"]))'"
continue reading on elixirdrops.net
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.