Skip to content

Instantly share code, notes, and snippets.

@MSch
Last active October 12, 2015 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MSch/e7c34eb846ee647813ee to your computer and use it in GitHub Desktop.
Save MSch/e7c34eb846ee647813ee to your computer and use it in GitHub Desktop.
defmodule ReleaseManager.Plugin.ReleaseTasks do
@name "release_tasks"
@shortdoc "Generates an escript to invoke PS.ReleaseTasks"
use ReleaseManager.Plugin
alias ReleaseManager.Utils
def before_release(_), do: nil
def after_release(%Config{name: name}) do
File.write(Utils.rel_dest_path([name, "bin", "release_tasks.escript"]), """
#!/usr/bin/env escript
%%! -config running-config/sys.config
main(Args) -> 'Elixir.PS.ReleaseTasks':main(Args).
""")
end
def after_cleanup(_), do: nil
def after_package(_), do: nil
end
defmodule PS.ReleaseTasks do
@moduledoc ~S"""
Mix is not available in a built release. Instead we define the tasks here and use a small escript
that delegates to `PS.ReleaseTasks.main`. See `ReleaseManager.Plugin.ReleaseTasks`.
In the release you can invoke tasks like this:
bin/pssync escript bin/release_tasks.escript migrate
"""
def main(['migrate']), do: migrate()
def migrate do
start_applications([:logger, :sbroker, :postgrex, :ecto])
Application.load(:pssync)
PS.Ecto.PGPidCache.start_link()
PS.Repo.start_link()
migrations_path = Application.app_dir(:pssync, "priv/migrations")
Ecto.Migrator.run(PS.Repo, migrations_path, :up, all: true)
end
defp start_applications(apps) do
Enum.each(apps, fn app ->
{:ok, _} = Application.ensure_all_started(app)
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment