commit
67e1dba177
@ -0,0 +1,93 @@ |
||||
defmodule Explorer.ReleaseTasks do |
||||
@moduledoc """ |
||||
Release tasks used to migrate or generate seeds. |
||||
""" |
||||
|
||||
alias Ecto.Migrator |
||||
|
||||
@start_apps [ |
||||
:crypto, |
||||
:ssl, |
||||
:postgrex, |
||||
:ecto, |
||||
# If using Ecto 3.0 or higher |
||||
:ecto_sql |
||||
] |
||||
|
||||
@repos Application.get_env(:blockscout, :ecto_repos, [Explorer.Repo]) |
||||
|
||||
def migrate(_argv) do |
||||
start_services() |
||||
|
||||
run_migrations() |
||||
|
||||
stop_services() |
||||
end |
||||
|
||||
def seed(_argv) do |
||||
start_services() |
||||
|
||||
run_migrations() |
||||
|
||||
run_seeds() |
||||
|
||||
stop_services() |
||||
end |
||||
|
||||
defp start_services do |
||||
IO.puts("Starting dependencies..") |
||||
# Start apps necessary for executing migrations |
||||
Enum.each(@start_apps, &Application.ensure_all_started/1) |
||||
|
||||
# Start the Repo(s) for app |
||||
IO.puts("Starting repos..") |
||||
|
||||
# Switch pool_size to 2 for ecto > 3.0 |
||||
Enum.each(@repos, & &1.start_link(pool_size: 1)) |
||||
end |
||||
|
||||
defp stop_services do |
||||
IO.puts("Success!") |
||||
:init.stop() |
||||
end |
||||
|
||||
defp run_migrations do |
||||
Enum.each(@repos, &run_migrations_for/1) |
||||
end |
||||
|
||||
defp run_migrations_for(repo) do |
||||
app = Keyword.get(repo.config, :otp_app) |
||||
IO.puts("Running migrations for #{app}") |
||||
migrations_path = priv_path_for(repo, "migrations") |
||||
Migrator.run(repo, migrations_path, :up, all: true) |
||||
end |
||||
|
||||
defp run_seeds do |
||||
Enum.each(@repos, &run_seeds_for/1) |
||||
end |
||||
|
||||
# sobelow_skip ["RCE.CodeModule"] |
||||
defp run_seeds_for(repo) do |
||||
# Run the seed script if it exists |
||||
seed_script = priv_path_for(repo, "seeds.exs") |
||||
|
||||
if File.exists?(seed_script) do |
||||
IO.puts("Running seed script..") |
||||
Code.eval_file(seed_script) |
||||
end |
||||
end |
||||
|
||||
defp priv_path_for(repo, filename) do |
||||
app = Keyword.get(repo.config, :otp_app) |
||||
|
||||
repo_underscore = |
||||
repo |
||||
|> Module.split() |
||||
|> List.last() |
||||
|> Macro.underscore() |
||||
|
||||
priv_dir = "#{:code.priv_dir(app)}" |
||||
|
||||
Path.join([priv_dir, repo_underscore, filename]) |
||||
end |
||||
end |
@ -0,0 +1,3 @@ |
||||
#!/bin/sh |
||||
|
||||
release_ctl eval --mfa "Explorer.ReleaseTasks.migrate/1" --argv -- "$@" |
@ -0,0 +1,3 @@ |
||||
#!/bin/sh |
||||
|
||||
release_ctl eval --mfa "Explorer.ReleaseTasks.seed/1" --argv -- "$@" |
@ -0,0 +1,85 @@ |
||||
# 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)) |
||||
|
||||
defer = fn fun -> |
||||
apply(fun, []) |
||||
end |
||||
|
||||
app_root = fn -> |
||||
if String.contains?(System.cwd!(), "apps") do |
||||
Path.join([System.cwd!(), "/../../"]) |
||||
else |
||||
System.cwd!() |
||||
end |
||||
end |
||||
|
||||
cookie = |
||||
defer.(fn -> |
||||
cookie_bytes = |
||||
:crypto.strong_rand_bytes(32) |
||||
|> Base.encode32() |
||||
|
||||
:ok = File.write!(Path.join(app_root.(), ".erlang_cookie"), cookie_bytes) |
||||
:erlang.binary_to_atom(cookie_bytes, :utf8) |
||||
end) |
||||
|
||||
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: :"i6E,!mJ6|E&|.VPaDywo@N.o}BgmC$UdKXW[aK,(@U0Asfpp/NergA;CR%YW4;i6" |
||||
end |
||||
|
||||
environment :prod do |
||||
set include_erts: true |
||||
set include_src: false |
||||
set cookie: cookie |
||||
set vm_args: "rel/vm.args" |
||||
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 :blockscout do |
||||
set version: "1.2.0-beta" |
||||
set applications: [ |
||||
:runtime_tools, |
||||
block_scout_web: :permanent, |
||||
ethereum_jsonrpc: :permanent, |
||||
explorer: :permanent, |
||||
indexer: :permanent |
||||
] |
||||
set commands: [ |
||||
migrate: "rel/commands/migrate.sh", |
||||
seed: "rel/commands/seed.sh", |
||||
] |
||||
end |
||||
|
@ -0,0 +1,3 @@ |
||||
*.* |
||||
!*.exs |
||||
!.gitignore |
@ -0,0 +1,30 @@ |
||||
## This file provide the arguments provided to the VM at startup |
||||
## You can find a full list of flags and their behaviours at |
||||
## http://erlang.org/doc/man/erl.html |
||||
|
||||
## Name of the node |
||||
-name <%= release_name %>@127.0.0.1 |
||||
|
||||
## Cookie for distributed erlang |
||||
-setcookie <%= release.profile.cookie %> |
||||
|
||||
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive |
||||
## (Disabled by default..use with caution!) |
||||
##-heart |
||||
|
||||
## Enable kernel poll and a few async threads |
||||
##+K true |
||||
##+A 5 |
||||
## For OTP21+, the +A flag is not used anymore, |
||||
## +SDio replace it to use dirty schedulers |
||||
##+SDio 5 |
||||
|
||||
## Increase number of concurrent ports/sockets |
||||
##-env ERL_MAX_PORTS 4096 |
||||
|
||||
## Tweak GC to run more often |
||||
##-env ERL_FULLSWEEP_AFTER 10 |
||||
|
||||
# Enable SMP automatically based on availability |
||||
# On OTP21+, this is not needed anymore. |
||||
-smp auto |
Loading…
Reference in new issue