bitwalker / distillery

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

Dependencies are not included in the .tar.gz when using include_erts: "some/path" #574

Closed ejpcmac closed 5 years ago

ejpcmac commented 5 years ago

Steps to reproduce

  1. Configure a release environment with include_erts: "some/path"
  2. Build a release
  3. Untar the archive and look in lib/: there is no Elixir or other Mix dependencies

Verbose Logs

``` $ MIX_ENV=prod mix release --env=freebsd --verbose ==> Loading configuration.. ==> Assembling release.. ==> Building release : using environment freebsd ==> Discovered applications: > poolboy-1.5.1 | | from: _build/prod/lib/poolboy | applications: | :kernel | :stdlib | includes: none |_____ > ecto-2.2.11 | | from: _build/prod/lib/ecto | applications: | :kernel | :stdlib | :elixir | :logger | :decimal | :poolboy | :crypto | includes: none |_____ > phoenix_ecto-3.5.0 | | from: _build/prod/lib/phoenix_ecto | applications: | :kernel | :stdlib | :elixir | :logger | :ecto | :plug | includes: none |_____ > kernel-6.1 | | from: /opt/erlang-freebsd/lib/kernel-6.1 | applications: none | includes: none |_____ > toml-0.3.0 | | from: _build/prod/lib/toml | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > recon-2.3.6 | | from: _build/prod/lib/recon | applications: | :kernel | :stdlib | includes: none |_____ > observer_cli-1.4.0 | | from: _build/prod/lib/observer_cli | applications: | :kernel | :stdlib | :recon | includes: none |_____ > artificery-0.2.6 | | from: _build/prod/lib/artificery | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > distillery-2.0.10 | | from: _build/prod/lib/distillery | applications: | :kernel | :stdlib | :elixir | :runtime_tools | :artificery | includes: none |_____ > decimal-1.5.0 | | from: _build/prod/lib/decimal | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > connection-1.0.4 | | from: _build/prod/lib/connection | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > db_connection-1.1.3 | | from: _build/prod/lib/db_connection | applications: | :kernel | :stdlib | :elixir | :logger | :connection | includes: none |_____ > postgrex-0.13.5 | | from: _build/prod/lib/postgrex | applications: | :kernel | :stdlib | :elixir | :logger | :db_connection | :decimal | :crypto | includes: none |_____ > eex-1.7.3 | | from: /nix/store/7hfhxiq3bm7lgsd7gz66avjqksc9vw6f-elixir-1.7.3/lib/elixir/bin/../lib/eex | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > phoenix-1.3.4 | | from: _build/prod/lib/phoenix | applications: | :kernel | :stdlib | :elixir | :plug | :poison | :logger | :eex | :phoenix_pubsub | :crypto | includes: none |_____ > mime-1.3.0 | | from: _build/prod/lib/mime | applications: | :kernel | :stdlib | :elixir | :logger | includes: none |_____ > plug-1.6.4 | | from: _build/prod/lib/plug | applications: | :kernel | :stdlib | :elixir | :crypto | :logger | :mime | includes: none |_____ > ex2ms-1.5.0 | | from: _build/prod/lib/ex2ms | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > ex_rated-1.3.2 | | from: _build/prod/lib/ex_rated | applications: | :kernel | :stdlib | :elixir | :logger | :ex2ms | includes: none |_____ > runtime_tools-1.13.1 | | from: /opt/erlang-freebsd/lib/runtime_tools-1.13.1 | applications: | :kernel | :stdlib | includes: none |_____ > cowlib-1.0.2 | | from: _build/prod/lib/cowlib | applications: | :kernel | :stdlib | :crypto | includes: none |_____ > stdlib-3.6 | | from: /opt/erlang-freebsd/lib/stdlib-3.6 | applications: | :kernel | includes: none |_____ > phoenix_pubsub-1.1.0 | | from: _build/prod/lib/phoenix_pubsub | applications: | :kernel | :stdlib | :elixir | :logger | :crypto | includes: none |_____ > crypto-4.3.3 | | from: /opt/erlang-freebsd/lib/crypto-4.3.3 | applications: | :kernel | :stdlib | includes: none |_____ > arc_ecto-0.11.0 | | from: _build/prod/lib/arc_ecto | applications: | :kernel | :stdlib | :elixir | :logger | :arc | includes: none |_____ > phoenix_html-2.12.0 | | from: _build/prod/lib/phoenix_html | applications: | :kernel | :stdlib | :elixir | :logger | :plug | includes: none |_____ > certifi-2.4.2 | | from: _build/prod/lib/certifi | applications: | :kernel | :stdlib | includes: none |_____ > metrics-1.0.1 | | from: _build/prod/lib/metrics | applications: | :kernel | :stdlib | includes: none |_____ > ssl_verify_fun-1.1.4 | | from: _build/prod/lib/ssl_verify_fun | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > mimerl-1.0.2 | | from: _build/prod/lib/mimerl | applications: | :kernel | :stdlib | includes: none |_____ > unicode_util_compat-0.4.1 | | from: _build/prod/lib/unicode_util_compat | applications: | :kernel | :stdlib | includes: none |_____ > idna-6.0.0 | | from: _build/prod/lib/idna | applications: | :kernel | :stdlib | :unicode_util_compat | includes: none |_____ > ssl-9.0.2 | | from: /opt/erlang-freebsd/lib/ssl-9.0.2 | applications: | :crypto | :public_key | :kernel | :stdlib | includes: none |_____ > public_key-1.6.2 | | from: /opt/erlang-freebsd/lib/public_key-1.6.2 | applications: | :asn1 | :crypto | :kernel | :stdlib | includes: none |_____ > asn1-5.0.7 | | from: /opt/erlang-freebsd/lib/asn1-5.0.7 | applications: | :kernel | :stdlib | includes: none |_____ > hackney-1.14.3 | | from: _build/prod/lib/hackney | applications: | :kernel | :stdlib | :crypto | :asn1 | :public_key | :ssl | :idna | :mimerl | :certifi | :ssl_verify_fun | :metrics | includes: none |_____ > ranch-1.3.2 | | from: _build/prod/lib/ranch | applications: | :kernel | :stdlib | :ssl | includes: none |_____ > cowboy-1.1.2 | | from: _build/prod/lib/cowboy | applications: | :kernel | :stdlib | :ranch | :cowlib | :crypto | includes: none |_____ > gen_smtp-0.12.0 | | from: _build/prod/lib/gen_smtp | applications: | :kernel | :stdlib | :crypto | :asn1 | :public_key | :ssl | includes: none |_____ > bamboo_smtp-1.6.0 | | from: _build/prod/lib/bamboo_smtp | applications: | :kernel | :stdlib | :elixir | :gen_smtp | :logger | :bamboo | includes: none |_____ > poison-3.1.0 | | from: _build/prod/lib/poison | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > bamboo-1.1.0 | | from: _build/prod/lib/bamboo | applications: | :kernel | :stdlib | :elixir | :logger | :hackney | :poison | includes: none |_____ > plug_redirect-0.1.2 | | from: _build/prod/lib/plug_redirect | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > ex_phone_number-0.1.1 | | from: _build/prod/lib/ex_phone_number | applications: | :kernel | :stdlib | :elixir | :logger | includes: none |_____ > arc-0.11.0 | | from: _build/prod/lib/arc | applications: | :kernel | :stdlib | :elixir | :logger | :hackney | includes: none |_____ > combine-0.10.0 | | from: _build/prod/lib/combine | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > tzdata-0.5.19 | | from: _build/prod/lib/tzdata | applications: | :kernel | :stdlib | :elixir | :hackney | :logger | includes: none |_____ > timex-3.4.1 | | from: _build/prod/lib/timex | applications: | :kernel | :stdlib | :elixir | :logger | :tzdata | :gettext | :combine | includes: none |_____ > gettext-0.16.0 | | from: _build/prod/lib/gettext | applications: | :kernel | :stdlib | :elixir | :logger | includes: none |_____ > marcus-0.1.1 | | from: _build/prod/lib/marcus | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > logger-1.7.3 | | from: /nix/store/7hfhxiq3bm7lgsd7gz66avjqksc9vw6f-elixir-1.7.3/lib/elixir/bin/../lib/logger | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > - | | from: _build/prod/lib/ | applications: | :kernel | :stdlib | :elixir | :logger | :runtime_tools | :marcus | :gettext | :timex | :arc | :ex_phone_number | :phoenix_pubsub | :cowboy | :ex_rated | :phoenix_html | :plug_redirect | :bamboo | :bamboo_smtp | :phoenix | :postgrex | :arc_ecto | :distillery | :observer_cli | :toml | :phoenix_ecto | includes: none |_____ > compiler-7.2.5 | | from: /opt/erlang-freebsd/lib/compiler-7.2.5 | applications: | :kernel | :stdlib | includes: none |_____ > sasl-3.2.1 | | from: /opt/erlang-freebsd/lib/sasl-3.2.1 | applications: | :kernel | :stdlib | includes: none |_____ > iex-1.7.3 | | from: /nix/store/7hfhxiq3bm7lgsd7gz66avjqksc9vw6f-elixir-1.7.3/lib/elixir/bin/../lib/iex | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > mix-1.7.3 | | from: /nix/store/7hfhxiq3bm7lgsd7gz66avjqksc9vw6f-elixir-1.7.3/lib/elixir/bin/../lib/mix | applications: | :kernel | :stdlib | :elixir | includes: none |_____ > elixir-1.7.3 | | from: /nix/store/7hfhxiq3bm7lgsd7gz66avjqksc9vw6f-elixir-1.7.3/lib/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=: release_version="" is_upgrade=false upgrade_from=:latest dev_mode=false include_erts="/opt/erlang-freebsd" include_src=false include_system_libs="/opt/erlang-freebsd" erl_opts="" run_erl_env="" erts_vsn="10.1" output_dir="_build/prod/rel/" ==> Copying applications to _build/prod/rel/ ==> Generating start_erl.data ==> Generating vm.args ==> Generating sys.config from config/config.exs ==> Including ERTS 10.1 from /opt/erlang-freebsd/erts-10.1 ==> Generating boot scripts ==> Generating RELEASES ==> Applying overlays ==> Applying mkdir overlay dst: releases//hooks ==> Applying mkdir overlay dst: releases//hooks/pre_configure.d ==> Applying mkdir overlay dst: releases//hooks/post_configure.d ==> Applying mkdir overlay dst: releases//hooks/pre_start.d ==> Applying mkdir overlay dst: releases//hooks/post_start.d ==> Applying mkdir overlay dst: releases//hooks/pre_stop.d ==> Applying mkdir overlay dst: releases//hooks/post_stop.d ==> Applying mkdir overlay dst: releases//hooks/pre_upgrade.d ==> Applying mkdir overlay dst: releases//hooks/post_upgrade.d ==> Applying copy overlay src: rel/hooks/pre_start dst: releases//hooks/pre_start.d ==> Applying copy overlay src: _build/prod/lib/distillery/priv/libexec dst: releases//libexec ==> Applying mkdir overlay dst: releases//commands ==> Applying copy overlay src: rel/config/defaults.toml dst: etc/config.toml.sample ==> Packaging release.. ==> Archiving - ==> Writing archive to /***//_build/prod/rel//releases//.tar.gz ==> Updating archive.. ==> Including system libs from /opt/erlang-freebsd ==> Saving archive.. ==> Archive saved! Release successfully built! ```

