Distillery VS. Elixir 1.9 Release current working directory difference

Distillery VS. Elixir 1.9 Release CWD

I’m noticing a difference between Distillery (on Elixir 1.6) and Elixir 1.9 Releases. I’ve got an app that reads a file at ../filename.txt. With Distillery this results in /my_app_name/rel/filename.txt being read, whereas with an Elixir 1.9 release, it tries to read /filename.txt, which does not exist. I’ve checked my app and it’s dependencies for any File.cd/File.cd! calls that may have changed the current working directory, but didn’t find anything. I’m running the release inside an Alpine Docker container. Below are a couple commands I ran on the two containers I built.

Distillery (Elixir 1.6) container:

bash-4.4# /my_app_name/rel/my_app_name/bin/my_app_name rpc Elixir.File 'cwd!'
==> Generated sys.config in /my_app_name/rel/my_app_name/var

$ ps aux | cat
86 root       0:02 /my_app_name/rel/my_app_name/erts-9.2/bin/beam.smp -Bd -- -root /my_app_name/rel/my_app_name -progname my_app_name/rel/my_app_name/releases/1.0.0/my_app_name.sh -- -home /root -- -noshell -noshell -noinput -boot /my_app_name/rel/my_app_name/releases/1.0.0/my_app_name -boot_var ERTS_LIB_DIR /my_app_name/rel/my_app_name/erts-9.2/../lib -pa /my_app_name/rel/my_app_name/lib/my_app_name-1.0.0/consolidated -name my_app_name@ -setcookie $djkf/s3!WU`Tt3_^V/OnK&W(MLLAI}@9zup`={$4JtgD}8=XNq^&2B(yzMoZE*) -smp auto -config /my_app_name/rel/my_app_name/var/sys.config -mode embedded -extra -conform_schema /my_app_name/rel/my_app_name/releases/1.0.0/my_app_name.schema.exs -conform_config /my_app_name/rel/my_app_name/releases/1.0.0/my_app_name.conf -- foreground

Elixir 1.9 Release container:

$ /my_app_name/rel/my_app_name/bin/my_app_name rpc 'IO.inspect(File.cwd!())'

$ ps aux | cat
1 root      0:11 /my_app_name/rel/my_app_name/erts-10.5.3/bin/beam.smp -- -root /my_app_name/rel/my_app_name -progname erl -- -home /root -- -noshell -s elixir start_cli -mode embedded -setcookie VKF7QZAFZRIIRQLQ5Q6WBHFMUV7VGL2Z57K54PYKBIVXTTKO63RQ==== -sname my_app_name -config /my_app_name/rel/my_app_name/tmp/my_app_name-1.0.0-20191105221125-6ebc.runtime -boot /my_app_name/rel/my_app_name/releases/1.0.0/start -boot_var RELEASE_LIB /my_app_name/rel/my_app_name/lib -- -extra --no-halt

Any idea why these differences exist? Is this by design? I can adjust the path to the file I’m looking for, that’s not a big deal. What I’m trying to understand is what changed as far as the current working directory goes.

Honestly it’s because you are using a relative path, and trusting the CWD to be in a specific place in a vastly multi-actor system is bound to fail at times. Use absolute paths, this is specifically what the priv directory is for (:code.priv_dir). Either give an absolute path somewhere, or use the priv directory.