Build app deployment from notebook or source

This commit is contained in:
Alexandre de Souza 2025-06-30 14:11:49 -03:00
parent 374680fa16
commit a5f2361f56
No known key found for this signature in database
GPG key ID: E39228FFBA346545

View file

@ -42,11 +42,27 @@ defmodule Livebook.Teams.AppDeployment do
@doc """
Creates a new app deployment from notebook.
"""
@spec new(Livebook.Notebook.t(), Livebook.FileSystem.File.t()) ::
@spec new(Livebook.Notebook.t() | String.t(), Livebook.FileSystem.File.t()) ::
{:ok, t()} | {:warning, list(String.t())} | {:error, FileSystem.error()}
def new(notebook, files_dir) do
with {:ok, source} <- fetch_notebook_source(notebook),
{:ok, files} <- build_and_check_file_entries(notebook, source, files_dir),
def new(%Livebook.Notebook{} = notebook, files_dir) do
case Livebook.LiveMarkdown.notebook_to_livemd(notebook) do
{source, []} -> new(notebook, source, files_dir)
{_, warnings} -> {:warning, warnings}
end
end
@stamp_error "notebook does not have a stamp, disabling access to secrets and remote files"
def new(source, files_dir) when is_binary(source) do
case Livebook.LiveMarkdown.notebook_from_livemd(source) do
{notebook, %{warnings: [], stamp_verified?: true}} -> new(notebook, source, files_dir)
{_, %{warnings: [], stamp_verified?: false}} -> {:warning, [@stamp_error]}
{_, %{warnings: warnings}} -> {:warning, warnings}
end
end
def new(%Livebook.Notebook{} = notebook, source, files_dir) do
with {:ok, files} <- build_and_check_file_entries(notebook, source, files_dir),
{:ok, {_, zip_content}} <- :zip.create(~c"app_deployment.zip", files, [:memory]),
:ok <- validate_size(zip_content) do
md5_hash = :crypto.hash(:md5, zip_content)
@ -66,13 +82,6 @@ defmodule Livebook.Teams.AppDeployment do
end
end
defp fetch_notebook_source(notebook) do
case Livebook.LiveMarkdown.notebook_to_livemd(notebook) do
{source, []} -> {:ok, source}
{_, warnings} -> {:warning, warnings}
end
end
defp build_and_check_file_entries(notebook, source, files_dir) do
notebook.file_entries
|> Enum.filter(&(&1.type == :attachment))