Description of issue

What are the expected results?

All dependencies should be included in _build/prod/rel/<app>/lib and in the lib/ directory inside the .tar.gz. However, the lib/ directory in the archive contains only applications from OTP and my application. No Mix dependencies, no Elixir. It does work properly when using include_erts: true.

What version of Distillery?

2.0.10

What OS, Erlang/Elixir versions are you seeing this issue on?

The custom OTP is Erlang/OTP 21.1 built on FreeBSD 11.2-RELEASE-p4 from the ports tree.

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

```elixir # Import all plugins from `rel/plugins`. ~w(rel plugins *.exs) |> Path.join() |> Path.wildcard() |> Enum.map(&Code.eval_file(&1)) use Mix.Releases.Config, default_release: :default, default_environment: Mix.env() alias TomlTransforms.{LogLevel, MailerConfig, SSL} environment :dev do set dev_mode: true set include_erts: false set cookie: :":)" end environment :preprod do set include_erts: true set include_src: false set pre_start_hooks: "rel/hooks/pre_start" set cookie: :":)" set config_providers: [ {Toml.Provider, path: "${RELEASE_ROOT_DIR}/etc/config.toml", transforms: [LogLevel, MailerConfig, SSL]} ] set overlays: [ {:copy, "rel/config/preprod.toml", "etc/config.toml"} ] end environment :prod do set include_erts: true set include_src: false set pre_start_hooks: "rel/hooks/pre_start" set cookie: :":)" set config_providers: [ {Toml.Provider, path: "${RELEASE_ROOT_DIR}/etc/config.toml", transforms: [LogLevel, MailerConfig, SSL]} ] set overlays: [ {:copy, "rel/config/defaults.toml", "etc/config.toml.sample"} ] end environment :freebsd do set include_erts: "/opt/erlang-freebsd" set include_src: false set pre_start_hooks: "rel/hooks/pre_start" set cookie: :":)" set config_providers: [ {Toml.Provider, path: "${RELEASE_ROOT_DIR}/etc/config.toml", transforms: [LogLevel, MailerConfig, SSL]} ] set overlays: [ {:copy, "rel/config/defaults.toml", "etc/config.toml.sample"} ] end release :"" do set version: current_version(:"") end ```
itSQualL commented 5 years ago

