Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Livebook Integration #478

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hexpm/elixir:1.15.7-erlang-26.1.2-alpine-3.18.4 AS build
FROM hexpm/elixir:1.17.2-erlang-27.0-alpine-3.18.7 AS build

# install build dependencies
RUN \
Expand Down Expand Up @@ -45,7 +45,7 @@ RUN mix deps.compile
RUN mix do compile, release

# prepare release image
FROM alpine:3.18.5 AS app
FROM alpine:3.18.7 AS app

# install runtime dependencies
RUN \
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-armv7
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM arm32v7/elixir:1.14-otp-25-alpine AS build
FROM arm32v7/elixir:1.17.2-otp-27-alpine AS build

# install build dependencies
RUN \
Expand Down Expand Up @@ -47,7 +47,7 @@ RUN cd apps/ex_nvr_web && mix assets.deploy
RUN mix do compile, release

# prepare release image
FROM alpine:3.17.5 AS app
FROM alpine:3.18.7 AS app

# install runtime dependencies
RUN \
Expand Down
6 changes: 3 additions & 3 deletions apps/ex_nvr/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ defmodule ExNVR.MixProject do
{:bundlex, "~> 1.4.6"},
{:bcrypt_elixir, "~> 3.0"},
{:phoenix_pubsub, "~> 2.1"},
{:ecto_sql, "~> 3.6"},
{:ecto_sqlite3, ">= 0.0.0"},
{:ecto_sql, "~> 3.11.3"},
{:ecto_sqlite3, "~> 0.16.0"},
{:ecto_sqlite3_extras, "~> 1.2.0"},
{:jason, "~> 1.2"},
{:swoosh, "~> 1.15"},
Expand All @@ -64,7 +64,7 @@ defmodule ExNVR.MixProject do
{:turbojpeg, "~> 0.4.0"},
{:ex_aws, "~> 2.5"},
{:ex_aws_s3, "~> 2.5"},
{:flop, "~> 0.22.1"},
{:flop, "~> 0.26.1"},
{:soap, github: "gBillal/soap", branch: "parse-attributes"},
{:req, "~> 0.4.0"},
{:multipart, "~> 0.4.0"},
Expand Down
2 changes: 1 addition & 1 deletion apps/ex_nvr_web/lib/ex_nvr_web/components/flop_config.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule ExNVRWeb.FlopConfig do
import Phoenix.HTML.Tag
use PhoenixHTMLHelpers

