mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-10 06:01:44 +08:00
Encapsulate compile and runtime configuration (#577)
This commit is contained in:
parent
ac60aba2fb
commit
354aae9467
3 changed files with 55 additions and 41 deletions
|
|
@ -1,41 +1,2 @@
|
||||||
import Config
|
import Config
|
||||||
require Logger
|
Livebook.config_runtime()
|
||||||
|
|
||||||
config :livebook, LivebookWeb.Endpoint,
|
|
||||||
secret_key_base:
|
|
||||||
Livebook.Config.secret!("LIVEBOOK_SECRET_KEY_BASE") ||
|
|
||||||
Base.encode64(:crypto.strong_rand_bytes(48))
|
|
||||||
|
|
||||||
if password = Livebook.Config.password!("LIVEBOOK_PASSWORD") do
|
|
||||||
config :livebook, authentication_mode: :password, password: password
|
|
||||||
else
|
|
||||||
config :livebook, token: Livebook.Utils.random_id()
|
|
||||||
end
|
|
||||||
|
|
||||||
if port = Livebook.Config.port!("LIVEBOOK_PORT") do
|
|
||||||
config :livebook, LivebookWeb.Endpoint, http: [port: port]
|
|
||||||
end
|
|
||||||
|
|
||||||
if ip = Livebook.Config.ip!("LIVEBOOK_IP") do
|
|
||||||
config :livebook, LivebookWeb.Endpoint, http: [ip: ip]
|
|
||||||
end
|
|
||||||
|
|
||||||
config :livebook,
|
|
||||||
:cookie,
|
|
||||||
Livebook.Config.cookie!("LIVEBOOK_COOKIE") ||
|
|
||||||
Livebook.Config.cookie!("RELEASE_COOKIE") ||
|
|
||||||
Livebook.Utils.random_cookie()
|
|
||||||
|
|
||||||
config :livebook,
|
|
||||||
:default_runtime,
|
|
||||||
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
|
|
||||||
{Livebook.Runtime.ElixirStandalone, []}
|
|
||||||
|
|
||||||
root_path =
|
|
||||||
Livebook.Config.root_path!("LIVEBOOK_ROOT_PATH")
|
|
||||||
|> Livebook.FileSystem.Utils.ensure_dir_path()
|
|
||||||
|
|
||||||
local_file_system = Livebook.FileSystem.Local.new(default_path: root_path)
|
|
||||||
configured_file_systems = Livebook.Config.file_systems!("LIVEBOOK_FILE_SYSTEM_")
|
|
||||||
|
|
||||||
config :livebook, :file_systems, [local_file_system | configured_file_systems]
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,58 @@ defmodule Livebook do
|
||||||
This module includes the public API.
|
This module includes the public API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Executes Livebook's config/runtime.exs.
|
||||||
|
|
||||||
|
If you use Livebook as a dependency, you can add the following
|
||||||
|
to your `config/runtime.exs` to trigger Livebook's config/runtime.exs
|
||||||
|
configuration:
|
||||||
|
|
||||||
|
Livebook.config_runtime()
|
||||||
|
|
||||||
|
"""
|
||||||
|
def config_runtime do
|
||||||
|
import Config
|
||||||
|
|
||||||
|
config :livebook, LivebookWeb.Endpoint,
|
||||||
|
secret_key_base:
|
||||||
|
Livebook.Config.secret!("LIVEBOOK_SECRET_KEY_BASE") ||
|
||||||
|
Base.encode64(:crypto.strong_rand_bytes(48))
|
||||||
|
|
||||||
|
if port = Livebook.Config.port!("LIVEBOOK_PORT") do
|
||||||
|
config :livebook, LivebookWeb.Endpoint, http: [port: port]
|
||||||
|
end
|
||||||
|
|
||||||
|
if ip = Livebook.Config.ip!("LIVEBOOK_IP") do
|
||||||
|
config :livebook, LivebookWeb.Endpoint, http: [ip: ip]
|
||||||
|
end
|
||||||
|
|
||||||
|
if password = Livebook.Config.password!("LIVEBOOK_PASSWORD") do
|
||||||
|
config :livebook, authentication_mode: :password, password: password
|
||||||
|
else
|
||||||
|
config :livebook, token: Livebook.Utils.random_id()
|
||||||
|
end
|
||||||
|
|
||||||
|
if runtime = Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") do
|
||||||
|
config :livebook, :default_runtime, runtime
|
||||||
|
end
|
||||||
|
|
||||||
|
config :livebook,
|
||||||
|
:cookie,
|
||||||
|
Livebook.Config.cookie!("LIVEBOOK_COOKIE") ||
|
||||||
|
Livebook.Config.cookie!("RELEASE_COOKIE") ||
|
||||||
|
Livebook.Utils.random_cookie()
|
||||||
|
|
||||||
|
root_path =
|
||||||
|
Livebook.Config.root_path!("LIVEBOOK_ROOT_PATH")
|
||||||
|
|> Livebook.FileSystem.Utils.ensure_dir_path()
|
||||||
|
|
||||||
|
local_file_system = Livebook.FileSystem.Local.new(default_path: root_path)
|
||||||
|
configured_file_systems = Livebook.Config.file_systems!("LIVEBOOK_FILE_SYSTEM_")
|
||||||
|
|
||||||
|
config :livebook, :file_systems, [local_file_system | configured_file_systems]
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Parses the given Live Markdown document and converts it to Elixir
|
Parses the given Live Markdown document and converts it to Elixir
|
||||||
source code.
|
source code.
|
||||||
|
|
|
||||||
3
mix.exs
3
mix.exs
|
|
@ -24,7 +24,8 @@ defmodule Livebook.MixProject do
|
||||||
def application do
|
def application do
|
||||||
[
|
[
|
||||||
mod: {Livebook.Application, []},
|
mod: {Livebook.Application, []},
|
||||||
extra_applications: [:logger, :runtime_tools, :os_mon, :inets, :ssl, :xmerl]
|
extra_applications: [:logger, :runtime_tools, :os_mon, :inets, :ssl, :xmerl],
|
||||||
|
env: Application.get_all_env(:livebook)
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue