mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 10:05:57 +08:00
allow embedded runtime by env (#1084)
* allow embedded runtime by env * fix session live test * This reverts commit f36931d6ef9b..81ca7d * allow runtime modules * Apply suggestions from code review
This commit is contained in:
parent
902c993098
commit
e3d9c5fa35
|
@ -118,6 +118,14 @@ defmodule Livebook do
|
|||
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
||||
Livebook.Runtime.ElixirStandalone.new()
|
||||
|
||||
config :livebook,
|
||||
:runtime_modules,
|
||||
[
|
||||
Livebook.Runtime.ElixirStandalone,
|
||||
Livebook.Runtime.MixStandalone,
|
||||
Livebook.Runtime.Attached
|
||||
]
|
||||
|
||||
if home = Livebook.Config.writable_dir!("LIVEBOOK_HOME") do
|
||||
config :livebook, :home, home
|
||||
end
|
||||
|
|
|
@ -26,6 +26,15 @@ defmodule Livebook.Config do
|
|||
Application.fetch_env!(:livebook, :default_runtime)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns if the runtime module is enabled.
|
||||
"""
|
||||
@spec runtime_enabled?(module()) :: boolean()
|
||||
def runtime_enabled?(runtime) do
|
||||
runtime in Application.fetch_env!(:livebook, :runtime_modules) or
|
||||
runtime == default_runtime().__struct__
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the authentication mode.
|
||||
"""
|
||||
|
|
|
@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.AttachedLive do
|
|||
|
||||
@impl true
|
||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
||||
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Attached) do
|
||||
raise "runtime module not allowed"
|
||||
end
|
||||
|
||||
if connected?(socket) do
|
||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||
end
|
||||
|
|
|
@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.ElixirStandaloneLive do
|
|||
|
||||
@impl true
|
||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
||||
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.ElixirStandalone) do
|
||||
raise "runtime module not allowed"
|
||||
end
|
||||
|
||||
if connected?(socket) do
|
||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||
end
|
||||
|
|
|
@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.EmbeddedLive do
|
|||
|
||||
@impl true
|
||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
||||
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Embedded) do
|
||||
raise "runtime module not allowed"
|
||||
end
|
||||
|
||||
if connected?(socket) do
|
||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||
end
|
||||
|
|
|
@ -7,6 +7,10 @@ defmodule LivebookWeb.SessionLive.MixStandaloneLive do
|
|||
|
||||
@impl true
|
||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
||||
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.MixStandalone) do
|
||||
raise "runtime module not allowed"
|
||||
end
|
||||
|
||||
if connected?(socket) do
|
||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||
end
|
||||
|
|
|
@ -30,34 +30,42 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do
|
|||
</h3>
|
||||
<div class="w-full flex-col space-y-5">
|
||||
<div class="flex space-x-4">
|
||||
<.choice_button
|
||||
active={@type == "elixir_standalone"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="elixir_standalone"
|
||||
phx-target={@myself}>
|
||||
Elixir standalone
|
||||
</.choice_button>
|
||||
<.choice_button
|
||||
active={@type == "mix_standalone"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="mix_standalone"
|
||||
phx-target={@myself}>
|
||||
Mix standalone
|
||||
</.choice_button>
|
||||
<.choice_button
|
||||
active={@type == "attached"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="attached"
|
||||
phx-target={@myself}>
|
||||
Attached node
|
||||
</.choice_button>
|
||||
<.choice_button
|
||||
active={@type == "embedded"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="embedded"
|
||||
phx-target={@myself}>
|
||||
Embedded
|
||||
</.choice_button>
|
||||
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.ElixirStandalone) do %>
|
||||
<.choice_button
|
||||
active={@type == "elixir_standalone"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="elixir_standalone"
|
||||
phx-target={@myself}>
|
||||
Elixir standalone
|
||||
</.choice_button>
|
||||
<% end %>
|
||||
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.MixStandalone) do %>
|
||||
<.choice_button
|
||||
active={@type == "mix_standalone"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="mix_standalone"
|
||||
phx-target={@myself}>
|
||||
Mix standalone
|
||||
</.choice_button>
|
||||
<% end %>
|
||||
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Attached) do %>
|
||||
<.choice_button
|
||||
active={@type == "attached"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="attached"
|
||||
phx-target={@myself}>
|
||||
Attached node
|
||||
</.choice_button>
|
||||
<% end %>
|
||||
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Embedded) do %>
|
||||
<.choice_button
|
||||
active={@type == "embedded"}
|
||||
phx-click="set_runtime_type"
|
||||
phx-value-type="embedded"
|
||||
phx-target={@myself}>
|
||||
Embedded
|
||||
</.choice_button>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<%= live_render @socket, live_view_for_type(@type),
|
||||
|
|
|
@ -11,6 +11,13 @@ Livebook.Runtime.ErlDist.NodeManager.start(
|
|||
# and setting them explicitly
|
||||
Application.put_env(:livebook, :default_runtime, Livebook.Runtime.Embedded.new())
|
||||
|
||||
Application.put_env(:livebook, :runtime_modules, [
|
||||
Livebook.Runtime.ElixirStandalone,
|
||||
Livebook.Runtime.MixStandalone,
|
||||
Livebook.Runtime.Attached,
|
||||
Livebook.Runtime.Embedded
|
||||
])
|
||||
|
||||
defmodule Livebook.Runtime.Embedded.Dependencies do
|
||||
def entries() do
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue