I’ve been loving Livebook for prototyping and interacting with my apps. It’s become an essential tool for me. I’m especially stoked about its new “deploy as app” feature and have been trying to get it to work attached to my node.
Here’s what I’m dealing with:
I’ve got a Livebook running locally as an admin interface for my production app, and it attaches to a remote node without a problem. This is working great for me, but I’ve been hoping to share some of these admin features with my non-programmer colleagues, so I’ve been trying to deploy them as apps.
So, I got a Livebook up and running on Fly.io and it connects to my production node just fine. But when I try to save it as an app, I hit a roadblock. I get an error that the code can’t find the modules I’m references as it’s not connected to the remote node.
What I’ve tried
I tried setting the env variable
For full context, these are the ENV variables that are being set:
ELIXIR_ERL_OPTIONS = "-proto_dist inet6_tcp"
LIVEBOOK_APP_SERVICE_NAME = "Fly.io - app_name"
LIVEBOOK_APP_SERVICE_URL = "https://fly.io/apps/app_name"
LIVEBOOK_DATA_PATH = "/data"
LIVEBOOK_HOME = "/data"
LIVEBOOK_IP = "::"
LIVEBOOK_ROOT_PATH = "/data"
LIVEBOOK_UPDATE_INSTRUCTIONS_URL = "https://fly.io/apps/app_name"
LIVEBOOK_DEFAULT_RUNTIME = "attached:node_name@cookie"
PORT = "8080"
Any help is appreciated. Just want to make sure whether what I’m trying to accomplished is support / possible. If not, then Ill figure something else out. Thanks everyone!
Hey, apps always run using the standalone Elixir runtime (not the Attached one). This is by design, because apps generally make use of Kino packages for UI, and adding those as dependencies to your production application is not recommended. You can connect from your app notebook to the production node using
Node.connect/1, then you can use
:erpc to fetch data from the production node and visualise it in the app using whatever packages you want : )
Awesome, that totally makes sense now. Thanks a ton for the quick and clear explanation, it really helps. Livebook’s really blowing my mind with all its features.
Just one more thing, if you don’t mind. Why’s it not the best idea to add Kino as a dependency to the production app? Trying to get a solid grip on this.
Again, big thanks for your help and for all the cool work you all are doing on Livebook!
Why’s it not the best idea to add Kino as a dependency to the production app?
It makes sense to avoid unnecessary dependencies in your application (reducing compilation time, release footprint, etc). With this approach you would need to add more dependencies as you want to do more things in the notebooks, for example if you want charts, you need
:kino_vega_lite, and you may even want other packages like
:explorer to analyse the data, this would quickly accumulate. And then if you want to use a newer version of those packages you need to bump them and potentially update old notebooks. Using the manual connect approach, each notebook can have different dependencies and they have no impact on your production application whatsoever.
On a separate note, another benefit of the standalone runtime is more isolation. For example if you do some expensive analysis with
:explorer, it doesn’t increase load on your production node. In an edge case you could even run something that would kill the runtime, so again the isolation helps : )
Thanks Jonatan for taking the time and reason me through it. Much appreciated and makes total sense.