def table_opts do
[
Expand Down
13 changes: 8 additions & 5 deletions apps/ex_nvr_web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@ defmodule ExNVRWeb.MixProject do
{:floki, "~> 0.36.0"},
{:phoenix, "~> 1.7.2"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_html, "~> 3.3"},
{:phoenix_html, "~> 4.1.1"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.20.0"},
{:phoenix_live_view, "~> 1.0.0-rc.5"},
{:phoenix_live_dashboard, "~> 0.8.1"},
{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_metrics, "~> 0.6", override: true},
{:telemetry_poller, "~> 1.0"},
{:gettext, "~> 0.20"},
{:ex_nvr, in_umbrella: true},
{:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"},
{:corsica, "~> 2.1"},
{:logger_json, "~> 5.1"},
{:flop_phoenix, "~> 0.21.1"},
{:flop_phoenix, "~> 0.23.0"},
{:prom_ex, "~> 1.9.0"},
{:mock, "~> 0.3", only: :test}
{:mock, "~> 0.3", only: :test},
{:phoenix_html_helpers, "~> 1.0"},
{:livebook, "~> 0.13.0"},
{:kino, "~> 0.13.2"}
]
end

Expand Down
35 changes: 35 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@ config :os_mon,

config :bundlex, :disable_precompiled_os_deps, apps: [:ex_libsrtp]

# Additional mime types
config :mime, :types, %{
"audio/m4a" => ["m4a"],
"text/plain" => ["livemd"]
}

# Sets the default storage backend
config :livebook, :storage, Livebook.Storage.Ets

# Enable the embedded runtime which isn't available by default
config :livebook, :runtime_modules, [Livebook.Runtime.Embedded, Livebook.Runtime.Attached]

# Allow Livebook to power off the device
config :livebook, :shutdown_callback, {Process, :spawn, [System, :cmd, ["sudo", ["poweroff"]], []]}

# Defaults for required configurations
config :livebook,
agent_name: "default",
allowed_uri_schemes: [],
app_service_name: nil,
app_service_url: nil,
authentication: {:password, "password"},
aws_credentials: false,
epmdless: false,
feature_flags: [],
force_ssl_host: nil,
plugs: [],
rewrite_on: [],
teams_auth?: false,
teams_url: "https://teams.livebook.dev",
update_instructions_url: nil,
within_iframe: false

config :livebook, Livebook.Apps.Manager, retry_backoff_base_ms: 5_000

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
66 changes: 61 additions & 5 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ defmodule ConfigParser do
end
end

url = URI.parse(System.get_env("EXNVR_URL", "http://localhost:4000"))

## SSL Support
enable_ssl = String.to_existing_atom(System.get_env("EXNVR_ENABLE_HTTPS", "false"))

if config_env() == :prod do
database_path =
System.get_env("DATABASE_PATH") ||
Expand Down Expand Up @@ -84,8 +89,6 @@ if config_env() == :prod do
You can generate one by calling: mix phx.gen.secret
"""

url = URI.parse(System.get_env("EXNVR_URL", "http://localhost:4000"))

check_origin =
case System.get_env("EXNVR_CHECK_ORIGIN", "true") do
"true" -> true
Expand All @@ -102,9 +105,6 @@ if config_env() == :prod do
url: [scheme: url.scheme, host: url.host, port: url.port],
check_origin: check_origin

## SSL Support
enable_ssl = String.to_existing_atom(System.get_env("EXNVR_ENABLE_HTTPS", "false"))

if enable_ssl do
config :ex_nvr_web, ExNVRWeb.Endpoint,
https: [
Expand Down Expand Up @@ -148,3 +148,59 @@ if config_env() == :prod do
#
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
end

# Start with Livebook defaults
Livebook.config_runtime()

# Store notebooks in a writable location on the device
notebook_path = File.cwd!() <> "/notebooks/"

config :livebook,
home: notebook_path,
file_systems: [Livebook.FileSystem.Local.new(default_path: notebook_path)]

# Use the embedded runtime to run notebooks in the same VM
config :livebook,
default_runtime: Livebook.Runtime.Embedded.new(),
default_app_runtime: Livebook.Runtime.Embedded.new()

# Set the Erlang distribution cookie
config :livebook,
cookie: :ex_nvr_cookie

# Endpoint configuration
livebook_port = String.to_integer(System.get_env("EXNVR_LB_HTTP_PORT") || "9100")

config :livebook, LivebookWeb.Endpoint,
adapter: Bandit.PhoenixAdapter,
url: [host: url.host, path: "/"],
pubsub_server: Livebook.PubSub,
live_view: [signing_salt: "livebook"],
drainer: [shutdown: 1000],
render_errors: [formats: [html: LivebookWeb.ErrorHTML], layout: false],
http: [
port: livebook_port,
http_1_options: [max_header_length: 32768]
],
code_reloader: false,
server: true

if enable_ssl do
config :livebook, LivebookWeb.Endpoint,
https: [
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: String.to_integer(System.get_env("EXNVR_LB_HTTPS_PORT") || "9101"),
cipher_suite: :compatible,
keyfile: System.get_env("EXNVR_SSL_KEY_PATH"),
certfile: System.get_env("EXNVR_SSL_CERT_PATH")
]
end

config :livebook, :iframe_port, String.to_integer(System.get_env("EXNVR_LB_IFRAME_PORT") || "9102")

# Setup Erlang distribution
with {_, 0} <- System.cmd("epmd", ["-daemon"]),
{:ok, _pid} <- Node.start(:"livebook@#{url.host}") do
# Livebook always sets the cookie, so let it set it. See the Livebook application config.
:ok
end
16 changes: 14 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ defmodule ExNVR.Umbrella.MixProject do

defp steps() do
if System.get_env("DOCKER_BUILD", "false") |> String.to_existing_atom() do
[:assemble]
[:assemble, &copy_notebooks/1]
else
release_steps(get_target())
release_steps(get_target()) ++ [&copy_notebooks/1]
end
end

Expand Down Expand Up @@ -82,6 +82,18 @@ defmodule ExNVR.Umbrella.MixProject do

defp release_steps(_other), do: [:assemble]

defp copy_notebooks(release) do
notebooks_dest = Path.join(release.path, "notebooks")

unless File.exists?(notebooks_dest) do
File.mkdir_p!(notebooks_dest)
end

{:ok, _} = File.cp_r("./notebooks/", notebooks_dest)

release
end

defp delete_wrong_symlink(release) do
Path.join([Application.app_dir(:ex_nvr), "priv", "bundlex", "nif", "*"])
|> Path.wildcard()
Expand Down
Loading