Merge pull request #1131 from atoulme/release_build

Add release build
pull/1164/head
Andrew Cravenho 6 years ago committed by GitHub
commit 67e1dba177
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      .circleci/config.yml
  2. 93
      apps/explorer/lib/release_tasks.ex
  3. 4
      mix.exs
  4. 2
      mix.lock
  5. 3
      rel/commands/migrate.sh
  6. 3
      rel/commands/seed.sh
  7. 85
      rel/config.exs
  8. 3
      rel/plugins/.gitignore
  9. 30
      rel/vm.args

@ -122,6 +122,7 @@ jobs:
- mix.exs
- mix.lock
- appspec.yml
- rel
check_formatted:
docker:
# Ensure .tool-versions matches
@ -279,6 +280,32 @@ jobs:
name: Jest
command: ./node_modules/.bin/jest
working_directory: apps/block_scout_web/assets
release:
docker:
# Ensure .tool-versions matches
- image: circleci/elixir:1.7.2
environment:
MIX_ENV: prod
working_directory: ~/app
steps:
- attach_workspace:
at: .
- run: mix local.hex --force
- run: mix local.rebar --force
- run: mix release --verbose --env prod
- run:
name: Collecting artifacts
command: |
find -name 'blockscout.tar.gz' -exec sh -c 'mkdir -p ci_artifact && cp "$@" ci_artifact/ci_artifact_blockscout.tar.gz' _ {} +
when: always
- store_artifacts:
name: Uploading CI artifacts
path: ci_artifact/ci_artifact_blockscout.tar.gz
destination: ci_artifact_blockscout.tar.gz
sobelow:
docker:
# Ensure .tool-versions matches
@ -561,6 +588,9 @@ workflows:
- jest:
requires:
- build
- release:
requires:
- build
- sobelow:
requires:
- build

@ -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

@ -63,7 +63,9 @@ defmodule BlockScout.Mixfile do
# Documentation
{:ex_doc, "~> 0.19.0", only: [:dev]},
# Code coverage
{:excoveralls, "~> 0.10.0", only: [:test], github: "KronicDeth/excoveralls", branch: "circle-workflows"}
{:excoveralls, "~> 0.10.0", only: [:test], github: "KronicDeth/excoveralls", branch: "circle-workflows"},
# Release
{:distillery, "~> 2.0", runtime: false}
]
end
end

@ -6,6 +6,7 @@
"absinthe_plug": {:hex, :absinthe_plug, "1.4.6", "ac5d2d3d02acf52fda0f151b294017ab06e2ed1c6c15334e06aac82c94e36e08", [:mix], [{:absinthe, "~> 1.4.11", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.2 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"absinthe_relay": {:hex, :absinthe_relay, "1.4.4", "d0a6d8e71375a6026974d227456c8a73ea8eea7c7b00e698603ab5a96066c333", [:mix], [{:absinthe, "~> 1.4.0", [hex: :absinthe, repo: "hexpm", optional: false]}, {:ecto, "~> 2.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
"accept": {:hex, :accept, "0.3.3", "548ebb6fb2e8b0d170e75bb6123aea6ceecb0189bb1231eeadf52eac08384a97", [:rebar3], [], "hexpm"},
"artificery": {:hex, :artificery, "0.2.6", "f602909757263f7897130cbd006b0e40514a541b148d366ad65b89236b93497a", [:mix], [], "hexpm"},
"bcrypt_elixir": {:hex, :bcrypt_elixir, "1.1.1", "6b5560e47a02196ce5f0ab3f1d8265db79a23868c137e973b27afef928ed8006", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"benchee": {:hex, :benchee, "0.13.2", "30cd4ff5f593fdd218a9b26f3c24d580274f297d88ad43383afe525b1543b165", [:mix], [{:deep_merge, "~> 0.1", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"},
"benchee_csv": {:hex, :benchee_csv, "0.8.0", "0ca094677d6e2b2f601b7ee7864b754789ef9d24d079432e5e3d6f4fb83a4d80", [:mix], [{:benchee, "~> 0.12", [hex: :benchee, optional: false]}, {:csv, "~> 2.0", [hex: :csv, optional: false]}]},
@ -25,6 +26,7 @@
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], []},
"deep_merge": {:hex, :deep_merge, "0.2.0", "c1050fa2edf4848b9f556fba1b75afc66608a4219659e3311d9c9427b5b680b3", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], []},
"distillery": {:hex, :distillery, "2.0.12", "6e78fe042df82610ac3fa50bd7d2d8190ad287d120d3cd1682d83a44e8b34dfb", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "2.2.11", "4bb8f11718b72ba97a2696f65d247a379e739a0ecabf6a13ad1face79844791c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"},

@ -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…
Cancel
Save