Skip to content

Commit

Permalink
Enhance Hot upgrades (#25)
Browse files Browse the repository at this point in the history
* Cleanup config

* Move Uniris.Bootstrap.NetworkInit.genesis_pools to config.exs

* Split UNIRIS_P2P_PORT configuration

* Use mix configs for distillery release

* Fix install script arguments

* Keep runtime config in release specific folder

* Provide hot upgrades

* Add distillery hook to copy process environment from the running node
to upgrde script during release upgrade

* Do compile testnet and minenet in install script

* Use unpublished distillery

See bitwalker/distillery#732
  • Loading branch information
pvmart authored Feb 15, 2021
1 parent 6d2e8e5 commit 52cc44c
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 183 deletions.
36 changes: 34 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :git_hooks,
auto_install: true,
Expand Down Expand Up @@ -62,7 +62,7 @@ config :uniris, Uniris.P2P.BootstrappingSeeds, file: "priv/p2p/seeds"
config :uniris, Uniris.P2P.Endpoint,
nb_acceptors: 100,
transport: :tcp,
port: System.get_env("UNIRIS_P2P_PORT", "3002") |> String.to_integer()
port: 3002

# Configure the endpoint
config :uniris, UnirisWeb.Endpoint,
Expand All @@ -76,6 +76,38 @@ config :uniris, UnirisWeb.Endpoint,

config :uniris, Uniris.Governance.Code.CICD, impl: Uniris.Governance.Code.CICD.Docker

config :uniris, Uniris.Bootstrap.NetworkInit,
genesis_pools: [
funding: [
public_key: "002E354A95241E867C836E8BBBBF6F9BF2450860BA28B1CF24B734EF67FF49169E",
amount: 3.82e9
],
deliverable: [
public_key: "00AD439F0CD4048576D4AFB812DCB1815C57EFC303BFF03696436B157C69547128",
amount: 2.36e9
],
enhancement: [
public_key: "008C9309535A3853379D6367F67AB93E3DAF5BFAA41C68BD7C3C1F00AA8D5822FD",
amount: 9.0e8
],
team: [
public_key: "00B1F862FF9E534DAC6A0AD32528E08F7BB0F3DD0DCB253B119900F4CE447C5CC4",
amount: 5.6e8
],
exchange: [
public_key: "004CD06F40D2F75DA02B29D559A3CBD5E07580B1E65163A4F3256CDC8781B280E3",
amount: 3.4e8
],
marketing: [
public_key: "00783510644E885FFAC82FE22FB3F33C5B0936B79B7A3D3A78D5D612341A0B3B9A",
amount: 3.4e8
],
foundation: [
public_key: "00CD534224DE5AE2584163D69A8A99F36E6FAE506373B619736B511A58B804E311",
amount: 2.2e8
]
]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
37 changes: 4 additions & 33 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# config :logger, handle_sasl_reports: true

Expand Down Expand Up @@ -29,38 +29,6 @@ config :uniris, Uniris.P2P.BootstrappingSeeds,
"127.0.0.1:3002:00682FF302BFA84702A00D81D5F97610E02573C0487FBCD6D00A66CCBC0E0656E8:tcp"
)

config :uniris, Uniris.Bootstrap.NetworkInit,
genesis_pools: [
funding: [
public_key: "002E354A95241E867C836E8BBBBF6F9BF2450860BA28B1CF24B734EF67FF49169E",
amount: 3.82e9
],
deliverable: [
public_key: "00AD439F0CD4048576D4AFB812DCB1815C57EFC303BFF03696436B157C69547128",
amount: 2.36e9
],
enhancement: [
public_key: "008C9309535A3853379D6367F67AB93E3DAF5BFAA41C68BD7C3C1F00AA8D5822FD",
amount: 9.0e8
],
team: [
public_key: "00B1F862FF9E534DAC6A0AD32528E08F7BB0F3DD0DCB253B119900F4CE447C5CC4",
amount: 5.6e8
],
exchange: [
public_key: "004CD06F40D2F75DA02B29D559A3CBD5E07580B1E65163A4F3256CDC8781B280E3",
amount: 3.4e8
],
marketing: [
public_key: "00783510644E885FFAC82FE22FB3F33C5B0936B79B7A3D3A78D5D612341A0B3B9A",
amount: 3.4e8
],
foundation: [
public_key: "00CD534224DE5AE2584163D69A8A99F36E6FAE506373B619736B511A58B804E311",
amount: 2.2e8
]
]

