bitwalker / distillery

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

vm.args not loaded when running release tasks. #588

Closed bsechter-unext closed 5 years ago

bsechter-unext commented 5 years ago

Steps to reproduce

tl;dr, run node() from a release task versus the release console.

rel/vm.args (comments removed)

-name ${NODE_NAME}

myapp/lib/release_tasks.ex

defmodule :release_tasks do
  def node, do: node() |> IO.puts
end

rel/config.exs (relevant section)

release :myapp do
  set vm_args: "rel/vm.args"
  set applications: [
    :runtime_tools,
    myapp: :permanent
  ]
  set commands: [
    "myapp.info": "rel/commands/myapp_node"
  ]
end

rel/commands/myapp_node

#!/usr/bin/env sh
"${SCRIPT}" command release_tasks node

Given the above setup, build a release and compare the output of node() function when run in a release task with the same function run when run from the release console.

export NODE_NAME="mynode@127.0.0.1"
$ _build/prod/rel/myapp/bin/myapp myapp.node
nonode@nohost
$ _build/prod/rel/myapp/bin/myapp console
# (snip)
iex(mynode@127.0.0.1)1> :release_tasks.node
mynode@127.0.0.1

Verbose Logs

Paste the output of the release command you ran with the --verbose flag below in the summary tags (this helps keep the issue easy to navigate):

``` (no verbose output) ```

Description of issue

$ date -u "+%Y-%m-%d %H:%M:%S +0000"
2018-11-14 12:39:56 +0000
$ uname -vm
#39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64
$ mix hex.info
Hex:    0.18.2
Elixir: 1.7.3
OTP:    21.1

Built with: Elixir 1.7.4 and OTP 19.3
$ cat mix.lock | grep distillery | cut -d" " -f 3,6 | sed 's/[",]//g'
distillery: 2.0.10
$ cat rel/config.exs | sed -e 's/#.*$//' -e '/^$/d' | sed '/^\s*$/d' | sed 's/myrealappname/myapp/g'
~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()
environment :dev do
  set dev_mode: true
  set include_erts: false
  set cookie: :"oVVuxeOsnMQawK4nRZ1VkBK6sLU5kfV+TF1YkBbR0rre92aEVVVx/NNLIyZd3L+w"
end
environment :prod do
  set include_erts: true
  set include_src: false
  set cookie: :"oqjl275+3SVUZl05UxDCMmpSB/UqDYTWfl38Z6Cae6UZdfdddGzE1tQsm5r1DTuN"
end
release :myapp do
  set vm_args: "rel/vm.args"
  set version: current_version(:myapp_interface)
  set applications: [
    :runtime_tools,
    myapp_cache: :permanent,
    myapp_interface: :permanent
  ]
  set commands: [
    "myapp.info": "rel/commands/myapp_info",
    "myapp.setup": "rel/commands/myapp_setup",
    "myapp.remove": "rel/commands/myapp_remove"
  ]
end

I expect to be able to configure to node for release tasks, although I can did not manage to find documentation one way or another. Please let me know if you need anything else.

bsechter-unext commented 5 years ago

The conclusion of a conversation on the Slack distillery channel is that release tasks are the wrong tool for initializing mnesia databases. Idempotently initializing in the relevant GenServer init function or at the application level seems to be the way to set up mnesia or other things that need to run on the proper node.

bitwalker commented 5 years ago

command also runs in a clean node, so it is expected that there would be no node name, it is also deprecated in 2.0 in favor of the new eval