From 0061facd6448420f74981b9089b6e04e9fbe7cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Thu, 24 Jun 2021 18:03:00 +0200 Subject: [PATCH] Support configuring Attached as the default runtime (#397) * Support configuring Attached as the default runtime * Wrap env options section in the README --- README.md | 24 ++++++++++++++++-------- lib/livebook/config.ex | 17 +++++++++++++++++ lib/livebook_cli/server.ex | 3 ++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5e226d507..500e7d3a7 100644 --- a/README.md +++ b/README.md @@ -126,20 +126,28 @@ The following environment variables configure Livebook: * LIVEBOOK_COOKIE - sets the cookie for running Livebook in a cluster. Defaults to a random string that is generated on boot. - * LIVEBOOK_DEFAULT_RUNTIME - sets the runtime type that is used - by default when none is started explicitly for the given notebook. - Must be either "standalone" (Elixir standalone), "mix[:path]" (Mix standalone) - or "embedded" (Embedded). Defaults to "standalone". + * LIVEBOOK_DEFAULT_RUNTIME - sets the runtime type that is used by default + when none is started explicitly for the given notebook. Must be either + "standalone" (Elixir standalone), "mix[:PATH]" (Mix standalone), + "attached:NODE:COOKIE" (Standalone) or "embedded" (Embedded). + Defaults to "standalone". - * LIVEBOOK_IP - sets the ip address to start the web application on. Must be a valid IPv4 or IPv6 address. + * LIVEBOOK_IP - sets the ip address to start the web application on. + Must be a valid IPv4 or IPv6 address. - * LIVEBOOK_PASSWORD - sets a password that must be used to access Livebook. Must be at least 12 characters. Defaults to token authentication. + * LIVEBOOK_PASSWORD - sets a password that must be used to access Livebook. + Must be at least 12 characters. Defaults to token authentication. - * LIVEBOOK_PORT - sets the port Livebook runs on. If you want multiple instances to run on the same domain but different ports, you also need to set 'LIVEBOOK_SECRET_KEY_BASE'. Defaults to 8080. + * LIVEBOOK_PORT - sets the port Livebook runs on. If you want multiple instances + to run on the same domain but different ports, you also need to set 'LIVEBOOK_SECRET_KEY_BASE'. + Defaults to 8080. * LIVEBOOK_ROOT_PATH - sets the root path to use for file selection. - * LIVEBOOK_SECRET_KEY_BASE - sets a secret key that is used to sign and encrypt the session and other payloads used by Livebook. Must be at least 64 characters long and it can be generated by commands such as: 'openssl rand -base64 48'. Defaults to a random secret on every boot. + * LIVEBOOK_SECRET_KEY_BASE - sets a secret key that is used to sign and encrypt + the session and other payloads used by Livebook. Must be at least 64 characters + long and it can be generated by commands such as: 'openssl rand -base64 48'. + Defaults to a random secret on every boot. diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 9e458e6be..7de4c28db 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -177,6 +177,10 @@ defmodule Livebook.Config do abort!(~s{"#{path}" does not point to a Mix project}) end + "attached:" <> config -> + {node, cookie} = parse_connection_config!(config) + {Livebook.Runtime.Attached, [node, cookie]} + other -> abort!( ~s{expected #{context} to be either "standalone", "mix[:path]" or "embedded", got: #{inspect(other)}} @@ -195,6 +199,19 @@ defmodule Livebook.Config do end end + defp parse_connection_config!(config) do + [node, cookie] = String.split(config, ":", parts: 2) + + unless node =~ "@" do + abort!(~s{expected node to include hostname, got: #{inspect(node)}}) + end + + node = String.to_atom(node) + cookie = String.to_atom(cookie) + + {node, cookie} + end + @doc """ Aborts booting due to a configuration error. """ diff --git a/lib/livebook_cli/server.ex b/lib/livebook_cli/server.ex index 9c37da286..ec5aac0ab 100644 --- a/lib/livebook_cli/server.ex +++ b/lib/livebook_cli/server.ex @@ -24,7 +24,8 @@ defmodule LivebookCLI.Server do explicitly for the given notebook, defaults to standalone Supported options: * standalone - Elixir standalone - * mix[:path] - Mix standalone + * mix[:PATH] - Mix standalone + * attached:NODE:COOKIE - Attached * embedded - Embedded --ip The ip address to start the web application on, defaults to 127.0.0.1 Must be a valid IPv4 or IPv6 address