meraj
I have an elixir umbrella project with three applications. I am creating its binary (release) via distillery.
Running this command creates .tar.gz file in _build/prod/rel/se/releases/0.1.0:
MIX_ENV=prod mix release --env=qa
And I am able to extract and run the application. To run ecto migration I have added this module for release tasks [by following https://hexdocs.pm/distillery/running-migrations.html ]:
defmodule Se.ReleaseTasks do
@start_apps [
:postgrex,
:ecto
]
def myapp, do: Application.get_application(__MODULE__)
def repos, do: Application.get_env(myapp(), :ecto_repos, [])
def seed() do
me = myapp()
IO.puts "Loading #{me}.."
# Load the code for myapp, but don't start it
:ok = Application.load(me)
IO.puts "Starting dependencies.."
# Start apps necessary for executing migrations
Enum.each(@start_apps, &Application.ensure_all_started/1)
# Start the Repo(s) for myapp
IO.puts "Starting repos.."
Enum.each(repos(), &(&1.start_link(pool_size: 1)))
# Run migrations
migrate()
# Run seed script
Enum.each(repos(), &run_seeds_for/1)
# Signal shutdown
IO.puts "Success!"
:init.stop()
end
def migrate, do: Enum.each(repos(), &run_migrations_for/1)
def priv_dir(app), do: "#{:code.priv_dir(app)}"
defp run_migrations_for(repo) do
app = Keyword.get(repo.config, :otp_app)
IO.puts "Running migrations for #{app}"
Ecto.Migrator.run(repo, migrations_path(repo), :up, all: true)
end
def run_seeds_for(repo) do
# Run the seed script if it exists
seed_script = seeds_path(repo)
if File.exists?(seed_script) do
IO.puts "Running seed script.."
Code.eval_file(seed_script)
end
end
def migrations_path(repo), do: priv_path_for(repo, "migrations")
def seeds_path(repo), do: priv_path_for(repo, "seeds.exs")
def priv_path_for(repo, filename) do
app = Keyword.get(repo.config, :otp_app)
repo_underscore = repo |> Module.split |> List.last |> Macro.underscore
Path.join([priv_dir(app), repo_underscore, filename])
end
end
Application is run and compiled with this code located in one of the umbrella project where we require migrations. After compilation and starting server, when I try to run it via:
bin/se_cloud command Elixir.Se.ReleaseTasks seed
I get this error:
Elixir.Se.ReleaseTasks.seed is either not defined or has a non-zero arity
Did anyone else encounter this issue? Or I am mis-configuring something here?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Can you connect to the remote shell
bin/se_cloud remote_consoleand check that this module actually exists (or loaded)?meraj
I did that and following is the output:
idi527
That might be the problem. For some reason this module does not get loaded in your release. What “otp app” do you define this module in? Does that “otp app” get added to the release?
In other words, it seems that your app is named
:se(judging bySe). Is:seanywhere in yourrel/config.exs?meraj
Yes. I have it defined in my rel/config.exs as (it was in fact generated by distillery itself when I ran mix release.init I only added the set commands option.):
idi527
Ok, and what’s the folder of the file where
Se.ReleaseTasksis defined? Is it underapps/se/lib/?meraj
No this is file is defined under apps/se/
File name is release_tasks.ex
meraj
After moving release_tasks.ex to app/se/lib and creating release again I am getting this:
However, now when I run the seed command, I am getting this error:
I also checked it from remote console:
I am not sure whey getting this error now while I am able to run the bin/se_cloud start with seeing any error on console or logs.
idi527
You probably need to load your application before running the migrations.
meraj
Yes. In ReleaseTasks module I am trying to load application first, as you can see in my code:
But it is failing upon loading it. I also tried to run this via remote console:
And getting this nil which means it is not able find application while I am able to run bin/se_cloud start without any error printed to console / logs.
idi527
I don’t think
Application.get_application(:se)should return anything butnilunless you have defined:semodule for some application.What you should probably do is
I’ve added a
raise/1here to “fail fast” in the case no application gets found. It would also provide us with a more constructive error message (couldn't get application for Se.ReleaseTasks) than what we’ve had before ({{badmatch,{error,{“no such file or directory”,“nil.app”}}}).