mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-05 04:24:21 +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
8 changed files with 76 additions and 28 deletions
|
@ -118,6 +118,14 @@ defmodule Livebook do
|
||||||
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
||||||
Livebook.Runtime.ElixirStandalone.new()
|
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
|
if home = Livebook.Config.writable_dir!("LIVEBOOK_HOME") do
|
||||||
config :livebook, :home, home
|
config :livebook, :home, home
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,15 @@ defmodule Livebook.Config do
|
||||||
Application.fetch_env!(:livebook, :default_runtime)
|
Application.fetch_env!(:livebook, :default_runtime)
|
||||||
end
|
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 """
|
@doc """
|
||||||
Returns the authentication mode.
|
Returns the authentication mode.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.AttachedLive do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
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
|
if connected?(socket) do
|
||||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.ElixirStandaloneLive do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
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
|
if connected?(socket) do
|
||||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.EmbeddedLive do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
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
|
if connected?(socket) do
|
||||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,10 @@ defmodule LivebookWeb.SessionLive.MixStandaloneLive do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do
|
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
|
if connected?(socket) do
|
||||||
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,34 +30,42 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do
|
||||||
</h3>
|
</h3>
|
||||||
<div class="w-full flex-col space-y-5">
|
<div class="w-full flex-col space-y-5">
|
||||||
<div class="flex space-x-4">
|
<div class="flex space-x-4">
|
||||||
<.choice_button
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.ElixirStandalone) do %>
|
||||||
active={@type == "elixir_standalone"}
|
<.choice_button
|
||||||
phx-click="set_runtime_type"
|
active={@type == "elixir_standalone"}
|
||||||
phx-value-type="elixir_standalone"
|
phx-click="set_runtime_type"
|
||||||
phx-target={@myself}>
|
phx-value-type="elixir_standalone"
|
||||||
Elixir standalone
|
phx-target={@myself}>
|
||||||
</.choice_button>
|
Elixir standalone
|
||||||
<.choice_button
|
</.choice_button>
|
||||||
active={@type == "mix_standalone"}
|
<% end %>
|
||||||
phx-click="set_runtime_type"
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.MixStandalone) do %>
|
||||||
phx-value-type="mix_standalone"
|
<.choice_button
|
||||||
phx-target={@myself}>
|
active={@type == "mix_standalone"}
|
||||||
Mix standalone
|
phx-click="set_runtime_type"
|
||||||
</.choice_button>
|
phx-value-type="mix_standalone"
|
||||||
<.choice_button
|
phx-target={@myself}>
|
||||||
active={@type == "attached"}
|
Mix standalone
|
||||||
phx-click="set_runtime_type"
|
</.choice_button>
|
||||||
phx-value-type="attached"
|
<% end %>
|
||||||
phx-target={@myself}>
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Attached) do %>
|
||||||
Attached node
|
<.choice_button
|
||||||
</.choice_button>
|
active={@type == "attached"}
|
||||||
<.choice_button
|
phx-click="set_runtime_type"
|
||||||
active={@type == "embedded"}
|
phx-value-type="attached"
|
||||||
phx-click="set_runtime_type"
|
phx-target={@myself}>
|
||||||
phx-value-type="embedded"
|
Attached node
|
||||||
phx-target={@myself}>
|
</.choice_button>
|
||||||
Embedded
|
<% end %>
|
||||||
</.choice_button>
|
<%= 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>
|
||||||
<div>
|
<div>
|
||||||
<%= live_render @socket, live_view_for_type(@type),
|
<%= live_render @socket, live_view_for_type(@type),
|
||||||
|
|
|
@ -11,6 +11,13 @@ Livebook.Runtime.ErlDist.NodeManager.start(
|
||||||
# and setting them explicitly
|
# and setting them explicitly
|
||||||
Application.put_env(:livebook, :default_runtime, Livebook.Runtime.Embedded.new())
|
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
|
defmodule Livebook.Runtime.Embedded.Dependencies do
|
||||||
def entries() do
|
def entries() do
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Reference in a new issue