config :uniris, Uniris.Crypto.Keystore, impl: Uniris.Crypto.SoftwareKeystore

config :uniris, Uniris.Crypto.SoftwareKeystore,
Expand Down Expand Up @@ -95,6 +63,9 @@ config :uniris, Uniris.SharedSecrets.NodeRenewalScheduler,
# At 40th second
interval: "40 * * * * * *"

config :uniris, Uniris.P2P.Endpoint,
port: System.get_env("UNIRIS_P2P_PORT", "3002") |> String.to_integer()

# For development, we disable any cache and enable
# debugging and code reloading.
#
Expand Down
39 changes: 6 additions & 33 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# Do not print debug messages in production
config :logger, level: :info
Expand All @@ -7,38 +7,8 @@ config :uniris, Uniris.Bootstrap.Sync,
# 15 days
out_of_sync_date_threshold: 54_000

config :uniris, Uniris.Bootstrap.NetworkInit,
# TODO: provide the true addresses for the genesis UCO distribution
genesis_pools: [
funding: [
public_key: "002E354A95241E867C836E8BBBBF6F9BF2450860BA28B1CF24B734EF67FF49169E",
amount: 3.82e9
],
deliverable: [
public_key: "00AD439F0CD4048576D4AFB812DCB1815C57EFC303BFF03696436B157C69547128",
amount: 2.36e9
],
enhancement: [
public_key: "008C9309535A3853379D6367F67AB93E3DAF5BFAA41C68BD7C3C1F00AA8D5822FD",
amount: 9.0e8
],
team: [
public_key: "00B1F862FF9E534DAC6A0AD32528E08F7BB0F3DD0DCB253B119900F4CE447C5CC4",
amount: 5.6e8
],
exchange: [
public_key: "004CD06F40D2F75DA02B29D559A3CBD5E07580B1E65163A4F3256CDC8781B280E3",
amount: 3.4e8
],
marketing: [
public_key: "00783510644E885FFAC82FE22FB3F33C5B0936B79B7A3D3A78D5D612341A0B3B9A",
amount: 3.4e8
],
foundation: [
public_key: "00CD534224DE5AE2584163D69A8A99F36E6FAE506373B619736B511A58B804E311",
amount: 2.2e8
]
]
# TODO: provide the true addresses for the genesis UCO distribution
# config :uniris, Uniris.Bootstrap.NetworkInit, genesis_pools: []

config :uniris, Uniris.BeaconChain.SlotTimer,
# Every 10 minutes at the 50th second
Expand Down Expand Up @@ -79,6 +49,9 @@ config :uniris, Uniris.SelfRepair.Scheduler,
# Every day at midnight
interval: "0 0 0 * * * *"

config :uniris, Uniris.P2P.Endpoint,
port: System.get_env("UNIRIS_P2P_PORT", "3002") |> String.to_integer()

# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
# when generating URLs.
Expand Down
34 changes: 1 addition & 33 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# Print only warnings and errors during test
config :logger, level: :warning
Expand All @@ -19,38 +19,6 @@ config :uniris, Uniris.BeaconChain.SummaryTimer,

config :uniris, Uniris.Bootstrap, enabled: false

config :uniris, Uniris.Bootstrap.NetworkInit,
genesis_pools: [
funding: [
public_key: "002E354A95241E867C836E8BBBBF6F9BF2450860BA28B1CF24B734EF67FF49169E",
amount: 3.82e9
],
deliverable: [
public_key: "00AD439F0CD4048576D4AFB812DCB1815C57EFC303BFF03696436B157C69547128",
amount: 2.36e9
],
enhancement: [
public_key: "008C9309535A3853379D6367F67AB93E3DAF5BFAA41C68BD7C3C1F00AA8D5822FD",
amount: 9.0e8
],
team: [
public_key: "00B1F862FF9E534DAC6A0AD32528E08F7BB0F3DD0DCB253B119900F4CE447C5CC4",
amount: 5.6e8
],
exchange: [
public_key: "004CD06F40D2F75DA02B29D559A3CBD5E07580B1E65163A4F3256CDC8781B280E3",
amount: 3.4e8
],
marketing: [
public_key: "00783510644E885FFAC82FE22FB3F33C5B0936B79B7A3D3A78D5D612341A0B3B9A",
amount: 3.4e8
],
foundation: [
public_key: "00CD534224DE5AE2584163D69A8A99F36E6FAE506373B619736B511A58B804E311",
amount: 2.2e8
]
]

