bitwalker / distillery

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

distillery is redefining module Mix.Tasks.Release #642

Closed fahadnaeemkhan closed 5 years ago

fahadnaeemkhan commented 5 years ago

Steps to reproduce

just compile distillery 2.0.12

Verbose Logs

$ mix deps.get
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  artificery 0.4.0
  connection 1.0.4
  cowboy 2.6.1
  cowlib 2.7.0
  db_connection 2.0.5
  decimal 1.7.0
  distillery 2.0.12
  ecto 3.0.7
  ecto_sql 3.0.5
  gettext 0.16.1
  jason 1.1.2
  mime 1.3.1
  phoenix 1.4.1
  phoenix_pubsub 1.1.2
  plug 1.7.2
  plug_cowboy 2.0.1
  plug_crypto 1.0.0
  postgrex 0.14.1
  ranch 1.7.1
  telemetry 0.3.0
* Getting distillery (Hex package)

$ mix deps.compile
===> Compiling ranch
===> Compiling telemetry
===> Compiling cowlib
===> Compiling cowboy
==> distillery
Compiling 33 files (.ex)
warning: redefining module Mix.Tasks.Release (current version loaded from <path to elixir>/elixir/bin/../lib/mix/ebin/Elixir.Mix.Tasks.Release.beam)
  lib/distillery/tasks/release.ex:1

