Speedrun
- Create a
fly.tomlfile with the contents in the next section. fly launch --no-deployfly secrets set LIVEBOOK_PASSWORD="<my-super-sekrit-password>"fly deploy --vm-size shared-cpu-2x --volume-initial-size 1fly apps open
Prepare a Fly Launch config
Fly Launch uses a TOML configuration file—calledfly.toml by default.
Prepare a directory for your Livebook app config and place a fly.toml file inside, with the following contents:
fly deploy.
Create a new Fly app
Create a new app by runningfly launch from the directory containing the app’s fly.toml config file.
Y to copy the configuration from your existing fly.toml to the new app. You’ll be asked for an app name and a primary region, which will be added to your local fly.toml. The app name must be unique across Fly.io. The primary region is the region where Machines are created for this app when not otherwise specified.
Set a Livebook password
Livebook stores your password in an environment variable. Set that variable securely usingfly secrets set.
Deploy the app
Now that the app has been created and theLIVEBOOK_PASSWORD secret is set, you can deploy to a Machine.
The fly deploy command creates a new release of an app using the fly.toml in your working directory, and rolls that out to its Machines.
The first time it’s run on a given app, and when it’s run on an app that currently doesn’t have any Machines, fly deploy does some extra work. For our Livebook app, it provisions public IP addresses for the HTTP service and creates the volume referred to in the mounts section in fly.toml, before creating and starting the app’s Machine(s).
fly deploy command accepts some options to tune the initial resource provisioning.
Livebook seems to want something a bit heftier than the default shared-cpu-1x Machine with 256MB RAM, so for the purpose of demonstration we chose a shared-cpu-2x size, which comes with 512MB. You can experiment with CPU and memory to see what you need for your project.
We explicitly set the size of the volume to be created, although 1GB happens to be the default size for a new volume created on fly deploy.
At the time of writing, you may see this error message as the first deployment finishes:
WARNING The app is not listening on the expected address and will not be reachable by fly-proxy.If you can reach your Livebook in the browser, then you can ignore this message. Occasionally, provisioning the storage volume can delay startup of Livebook until after this check times out.Visit your Livebook app
To use your Livebook, visithttps://<your-app-name>.fly.dev in the browser, or type fly apps open, and enter your password where prompted. Create a new notebook, and save it in the /data directory.
You can test that your notebook was saved onto the persistent volume by running fly apps restart and clicking “Open” on the Livebook home page to find and open it from storage.
A note on auto start and stop settings
Theauto_stop_machines and auto_start_machines config options are set to true in the app config. The Fly proxy will shut down the Machine when there’s nobody connected to it. Livebook does try to save even “unsaved notebooks,” but principle you can lose data if it shuts down and you have not saved your work.
The proxy will also start the Machine when a connection is requested. This means bots may wake up your app.
When you visit the app when it’s stopped, it will take a moment before it’s running again.
If you’d rather start and stop your Livebook app manually, you can do so directly with flyctl. Set auto_stop_machines and auto_start_machines both to false, and redeploy. Use the fly machine stop and fly machine start commands to stop the Machine when you’re not using it and to start it up again when you’re ready.