I'm having same issues.

I'm cross compiling from ubuntu to raspbian including erts.

When I copy the entire _build/prod folder to the raspberry it works like a charm.

But trying to copy the generated tar.gz is a headache.

The $ROOTDIR is bad calculated https://github.com/bitwalker/distillery/blob/master/priv/libexec/erts.sh#L301, so it isn't able to reach the erts folder.

After that, when I put it manually, it fails on trying to get the dependencies (https://github.com/bitwalker/distillery/blob/master/priv/libexec/erts.sh#L25-L33)

I think I'm missing something here.

sujithrs commented 5 years ago

I had the same issue. The following patch seems to fix the issue. I was able to cross compile from ubuntu to raspbian with erts successfully.

diff --git a/lib/mix/lib/releases/archiver.ex b/lib/mix/lib/releases/archiver.ex
index 674ff1e..af50f1b 100644
--- a/lib/mix/lib/releases/archiver.ex
+++ b/lib/mix/lib/releases/archiver.ex
@@ -236,15 +236,15 @@ defmodule Mix.Releases.Archiver do
     end)
   end

-  defp maybe_include_system_libs(archive, %Release{profile: %{include_erts: true}}, tmpdir) do
+  defp maybe_include_system_libs(archive, %Release{profile: %{include_erts: _}}, tmpdir) do
     Shell.debug("Including system libs from current Erlang installation")
     Archive.add(archive, Path.join(tmpdir, "lib"), "lib")
   end

https://github.com/bitwalker/distillery/blob/b945641ebbc17848378f4cd0f1c116ec78326ad4/lib/mix/lib/releases/archiver.ex#L238

ejpcmac commented 5 years ago

@sujithrs Your patch won’t exclude system libs in case include_erts: false is set, but I think you’ve spotted where the problem is :)

ejpcmac commented 5 years ago

I’ve made a PR with the patch after reading a bit the code and using it for a project update. Thank you @sujithrs for the spotting the issue.