reph icon indicating copy to clipboard operation
reph copied to clipboard

Does not work with Distillery

Open micahrye opened this issue 7 years ago • 2 comments
trafficstars

First, from initial play this is a nice project that removes a bunch of hassle.

I am able to dev with this and I can build and run as described in the Phoenix docs here.

If I try and build a release with Distillery I run into issues. These issues seam to be with respect to std_json_io, or its configuration and use in RePh.

FYI:

elixir --version
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.6.0-rc.0 (182c730) (compiled with OTP 20)

First when building release with Distillery I get:

MIX_ENV=prod mix release
==> Assembling release..
==> Building release demo_app:0.0.1 using environment prod
==> One or more direct or transitive dependencies are missing from
    :applications or :included_applications, they will not be included
    in the release:

    :poolboy

    This can cause your application to fail at runtime. If you are sure
    that this is not an issue, you may ignore this warning.

... 

If I try and run the release $ PORT=4001 _build/prod/rel/demo_app/bin/demo_app foreground I get the following error.

23:33:55.488 [info] [Porcelain]: goon executable not found
23:33:55.488 [info] [Porcelain]: falling back to the basic driver.
23:33:55.488 [info] [Porcelain]: (set `config :porcelain, driver: Porcelain.Driver.Basic` or `config :porcelain, goon_warn_if_missing: false` to disable this warning)
23:33:55.489 [info] Application std_json_io exited: exited in: StdJsonIo.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function :poolboy.child_spec/3 is undefined (module :poolboy is not available)
            :poolboy.child_spec(StdJsonIo.Pool, [name: {:local, StdJsonIo.Pool}, worker_module: StdJsonIo.Worker, size: 10, max_overflow: 10, strategy: :fifo], [script: "assets/node_modules/.bin/react-stdio"])
            (std_json_io) lib/std_json_io/application.ex:15: StdJsonIo.Application.start/2
            (kernel) application_master.erl:273: :application_master.start_it_old/4
{"Kernel pid terminated",application_controller,"{application_start_failure,std_json_io,{bad_return,{{'Elixir.StdJsonIo.Application',start,[normal,[]]},{'EXIT',{undef,[{poolboy,child_spec,['Elixir.StdJsonIo.Pool',[{name,{local,'Elixir.StdJsonIo.Pool'}},{worker_module,'Elixir.StdJsonIo.Worker'},{size,10},{max_overflow,10},{strategy,fifo}],[{script,<<\"assets/node_modules/.bin/react-stdio\">>}]],[]},{'Elixir.StdJsonIo.Application',start,2,[{file,\"lib/std_json_io/application.ex\"},{line,15}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,273}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,std_json_io,{bad_return,{{'Elixir.StdJsonIo.Application',start,[normal,[]]},{'EXIT',{undef,[{poolboy,child_spec,['Elixir.StdJ

Crash dump is being written to: erl_crash.dump...done

That is what first pointed me to std_json_io.

In attempting to fix things I first followed suggestions related to the first warning above regarding "One or more direct or transitive dependencies are missing" for "poolboy," which resolved that. and now the MIX_ENV=prod mix release results in no warning and no runtime elixir error:

MIX_ENV=prod mix release
==> Assembling release..
==> Building release demo_app:0.0.1 using environment prod
==> Including ERTS 9.0 from /usr/local/Cellar/erlang/20.0/lib/erlang/erts-9.0
==> Packaging release..
==> Release successfully built!
    You can run it in one of the following ways:
      Interactive: _build/prod/rel/demo_app/bin/demo_app console
      Foreground: _build/prod/rel/demo_app/bin/demo_app foreground
      Daemon: _build/prod/rel/demo_app/bin/demo_app start

But, if I run PORT=4001 _build/prod/rel/demo_app/bin/demo_app foreground I get this endless error: /bin/sh: assets/node_modules/.bin/react-stdio: No such file or directory

This lead me to play around with the configuration setting you have,

config :std_json_io,
  pool_size: 10,
  pool_max_overflow: 10,
  script: "assets/node_modules/.bin/react-stdio"

Without success.

I am wondering what I am doing wrong? Also, I am wondering about the usage of std_json_io. I see that you contributed a fix that was accepted, but that the maintainer has never updated hex.pm with that and does not seem to active on the project.

micahrye avatar Jan 18 '18 04:01 micahrye

That's all expected, since releases is some "special case", but no worries! Been there, done that :) You can take a look at this Dockerfile for one of Reph-powered apps (old one, but still can give you the basic idea) with Distillery: https://github.com/chvanikoff/elixir.run/blob/master/Dockerfile As you can see there, react-stdio is installed globally - that's because release doesn't have assets directory inside, but uses JS compiled into priv/static dir (in the Dockerfile done with RUN cd assets && node_modules/.bin/webpack -p && cd ../

chvanikoff avatar Jan 19 '18 01:01 chvanikoff

Thanks! To clarify for others and comment, you will need to modify rel/config.exs created from command MIX_ENV=prod mix release.init and you will need to modify config/config.exs from the tutorial @chvanikoff provided on Medium.

First you will need to install react-stido globally (Docker or otherwise) and then modifiyconfig/config.exs from

config :std_json_io,
  pool_size: 10,
  pool_max_overflow: 10,
  script: "assets/node_modules/.bin/react-stdio"

to

config :std_json_io,
  pool_size: 10,
  pool_max_overflow: 10,
  script: "react-stdio"

You will also modify rel/config.exs from

release :demo_app do
  set version: current_version(:demo_app)
  set applications: [
    :runtime_tools  
]
end

to

release :demo_app do
  set version: current_version(:demo_app)
  set applications: [
    :runtime_tools,
    poolboy: :load
  ]
end

@chvanikoff, my other question is still open with respect to std_json_io and also if you have ran load test or production with this setup and how you like it?

Thanks a lot for response.

micahrye avatar Jan 19 '18 03:01 micahrye