bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.96k stars 398 forks source link

dev_mode and Phoenix app, CodeReloader/Mix.Config #306

Closed tpitale closed 7 years ago

tpitale commented 7 years ago

Steps to reproduce

  1. clone PR https://github.com/tpitale/advocate-bridge/pull/6
  2. mix deps.get
  3. MIX_ENV=dev mix do clean --all, compile, release
  4. _build/dev/rel/advocate_bridge/bin/advocate_bridge console

Verbose Logs

==> Loading configuration..
==> Assembling release..
==> Building release advocate_bridge:0.0.1 using environment dev
==> Discovered applications:
  connection-1.0.4
    from: _build/dev/lib/connection
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  db_connection-1.1.2
    from: _build/dev/lib/db_connection
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
      :connection
    includes: none

  postgrex-0.12.2
    from: _build/dev/lib/postgrex
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
      :db_connection
      :decimal
    includes: none

  poolboy-1.5.1
    from: _build/dev/lib/poolboy
    applications:
      :kernel
      :stdlib
    includes: none

  decimal-1.4.0
    from: _build/dev/lib/decimal
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  ecto-2.0.5
    from: _build/dev/lib/ecto
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
      :decimal
      :poolboy
    includes: none

  phoenix_ecto-3.0.1
    from: _build/dev/lib/phoenix_ecto
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
      :ecto
      :plug
    includes: none

  gettext-0.11.0
    from: _build/dev/lib/gettext
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
    includes: none

  cowlib-1.0.2
    from: _build/dev/lib/cowlib
    applications:
      :kernel
      :stdlib
      :crypto
    includes: none

  ranch-1.2.1
    from: _build/dev/lib/ranch
    applications:
      :kernel
      :stdlib
    includes: none

  cowboy-1.0.4
    from: _build/dev/lib/cowboy
    applications:
      :kernel
      :stdlib
      :ranch
      :cowlib
      :crypto
    includes: none

  phoenix_html-2.7.0
    from: _build/dev/lib/phoenix_html
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
      :plug
    includes: none

  phoenix_pubsub-1.0.1
    from: _build/dev/lib/phoenix_pubsub
    applications:
      :kernel
      :stdlib
      :elixir
      :logger
      :crypto
    includes: none

  eex-1.5.1
    from: /usr/local/Cellar/elixir/1.5.1/bin/../lib/eex
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  poison-2.2.0
    from: _build/dev/lib/poison
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  mime-1.0.1
    from: _build/dev/lib/mime
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  logger-1.5.1
    from: /usr/local/Cellar/elixir/1.5.1/bin/../lib/logger
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  crypto-4.0
    from: /usr/local/Cellar/erlang/20.0/lib/erlang/lib/crypto-4.0
    applications:
      :kernel
      :stdlib
    includes: none

  plug-1.2.2
    from: _build/dev/lib/plug
    applications:
      :kernel
      :stdlib
      :elixir
      :crypto
      :logger
      :mime
    includes: none

  phoenix-1.2.1
    from: _build/dev/lib/phoenix
    applications:
      :kernel
      :stdlib
      :elixir
      :plug
      :poison
      :logger
      :eex
    includes: none

  compiler-7.1
    from: /usr/local/Cellar/erlang/20.0/lib/erlang/lib/compiler-7.1
    applications:
      :kernel
      :stdlib
    includes: none

  elixir-1.5.1
    from: /usr/local/Cellar/elixir/1.5.1/bin/../lib/elixir
    applications:
      :kernel
      :stdlib
      :compiler
    includes: none

  stdlib-3.4
    from: /usr/local/Cellar/erlang/20.0/lib/erlang/lib/stdlib-3.4
    applications:
      :kernel
    includes: none

  kernel-5.3
    from: /usr/local/Cellar/erlang/20.0/lib/erlang/lib/kernel-5.3
    applications: none
    includes: none

  advocate_bridge-0.0.1
    from: _build/dev/lib/advocate_bridge
    applications:
      :kernel
      :stdlib
      :elixir
      :phoenix
      :phoenix_pubsub
      :phoenix_html
      :cowboy
      :logger
      :gettext
      :phoenix_ecto
      :postgrex
    includes: none

  iex-1.5.1
    from: /usr/local/Cellar/elixir/1.5.1/bin/../lib/iex
    applications:
      :kernel
      :stdlib
      :elixir
    includes: none

  sasl-3.0.4
    from: /usr/local/Cellar/erlang/20.0/lib/erlang/lib/sasl-3.0.4
    applications:
      :kernel
      :stdlib
    includes: none

  runtime_tools-1.12
    from: /usr/local/Cellar/erlang/20.0/lib/erlang/lib/runtime_tools-1.12
    applications:
      :kernel
      :stdlib
    includes: none

