Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error when call build task with distillery #40

Closed
diegonogueira opened this issue Aug 31, 2018 · 6 comments
Closed

Error when call build task with distillery #40

diegonogueira opened this issue Aug 31, 2018 · 6 comments

Comments

@diegonogueira
Copy link

When I try to run with distillery command:

Building elasticsearch indexes for app
** (exit) exited in: GenServer.call(Mix.ProjectStack, {:get, #Function<11.107724793/1 in Mix.ProjectStack.peek/0>}, 30000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir) lib/gen_server.ex:914: GenServer.call/3
    lib/mix/project.ex:155: Mix.Project.get/0
    lib/mix/task.ex:274: Mix.Task.run/2
    (elasticsearch) lib/mix/elasticsearch.build.ex:49: Mix.Tasks.Elasticsearch.Build.run/1
    (app) lib/mix/tasks/app.task.ex:8: Mix.Tasks.App.Task.run/1
    lib/mix/lib/releases/runtime/control.ex:717: Mix.Releases.Runtime.Control.eval/2
    lib/entry.ex:44: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:677: :erl_eval.do_apply/6

I think, the problem is Mix.Task.run("app.start", []). Maybe if the elasticsearch.build.ex contains only the code to build/index. Then, we can create our task(with our start_app) that calls Mix.Tasks.Elasticsearch.Build.run..

Any idea? Thanks!

@danielberkompas
Copy link
Owner

@diegonogueira can you share the distillery script you are running?

@diegonogueira
Copy link
Author

diegonogueira commented Aug 31, 2018

Yes :)

rel/config.exs

# 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: :"xyz"
  set overlays: [
    {:mkdir, "priv/elasticsearch"},
    {:copy, "priv/elasticsearch", "priv/elasticsearch"}
  ]
  set commands: [
    elasticsearch: "rel/commands/elasticsearch.sh"
  ]
end

environment :prod do
  set include_erts: true
  set include_src: false
  set cookie: :"xyz"
  set vm_args: "rel/vm.args"
  set overlays: [
    {:mkdir, "priv/elasticsearch"},
    {:copy, "priv/elasticsearch", "priv/elasticsearch"}
  ]
  set commands: [
    elasticsearch: "rel/commands/elasticsearch.sh"
  ]
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 :app do
  set version: current_version(:app)
  set applications: [
    :runtime_tools
  ]
end

rel/commands/elasticsearch.sh

#!/usr/bin/env bash

release_ctl eval --mfa "Mix.Tasks.Elasticsearch.Build.run/1" --argv -- "$@"

run:

MIX_ENV=dev mix release --env=dev && _build/dev/rel/app/bin/app elasticsearch profiles --cluster App.ElasticsearchCluster

@danielberkompas
Copy link
Owner

So the root problem here is that Distillery does not support running mix tasks. This is because Mix is not included in the built app. See this example from the official Distillery docs on how to run Ecto migrations.

I'll work on some documentation to show how to create a ReleaseTasks module for this library when using Distillery.

@diegonogueira
Copy link
Author

Yes.. I already have some tasks using Application.ensure_all_started.. The problem is with Mix.Tasks.Elasticsearch.Build that call automatically Mix.Task.run("app.start", []).

Thanks :)

danielberkompas added a commit that referenced this issue Aug 31, 2018
This will make it much simpler to call from other scripts, such as a
Distillery ReleaseTasks script.
danielberkompas added a commit that referenced this issue Aug 31, 2018
@diegonogueira
Copy link
Author

Thanks! It worked!

@jhonathas
Copy link

Thank you very much, it worked very well for me.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants