mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-04 20:14:57 +08:00
Build app deployment from notebook or source
This commit is contained in:
parent
374680fa16
commit
a5f2361f56
1 changed files with 20 additions and 11 deletions
|
@ -42,11 +42,27 @@ defmodule Livebook.Teams.AppDeployment do
|
||||||
@doc """
|
@doc """
|
||||||
Creates a new app deployment from notebook.
|
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()}
|
{:ok, t()} | {:warning, list(String.t())} | {:error, FileSystem.error()}
|
||||||
def new(notebook, files_dir) do
|
def new(%Livebook.Notebook{} = notebook, files_dir) do
|
||||||
with {:ok, source} <- fetch_notebook_source(notebook),
|
case Livebook.LiveMarkdown.notebook_to_livemd(notebook) do
|
||||||
{:ok, files} <- build_and_check_file_entries(notebook, source, files_dir),
|
{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, {_, zip_content}} <- :zip.create(~c"app_deployment.zip", files, [:memory]),
|
||||||
:ok <- validate_size(zip_content) do
|
:ok <- validate_size(zip_content) do
|
||||||
md5_hash = :crypto.hash(:md5, zip_content)
|
md5_hash = :crypto.hash(:md5, zip_content)
|
||||||
|
@ -66,13 +82,6 @@ defmodule Livebook.Teams.AppDeployment do
|
||||||
end
|
end
|
||||||
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
|
defp build_and_check_file_entries(notebook, source, files_dir) do
|
||||||
notebook.file_entries
|
notebook.file_entries
|
||||||
|> Enum.filter(&(&1.type == :attachment))
|
|> Enum.filter(&(&1.type == :attachment))
|
||||||
|
|
Loading…
Add table
Reference in a new issue