==> Generated overlay vars:
    release_name=:advocate_bridge
    release_version="0.0.1"
    is_upgrade=false
    upgrade_from=:latest
    dev_mode=true
    include_erts=false
    include_src=false
    include_system_libs=true
    erl_opts=""
    run_erl_env=""
    erts_vsn="9.0"
    output_dir="_build/dev/rel/advocate_bridge"
==> Copying applications to _build/dev/rel/advocate_bridge
==> Generating nodetool
==> Generating start_erl.data
==> Generating vm.args
==> Generating sys.config from config/config.exs
==> Generating boot script
==> Generating RELEASES
==> Generating start_clean.boot
==> Applying overlays
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/pre_configure.d
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/pre_start.d
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/post_start.d
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/pre_stop.d
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/post_stop.d
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/pre_upgrade.d
==> Applying mkdir overlay
    dst: releases/0.0.1/hooks/post_upgrade.d
==> Applying mkdir overlay
    dst: releases/0.0.1/commands
==> You have set dev_mode to true, skipping archival phase
==> Release successfully built!
    You can run it in one of the following ways:
      Interactive: _build/dev/rel/advocate_bridge/bin/advocate_bridge console
      Foreground: _build/dev/rel/advocate_bridge/bin/advocate_bridge foreground
      Daemon: _build/dev/rel/advocate_bridge/bin/advocate_bridge start

Description of issue

I'm not sure if dev_mode is expected to work with a Phoenix app. It seems to be upset with Mix.Config from Phoenix.CodeReloader.

Is this not what dev_mode config is intended to do (include things like Mix)? Or is there some accepted way to disable phoenix attempting to do code reloading at all (which I obviously don't need with a release).

If not, should dev_mode be documented somewhere to indicate it's purpose, as it is included in the release.init task.

Mac OS 10.12.4 Erlang/OTP 20 Elixir 1.5.1

# Import all plugins from `rel/plugins`
# They can then be used by adding `plugin MyPlugin` to
# either an environment, or release definition, where
# `MyPlugin` is the name of the plugin module.
Path.join(["rel", "plugins", "*.exs"])
|> Path.wildcard()
|> Enum.map(&Code.eval_file(&1))

use Mix.Releases.Config,
    # This sets the default release built by `mix release`
    default_release: :default,
    # This sets the default environment used by `mix release`
    default_environment: Mix.env()

# For a full list of config options for both releases
# and environments, visit https://hexdocs.pm/distillery/configuration.html

# You may define one or more environments in this file,
# an environment's settings will override those of a release
# when building in that environment, this combination of release
# and environment configuration is called a profile

environment :dev do
  set dev_mode: true
  set include_erts: false
  set cookie: :"n~1_fF6HFc,bm`::BA@uLpk)cc!.1%OB%G3}eLEbKKdmX5NhF%*JKWHB8yRjp*UU"
end

environment :prod do
  set include_erts: true
  set include_src: false
  set cookie: :"99y>=j!b`wOo)7r8>K:aH@m_]jXA]41F;T%.7?L`1q)BQRKvYX^nwi}[02Oex?ZK"
end

# You may define one or more releases in this file.
# If you have not set a default release, or selected one
# when running `mix release`, the first release in the file
# will be used by default

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

dev_mode documentation does explain that the code is symlink'd, but says nothing about Mix or using Phoenix.

tpitale commented 7 years ago

Phoenix Walkthrough does say there isn't much point to dev mode with Phoenix as it loses all the interactive features.

So, I guess the question is, should the dev environment included in the release.init rel/config.exs file have a note that it should be removed when using Phoenix.

Feel free to close this issue if this doesn't make sense.

bitwalker commented 7 years ago

Yeah we should add a note like that both in the docs and probably directly in the release config file as a last resort. That said, I wonder if it might be possible to detect if the current environment has the code reloader enabled, and fail the release build automatically because of that, I'll have to look into it, since that would provide a better failsafe.

Dev mode in Distillery is a way to run the release version of your application while being able to easily make changes and recompile without having to build the release again, you just restart it, making for quicker experimentation -- but it doesn't change the fundamental restrictions releases have in place, such as not being able to use Mix, and things which rely on Mix or the Mix project definition not working properly (such as the Phoenix code reloader).

tpitale commented 7 years ago

I'm going to open an issue on Phoenix to see if it is possible to disable CodeReloader/other mix-related code.

tpitale commented 7 years ago

For future folks who may find this post, you can disable CodeReloader by setting code_reloader: false in config/dev.exs and commenting out the code reloading section in lib/{yourapp}/endpoint.ex. https://stackoverflow.com/questions/45696663/possible-to-disable-codereloader-in-phoenix/45696773#45696773

bitwalker commented 7 years ago

I've added a note to the initial release config file in the latest release of Distillery, so that should help as well.