Skip to content

Commit

Permalink
Add app service settings (livebook-dev#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByeongUkChoi authored Apr 15, 2022
1 parent 35b3fae commit bfd47fd
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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.

<!-- Environment variables -->

If running Livebook as a Docker image or an Elixir release, [the environment
Expand Down
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ config :mime, :types, %{
}

config :livebook,
app_service_name: nil,
app_service_url: nil,
authentication_mode: :token,
explore_notebooks: [],
plugs: [],
Expand Down
8 changes: 8 additions & 0 deletions lib/livebook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
30 changes: 30 additions & 0 deletions lib/livebook/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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.
"""
Expand Down
12 changes: 12 additions & 0 deletions lib/livebook_web/live/settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ defmodule LivebookWeb.SettingsLive do
</h1>
<div class="flex items-center justify-between border border-gray-200 rounded-lg p-4">
<div class="flex items-center space-x-12">
<%= if app_name = Livebook.Config.app_service_name() do %>
<div class="flex flex-col space-y-1">
<span class="text-sm text-gray-500">Application</span>
<span class="text-gray-800 text-sm font-semibold">
<%= if app_url = Livebook.Config.app_service_url() do %>
<a href={app_url} target="_blank"><%= app_name %></a>
<% else %>
<%= app_name %>
<% end %>
</span>
</div>
<% end %>
<.labeled_text label="Livebook" text={"v#{Application.spec(:livebook, :vsn)}"} />
<.labeled_text label="Elixir" text={"v#{System.version()}"} />
</div>
Expand Down

0 comments on commit bfd47fd

Please sign in to comment.