Generated distillery app
There is a redefining of module ``Mix.Tasks.Release`` when compiling. This is causing release to act weirdly.
When I run distillery release like following, Mix is picking ``Release`` module from ``elixir/lib/mix/lib/mix/tasks/release.ex`` rather than from ``_build/lib/distillery/tasks/release.ex`` ``` $ MIX_ENV=dev mix release ** (Mix) Umbrella projects require releases to be explicitly defined with a non-empty applications key that chooses which umbrella children should be part of the releases: releases: [ foo: [ applications: [child_app_foo: :permanent] ], bar: [ applications: [child_app_bar: :permanent] ] ] Alternatively you can perform the release from the children applications $ MIX_ENV=dev mix release --name ** (Mix) Could not invoke task "release": 1 error found! --name : Unknown option ``` When i explicitly append `` _build/dev/lib/distillery/ebin`` path i get following error ``` MIX_ENV=dev elixir -pa _build/dev/lib/distillery/ebin -S mix release ==> Loading configuration.. ==> Assembling release.. ==> Building release testify_ex:0.1.0 using environment dev ==> Discovered applications: > plug_crypto-1.0.0 | | from: _build/dev/lib/plug_crypto | applications: | :kernel | :stdlib | :elixir | :crypto | includes: none |_____ > kernel-6.2 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/kernel-6.2 | applications: none | includes: none |_____ > mime-1.3.1 | | from: _build/dev/lib/mime | applications: | :kernel | :stdlib | :elixir | :logger | includes: none |_____ > plug-1.7.2 | | from: _build/dev/lib/plug | applications: | :kernel | :stdlib | :elixir | :logger | :mime | :plug_crypto | includes: none |_____ > asn1-5.0.8 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/asn1-5.0.8 | applications: | :kernel | :stdlib | includes: none |_____ > public_key-1.6.4 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/public_key-1.6.4 | applications: | :asn1 | :crypto | :kernel | :stdlib | includes: none |_____ > ssl-9.1.2 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/ssl-9.1.2 | applications: | :crypto | :public_key | :kernel | :stdlib | includes: none |_____ > ranch-1.7.1 | | from: _build/dev/lib/ranch | applications: | :kernel | :stdlib | :ssl | includes: none |_____ > cowlib-2.7.0 | | from: _build/dev/lib/cowlib | applications: | :kernel | :stdlib | :crypto | includes: none |_____ > cowboy-2.6.1 | | from: _build/dev/lib/cowboy | applications: | :kernel | :stdlib | :crypto | :cowlib | :ranch | includes: none |_____ > plug_cowboy-2.0.1 | | from: _build/dev/lib/plug_cowboy | applications: | :kernel | :stdlib | :elixir | :logger | :cowboy | :plug | includes: none |_____ > artificery-0.4.0 | | from: _build/dev/lib/artificery | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > distillery-2.0.12 | | from: _build/dev/lib/distillery | applications: | :kernel | :stdlib | :elixir | :runtime_tools | :artificery | includes: none |_____ > crypto-4.4 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/crypto-4.4 | applications: | :kernel | :stdlib | includes: none |_____ > decimal-1.7.0 | | from: _build/dev/lib/decimal | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > connection-1.0.4 | | from: _build/dev/lib/connection | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > db_connection-2.0.5 | | from: _build/dev/lib/db_connection | applications: | :kernel | :stdlib | :elixir | :logger | :connection | includes: none |_____ > postgrex-0.14.1 | | from: _build/dev/lib/postgrex | applications: | :kernel | :stdlib | :elixir | :logger | :db_connection | :decimal | :crypto | includes: none |_____ > eex-1.9.0-dev | | from: /Users/fnaeem/projects/elixir/elixir/bin/../lib/eex | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > phoenix-1.4.1 | | from: _build/dev/lib/phoenix | applications: | :kernel | :stdlib | :elixir | :logger | :eex | :crypto | :phoenix_pubsub | :plug | includes: none |_____ > ecto-3.0.7 | | from: _build/dev/lib/ecto | applications: | :kernel | :stdlib | :elixir | :logger | :crypto | :decimal | includes: none |_____ > telemetry-0.3.0 | | from: _build/dev/lib/telemetry | applications: | :kernel | :stdlib | includes: none |_____ > ecto_sql-3.0.5 | | from: _build/dev/lib/ecto_sql | applications: | :kernel | :stdlib | :elixir | :logger | :telemetry | :db_connection | :ecto | includes: none |_____ > logger-1.9.0-dev | | from: /Users/fnaeem/projects/elixir/elixir/bin/../lib/logger | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > tfy_database-0.1.0 | | from: _build/dev/lib/tfy_database | applications: | :kernel | :stdlib | :elixir | :logger | :runtime_tools | :postgrex | :ecto_sql | :distillery | includes: none |_____ > runtime_tools-1.13.1 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/runtime_tools-1.13.1 | applications: | :kernel | :stdlib | includes: none |_____ > stdlib-3.7 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/stdlib-3.7 | applications: | :kernel | includes: none |_____ > phoenix_pubsub-1.1.2 | | from: _build/dev/lib/phoenix_pubsub | applications: | :kernel | :stdlib | :elixir | :logger | :crypto | includes: none |_____ > jason-1.1.2 | | from: _build/dev/lib/jason | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > tfy_resource_manager-0.1.0 | | from: _build/dev/lib/tfy_resource_manager | applications: | :kernel | :stdlib | :elixir | :sasl | :logger | :jason | :distillery | :tfy_database | includes: none |_____ > compiler-7.3.1 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/compiler-7.3.1 | applications: | :kernel | :stdlib | includes: none |_____ > sasl-3.3 | | from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/sasl-3.3 | applications: | :kernel | :stdlib | includes: none |_____ > gettext-0.16.1 | | from: _build/dev/lib/gettext | applications: | :kernel | :stdlib | :elixir | :logger | includes: none |_____ > iex-1.9.0-dev | | from: /Users/fnaeem/projects/elixir/elixir/bin/../lib/iex | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > mix-1.9.0-dev | | from: /Users/fnaeem/projects/elixir/elixir/bin/../lib/mix | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > tfy_rest-0.1.0 | | from: _build/dev/lib/tfy_rest | applications: | :kernel | :stdlib | :elixir | :logger | :runtime_tools | :gettext | :jason | :phoenix_pubsub | :distillery | :tfy_database | :tfy_resource_manager | :plug_cowboy | :phoenix | includes: none |_____ > elixir-1.9.0-dev | | from: /Users/fnaeem/projects/elixir/elixir/bin/../lib/elixir | applications: | :kernel | :stdlib | :compiler | includes: none |_____ ==> Running validation checks.. > Mix.Releases.Checks.Erts * PASS > Mix.Releases.Checks.Cookie * PASS > Mix.Releases.Checks.LoadedOrphanedApps * PASS ==> Generated overlay vars: release_name=:testify_ex release_version="0.1.0" is_upgrade=false upgrade_from=:latest dev_mode=true include_erts=false include_src=false include_system_libs=false erl_opts="" run_erl_env="" erts_vsn="10.2.3" output_dir="_build/dev/rel/testify_ex" ==> Copying applications to _build/dev/rel/testify_ex ==> Generating start_erl.data ==> Generating vm.args ==> Generating sys.config from config/config.exs ==> Generating boot scripts ==> Release failed, during .boot generation: Duplicated modules: 'Elixir.Mix.Tasks.Release' specified in distillery and mix ```

