Skip to content
Merged
Changes from 1 commit
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
17 changes: 13 additions & 4 deletions lib/terrarium/runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,30 @@ defmodule Terrarium.Runtime do
defp deploy_code(sandbox, dest) do
# Only deploy application code paths, not OTP or Elixir stdlib.
# Those are already available on the remote via mise.
# Include both ebin/ and priv/ directories (priv contains data files
# needed by some deps like llm_db).
otp_lib = :code.lib_dir() |> List.to_string()
elixir_lib = :code.lib_dir(:elixir) |> List.to_string() |> Path.dirname()

paths =
ebin_paths =
:code.get_path()
|> Enum.map(&List.to_string/1)
|> Enum.filter(&File.dir?/1)
|> Enum.reject(fn p ->
String.starts_with?(p, otp_lib) or String.starts_with?(p, elixir_lib)
end)

Logger.debug("Creating tarball from #{length(paths)} code paths (app only)", sandbox_id: sandbox.id)
# Deploy entire app directories (app-version/) to preserve the ebin/priv structure.
# This allows Application.app_dir/1 to find priv/ directories on the remote.
app_dirs =
ebin_paths
|> Enum.map(&Path.dirname/1)
|> Enum.uniq()

Logger.debug("Creating tarball from #{length(app_dirs)} app dirs", sandbox_id: sandbox.id)

tarball_path = Path.join(System.tmp_dir!(), "terrarium_deploy_#{System.unique_integer([:positive])}.tar.gz")
file_args = Enum.flat_map(paths, fn path -> ["-C", Path.dirname(path), Path.basename(path)] end)
file_args = Enum.flat_map(app_dirs, fn dir -> ["-C", Path.dirname(dir), Path.basename(dir)] end)

try do
case System.cmd("tar", ["czf", tarball_path | file_args], stderr_to_stdout: true) do
Expand Down Expand Up @@ -236,7 +245,7 @@ defmodule Terrarium.Runtime do
defp start_peer(sandbox, runtime, dest, opts) do
# Include app code + Elixir stdlib paths
pa_paths = [
"#{dest}/ebin",
"#{dest}/*/ebin",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid loading stale releases via wildcard code path

Using "#{dest}/*/ebin" adds every previously deployed app directory under dest to the remote VM code path. Since deployment still does tar xzf ... -C #{dest} without clearing old content, re-running replication in the same sandbox after an app/dependency version bump leaves older app-vsn directories present, so the node can resolve modules from stale versions depending on path ordering. This regression is introduced by the wildcard -pa change; either clean dest before extract or build pa_paths from only the just-deployed directories.

Useful? React with 👍 / 👎.

"#{runtime.elixir_lib}/*/ebin"
]

Expand Down