From bfd47fd166bd2d213a917bac3317bf50bf08213a Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Fri, 15 Apr 2022 20:46:26 +0900 Subject: [PATCH] Add app service settings (#1116) --- README.md | 12 ++++++++--- config/config.exs | 2 ++ lib/livebook.ex | 8 +++++++ lib/livebook/config.ex | 30 ++++++++++++++++++++++++++ lib/livebook_web/live/settings_live.ex | 12 +++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c4b782418..75d9818df 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,12 @@ Livebook if said token is supplied as part of the URL. The following environment variables configure Livebook: + * LIVEBOOK_APP_SERVICE_NAME - sets the application name used by the cloud + provider to aid debugging. + + * LIVEBOOK_APP_SERVICE_URL - sets the application url to manage this + Livebook instance within the cloud provider platform. + * LIVEBOOK_COOKIE - sets the cookie for running Livebook in a cluster. Defaults to a random string that is generated on boot. @@ -157,6 +163,9 @@ The following environment variables configure Livebook: "attached:NODE:COOKIE" (Attached node) or "embedded" (Embedded). Defaults to "standalone". + * LIVEBOOK_FORCE_SSL_HOST - sets a host to redirect to if the request is not over HTTP. + Note it does not apply when accessing Livebook via localhost. Defaults to nil. + * LIVEBOOK_HOME - sets the home path for the Livebook instance. This is the default path used on file selection screens and others. Defaults to the user's operating system home. @@ -187,9 +196,6 @@ The following environment variables configure Livebook: Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to disable it. - * LIVEBOOK_FORCE_SSL_HOST - set a host to redirect to if the request is not over HTTP. - Note it does not apply when accessing Livebook via localhost. Defaults to nil. - If running Livebook as a Docker image or an Elixir release, [the environment diff --git a/config/config.exs b/config/config.exs index a0cf0b4a4..ded1955cc 100644 --- a/config/config.exs +++ b/config/config.exs @@ -20,6 +20,8 @@ config :mime, :types, %{ } config :livebook, + app_service_name: nil, + app_service_url: nil, authentication_mode: :token, explore_notebooks: [], plugs: [], diff --git a/lib/livebook.ex b/lib/livebook.ex index d370255f1..236449d99 100644 --- a/lib/livebook.ex +++ b/lib/livebook.ex @@ -147,6 +147,14 @@ defmodule Livebook do Livebook.Config.cookie!("LIVEBOOK_COOKIE") || Livebook.Config.cookie!("RELEASE_COOKIE") || Livebook.Utils.random_cookie() + + if app_service_name = Livebook.Config.app_service_name!("LIVEBOOK_APP_SERVICE_NAME") do + config :livebook, :app_service_name, app_service_name + + config :livebook, + :app_service_url, + Livebook.Config.app_service_url!("LIVEBOOK_APP_SERVICE_URL") + end end @doc """ diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 15e802f18..49af96354 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -106,6 +106,22 @@ defmodule Livebook.Config do Application.fetch_env!(:livebook, :shutdown_enabled) end + @doc """ + Returns the application service name. + """ + @spec app_service_name() :: String.t() | nil + def app_service_name() do + Application.fetch_env!(:livebook, :app_service_name) + end + + @doc """ + Returns the application service url. + """ + @spec app_service_url() :: String.t() | nil + def app_service_url() do + Application.fetch_env!(:livebook, :app_service_url) + end + ## Parsing @doc """ @@ -224,6 +240,20 @@ defmodule Livebook.Config do System.get_env(env) end + @doc """ + Parses application service name from env. + """ + def app_service_name!(env) do + System.get_env(env) + end + + @doc """ + Parses application service url from env. + """ + def app_service_url!(env) do + System.get_env(env) + end + @doc """ Parses and validates default runtime from env. """ diff --git a/lib/livebook_web/live/settings_live.ex b/lib/livebook_web/live/settings_live.ex index 02e7d3abd..43970ad27 100644 --- a/lib/livebook_web/live/settings_live.ex +++ b/lib/livebook_web/live/settings_live.ex @@ -50,6 +50,18 @@ defmodule LivebookWeb.SettingsLive do
+ <%= if app_name = Livebook.Config.app_service_name() do %> +
+ Application + + <%= if app_url = Livebook.Config.app_service_url() do %> + <%= app_name %> + <% else %> + <%= app_name %> + <% end %> + +
+ <% end %> <.labeled_text label="Livebook" text={"v#{Application.spec(:livebook, :vsn)}"} /> <.labeled_text label="Elixir" text={"v#{System.version()}"} />