Variable name in Distillery release

I have multiple projects and I want them to share the ‘almost same’ configuration for building the release and deployment. Edeliver was was as it is ‘just BASH’. However, with distillery I have 1 problem: I don’t know how to get the name of the app in the config file.

Tried both Mix.Project.config[:name] and something with the path of the file, but I just can’t get it to work. I would like something like this…

environment :prod do
  set include_erts: true
  set include_src: false
  set cookie: :"*snip"
  plugin Releases.Plugin.LinkConfig
  set vm_args: "/home/unprivileged/${APP_STRING}.args"
end

release APP_ATOM do
  set version: current_version(APP_ATOM)
end

Any help?

Update: After rereading your question, this should work: Mix.Project.config[:app]

If I am not mistaken this file is compiled when the release is built, so you should be able to use String.to_atom System.get_env("APP_NAME") and prefix your release with the APP_NAME environment variable

Yeah, tried that one already. But the release function doesn’t like it:

name_atom = Mix.Project.config[:app]
name_string = Atom.to_string (name_atom)

release(name_atom) do
  set version: current_version(name_atom)
end

==> Failed to load config:
no function clause matching in Mix.Releases.Config.release/2

I already checked if name_atom is an atom. And yes, it is. What do I mis?

Talked to Bitwalker about it, and it was not possible. ‘Fixed’ in master branch of Distillery.

Thumbs up for Bitwalker for the quick reply :slight_smile:

1 Like

I tried with the master branch of Distillery, but I still get no access to my app name. Here’s what I tried:

1> Mix.Project.config[:app]
nil

That’s no wonder, because:

2> Mix.Project.config
[aliases: [], build_embedded: false, build_per_environment: true,
 build_scm: Mix.SCM.Path, config_path: "config/config.exs",
 consolidate_protocols: true, default_task: "run", deps: [], deps_path: "deps",
 elixirc_paths: ["lib"], erlc_paths: ["src"], erlc_include_path: "include",
 erlc_options: [:debug_info], lockfile: "mix.lock", preferred_cli_env: [],
 start_permanent: false]

Without that, there is a bunch of libraries which fail — like phoenix_linguist which does the following:

def i18n(conn) do
  Mix.Project.config()[:app]
  |> Application.get_env(endpoint_module(conn))
  |> Dict.get(:i18n)
end

Everything works when running

mix phoenix.server

but when I run the (successfully built release with e.g.

_build/prod/rel/kokuhu/bin/kokuhu console

I run into exceptions…

Looks like the mix dependency in phoenix_linguist (or an non-task for mix) is a bad idea: The problem is solved with forking the project and replacing Mix.Project.config()[:app] by conn.private.phoenix_endpoint.config(:otp_app). Releases are working now!

1 Like