Description of issue

Elixir 1.9.0-dev (3680e8535) (compiled with Erlang/OTP 21)

- If possible, also provide your `rel/config.exs`, as it is often
  my first troubleshooting question, and you'll save us both time :)

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.

~w(rel plugins *.exs) |> Path.join() |> 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/config/distillery.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

If you are running Phoenix, you should make sure that

server: true is set and the code reloader is disabled,

even in dev mode.

It is recommended that you build with MIX_ENV=prod and pass

the --env flag to Distillery explicitly if you want to use

dev mode.

set dev_mode: true set include_erts: false set cookie: :")s~|tJgscs:fhCSU.th}~1XOF$4(G>J>h!]]qI[g$BYP_vV~C_8Qj.h(>M>yhz,K" end

environment :prod do set include_erts: true set include_src: false set cookie: :"%QlO$xp1Z`hC[DZa@]>={imBh$8,$W@$,T}~Kb5OOj[S&kW]5b,Gx{W?Xwt^{//;" set vm_args: "rel/vm.args" 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 :testify_ex do set version: "0.1.0" set applications: [ :runtime_tools, tfy_database: :permanent, tfy_resource_manager: :permanent, tfy_rest: :permanent ] end

fahadnaeemkhan commented 5 years ago

I have temporary fixed this by adding plugin in which i'm removing mix from %Release{} application list in before_assembly callback but I still have to add distillery to the path

$ MIX_ENV=dev elixir -pa _build/dev/lib/distillery/ebin -S mix release                                                                                 
==> Assembling release..                                                                                                                                                               
==> Building release testify_ex:0.1.0 using environment dev                                                                                                                             
==> This is executed just after assembling, and just prior to packaging the release                                                                                                    
==> You have set dev_mode to true, skipping archival phase                                                                                                                             
Release successfully built!                                                                                                                                                            
To start the release you have built, you can use one of the following tasks:                                                                                                           

    # start a shell, like 'iex -S mix'                                                                                                                                                 
    > _build/dev/rel/testify_ex/bin/testify_ex console                                     

    # start in the foreground, like 'mix run --no-halt'                                    
    > _build/dev/rel/testify_ex/bin/testify_ex foreground                                  

    # start in the background, must be stopped with the 'stop' command                     
    > _build/dev/rel/testify_ex/bin/testify_ex start                                       

If you started a release elsewhere, and wish to connect to it:                             

    # connects a local shell to the running node                                           
    > _build/dev/rel/testify_ex/bin/testify_ex remote_console                              

    # connects directly to the running node's console                                      
    > _build/dev/rel/testify_ex/bin/testify_ex attach                                      

For a complete listing of commands and their use:                                          

    > _build/dev/rel/testify_ex/bin/testify_ex help  

plugin code:


defmodule TestifyEx.TestPlugin do
  use Mix.Releases.Plugin

  def before_assembly(%Release{applications: _} = release, _opts) do
    release
    |> Map.update!(:applications, &(List.delete(&1, :mix)))
  end

  def after_assembly(%Release{} = release, _opts) do
    info "This is executed just after assembling, and just prior to packaging the release"
    release # or nil
  end

  def before_package(%Release{} = release, _opts) do
    info "This is executed just before packaging the release"
    release # or nil
  end

  def after_package(%Release{} = release, _opts) do
    info "This is executed just after packaging the release"
    release # or nil
  end

  def after_cleanup(_args, _opts) do
    info "This is executed just after running cleanup"
    :ok # It doesn't matter what we return here
  end
end
bitwalker commented 5 years ago

This is address in master