deploymentelixirphoenix-frameworkdistillery

How can I run executable release build in phoenix?


We are using distillery to create an executable build release in our phoenix application. We are using docker to deploy our application on Digital Ocean. Since we don't want to share code with the other machine we want to execute the build compiled file as executable which we can run on some remote machine through command line.

So after some research we found that distillery plugin build executable release which creates a build using

mix release --executable

We are able to create the release. It provides three command to run these

 punitjain@apple:project$ _build/dev/rel/project/bin/project foreground
 punitjain@apple:project$ _build/dev/rel/project/bin/project start
 punitjain@apple:project$ _build/dev/rel/project/bin/project console

I am getting following error after running foreground command

>  $ _build/dev/rel/project/bin/project foreground [info] Application
> project exited: Project.start(:normal, []) returned an error:
> shutdown: failed to start child: Project.Endpoint
>     ** (EXIT) shutdown: failed to start child: Phoenix.CodeReloader.Server
>         ** (EXIT) an exception was raised:
>             ** (UndefinedFunctionError) function Mix.Project.config/0 is undefined (module Mix.Project is not available)
>                 Mix.Project.config()
>                 (phoenix) lib/phoenix/code_reloader/server.ex:29: Phoenix.CodeReloader.Server.init/1
>                 (stdlib) gen_server.erl:328: :gen_server.init_it/6
>                 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 {"Kernel pid
> terminated",application_controller,"{application_start_failure,project,{{shutdown,{failed_to_start_child,'Elixir.Project.Endpoint',{shutdown,{failed_to_start_child,'Elixir.Phoenix.CodeReloader.Server',{undef,[{'Elixir.Mix.Project',config,[],[]},{'Elixir.Phoenix.CodeReloader.Server',init,1,[{file,\"lib/phoenix/code_reloader/server.ex\"},{line,29}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,328}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]}}}}},{'Elixir.Project',start,[normal,[]]}}}"}
> 
> Crash dump is being written to: erl_crash.dump...done Kernel pid
> terminated (application_controller)
> ({application_start_failure,project,{{shutdown,{failed_to_start_child,'Elixir.Project.Endpoint',{shutdown,{failed_to_start_child,'Elixir.Phoenix.Code

Can you please help me how to resolve this error?

I would also be very happy to hear if anyone is having any better approach to create an executable release file. Which I can use in any Linux based system to deploy without exposing my source code using Docker.

Please let me know if I need to provide more information or do any amendments in question asked. thanks


Solution

  • The problem is that you are building a release with MIX_ENV=dev, with Phoenix this will mean that the code reloader is included, and the code reloader does not work within a release. You should either build the release with MIX_ENV=prod or disable the code reloader in dev.