config :uniris, Uniris.Bootstrap.Sync, out_of_sync_date_threshold: 3

config :uniris, Uniris.Contracts.Loader, enabled: false
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule Uniris.MixProject do
{:phoenix_live_dashboard, "~> 0.2.7"},
{:ex_doc, "~> 0.21.2"},
{:observer_cli, "~> 1.5"},
{:distillery, "~> 2.0"},
{:distillery, github: "bitwalker/distillery", ref: "6700edb"},
{:crontab, "~> 1.1"},
{:credo, "~> 1.5", runtime: false},
{:git_hooks, "~> 0.4.0", runtime: false},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"db_connection": {:hex, :db_connection, "2.3.1", "4c9f3ed1ef37471cbdd2762d6655be11e38193904d9c5c1c9389f1b891a3088e", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "abaab61780dde30301d840417890bd9f74131041afd02174cf4e10635b3a63f5"},
"decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"},
"distillery": {:git, "https://github.com/bitwalker/distillery.git", "6700edb017804e51aec14dedb8df888d1db4e63c", [ref: "6700edb"]},
"earmark": {:hex, :earmark, "1.4.13", "2c6ce9768fc9fdbf4046f457e207df6360ee6c91ee1ecb8e9a139f96a4289d91", [:mix], [{:earmark_parser, ">= 1.4.12", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "a0cf3ed88ef2b1964df408889b5ecb886d1a048edde53497fc935ccd15af3403"},
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
"ecto": {:hex, :ecto, "3.5.7", "f440a476bf1be361173a43a4a18f04a2fdf4e6fac5b0457f03d8686e55f13f7e", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "04c4e69d4f1cc2bb085aa760d50389ba8ae3003f80c112fbde87d57f5ed75d39"},
Expand Down
22 changes: 4 additions & 18 deletions rel/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,19 @@ use Distillery.Releases.Config,
# when building in that environment, this combination of release
# and environment configuration is called a profile

environment :dev do
environment Mix.env() do
set include_erts: true
set include_src: false
set cookie: :crypto.strong_rand_bytes(32) |> Base.encode16() |> String.to_atom()
set vm_args: "rel/vm.args"
set pre_configure_hooks: "rel/pre_configure"

set config_providers: [
{Distillery.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/runtime_config.exs"]}
{Distillery.Releases.Config.Providers.Elixir, ["${REL_DIR}/runtime_config.exs"]}
]

set overlays: [
{:copy, "rel/dev_runtime_config.exs", "runtime_config.exs"}
]
end

environment :prod do
set include_erts: true
set include_src: false
set cookie: :crypto.strong_rand_bytes(32) |> Base.encode16() |> String.to_atom()
set vm_args: "rel/vm.args"

set config_providers: [
{Distillery.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/runtime_config.exs"]}
]

set overlays: [
{:copy, "rel/main_runtime_config.exs", "runtime_config.exs"}
{:copy, "config/#{Mix.env()}.exs", "releases/<%= release_version %>/runtime_config.exs"}
]
end

Expand Down
28 changes: 0 additions & 28 deletions rel/dev_runtime_config.exs

This file was deleted.

14 changes: 0 additions & 14 deletions rel/main_runtime_config.exs

This file was deleted.

18 changes: 18 additions & 0 deletions rel/pre_configure/clone-node-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#/usr/bin/env bash

rpc='\
System.get_env() \
|> Enum.filter(&String.starts_with?(elem(&1,0), "UNIRIS_")) \
|> Enum.map(&("#{elem(&1,0)}=#{elem(&1,1)}")) \
|> Enum.join(";")'

if output="$(release_remote_ctl rpc "$rpc")"
then
# split by ; cutting quotation and newline
IFS=";" read -a my_array <<< "${output:1:${#output}-2}"
for var in "${my_array[@]}"
do
info "Clone $var"
export "$var"
done
fi
Loading

0 comments on commit 52cc44c

Please sign in to comment.