Skip to content

Commit 35cddc0

Browse files
Pedro Piñera Buendíaclaude
authored andcommitted
feat: Deploy app directories with priv/ for proper Application.app_dir
Deploy entire app-version/ directories instead of flat ebin/ so that Application.app_dir/1 works on the remote and deps can find their priv/ files (e.g. llm_db's database). Update -pa to */ebin glob. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 024723a commit 35cddc0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/terrarium/runtime.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,30 @@ defmodule Terrarium.Runtime do
184184
defp deploy_code(sandbox, dest) do
185185
# Only deploy application code paths, not OTP or Elixir stdlib.
186186
# Those are already available on the remote via mise.
187+
# Include both ebin/ and priv/ directories (priv contains data files
188+
# needed by some deps like llm_db).
187189
otp_lib = :code.lib_dir() |> List.to_string()
188190
elixir_lib = :code.lib_dir(:elixir) |> List.to_string() |> Path.dirname()
189191

190-
paths =
192+
ebin_paths =
191193
:code.get_path()
192194
|> Enum.map(&List.to_string/1)
193195
|> Enum.filter(&File.dir?/1)
194196
|> Enum.reject(fn p ->
195197
String.starts_with?(p, otp_lib) or String.starts_with?(p, elixir_lib)
196198
end)
197199

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

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

203212
try do
204213
case System.cmd("tar", ["czf", tarball_path | file_args], stderr_to_stdout: true) do
@@ -236,7 +245,7 @@ defmodule Terrarium.Runtime do
236245
defp start_peer(sandbox, runtime, dest, opts) do
237246
# Include app code + Elixir stdlib paths
238247
pa_paths = [
239-
"#{dest}/ebin",
248+
"#{dest}/*/ebin",
240249
"#{runtime.elixir_lib}/*/ebin"
241250
]
242251

0 commit comments

Comments
 (0)