Last active
October 12, 2015 22:59
-
-
Save MSch/e7c34eb846ee647813ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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