Release with distillery is always built using environment dev

Hello. I’m trying to release my phoenix project with ecto. I chose distillery for packaging phoenix project.
I refered this document for installing distillery.

I cannot run built file on Ubuntu 18, but I can run on MacOS

First, I have added distillery to the project like this.

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.5.1"},
      {:phoenix_ecto, "~> 4.1"},
      {:ecto_sql, "~> 3.4"},
      {:ecto, "~> 3.0"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_dashboard, "~> 0.2.0"},
      {:telemetry_metrics, "~> 0.4"},
      {:telemetry_poller, "~> 0.4"},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:guardian, "~> 2.0"},
      {:calendar, "~> 0.17.4"},
      {:guardian_phoenix, "~> 2.0"},
      {:secure_random, "~> 0.5"},
      {:poison, "~> 3.1"},
      {:distillery, "~> 2.0"}
      # {:argon2_elixir, "~> 2.0"}
    ]
  end

and then, changed config/prod.exs like this.

config :milk, MilkWeb.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [host: "localhost", port: {:system, "PORT"}],
  #cache_static_manifest: "priv/static/cache_manifest.json",
  server: true,
  root: ".",
  version: Application.spec(:milk, :vsn)

After that, I used these commands;

sudo mix deps.get
MIX_ENV=prod sudo mix compile
sudo mix distillery.init
MIX_ENV=prod sudo mix distillery.release
✗ PORT=4000 sudo _build/dev/rel/milk/bin/milk foreground
[debug] Tzdata polling for update.
[info] tzdata release in place is from a file last modified Wed, 11 Sep 2019 19:35:17 GMT. Release file on server was last modified Wed, 07 Oct 2020 15:55:18 GMT.
[debug] Tzdata downloading new data from https://data.iana.org/time-zones/tzdata-latest.tar.gz
[debug] Tzdata data downloaded. Release version 2020b.
[info] Tzdata has updated the release from 2019c to 2020b
[debug] Tzdata deleting ETS table for version 2019c
[debug] Tzdata deleting ETS table file for version 2019c

It did not throw any errors. But I cannot access to the phoenix server.


I wonder it’s because of release problem.

✗ MIX_ENV=prod sudo mix distillery.release
==> Assembling release..
==> Building release milk:0.1.0 using environment dev
==> 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/milk/bin/milk console

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

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

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

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

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

For a complete listing of commands and their use:

    > _build/dev/rel/milk/bin/milk help

It says Building release milk:0.1.0 using environment dev. I think it should be using production dev. But I don’t know how to change it…

Help me!

Don’t forget to pass --env=prod to the distillery command.

1 Like

Thank you!