Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend : building release with distillery
- Loading branch information
Matthieu Segret
committed
Jul 3, 2018
1 parent
cf0e336
commit 6352b67
Showing
12 changed files
with
160 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
defmodule Yummy.ReleaseTasks do | ||
@start_apps [ | ||
:crypto, | ||
:ssl, | ||
:postgrex, | ||
:ecto, | ||
:ex_aws, | ||
:arc, | ||
:timex | ||
] | ||
|
||
def myapp, do: :yummy | ||
|
||
def repos, do: Application.get_env(myapp(), :ecto_repos, []) | ||
|
||
def seed do | ||
# Setup the Repo(s) for myapp | ||
setup() | ||
|
||
# Run seed script | ||
Enum.each(repos(), &run_seeds_for/1) | ||
|
||
# Signal shutdown | ||
IO.puts("Loading seeds success!") | ||
:init.stop() | ||
end | ||
|
||
def migrate do | ||
# Setup the Repo(s) for myapp | ||
setup() | ||
|
||
# Run migrations | ||
Enum.each(repos(), &run_migrations_for/1) | ||
|
||
# Signal shutdown | ||
IO.puts("Migrating success!") | ||
:init.stop() | ||
end | ||
|
||
def priv_dir(app), do: "#{:code.priv_dir(app)}" | ||
|
||
defp setup 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)) | ||
end | ||
|
||
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 |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
|
||
# running database migration | ||
$RELEASE_ROOT_DIR/bin/yummy command Elixir.Yummy.ReleaseTasks migrate |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
|
||
# loading seeds | ||
$RELEASE_ROOT_DIR/bin/yummy command Elixir.Yummy.ReleaseTasks seed |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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. | ||
Path.join(["rel", "plugins", "*.exs"]) | ||
|> Path.wildcard() | ||
|> Enum.map(&Code.eval_file(&1)) | ||
|
||
use Mix.Releases.Config, | ||
default_release: :default, | ||
default_environment: :prod | ||
|
||
environment :prod do | ||
set(include_erts: true) | ||
set(include_src: false) | ||
set(cookie: :";W^JBe|r10%%>?@&Y8XgVeZwH9kJ?w?bO/bl1!gjiD(P.<;2IkIz,[o<Mox:<.qg") | ||
|
||
set( | ||
commands: [ | ||
migrate: "rel/commands/migrate.sh", | ||
seeds: "rel/commands/seeds.sh" | ||
] | ||
) | ||
end | ||
|
||
release :yummy do | ||
set(version: current_version(:yummy)) | ||
set(vm_args: "rel/vm.args") | ||
|
||
set( | ||
applications: [ | ||
:runtime_tools | ||
] | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Name of the node | ||
-name ${NODE_NAME} | ||
|
||
## Cookie for distributed erlang | ||
-setcookie ${NODE_COOKIE} | ||
|
||
## App Settings | ||
-yummy port ${PORT} |