Refactor DB config

pull/6125/head
Viktor Baranov 2 years ago
parent f0df0b9189
commit 9fb791ec19
  1. 12
      apps/block_scout_web/config/runtime/test.exs
  2. 12
      apps/ethereum_jsonrpc/config/runtime/test.exs
  3. 11
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/variant.ex
  4. 12
      apps/explorer/config/runtime/test.exs
  5. 13
      apps/explorer/lib/explorer/repo/config_helper.ex
  6. 12
      apps/indexer/config/runtime/test.exs
  7. 38
      config/runtime/dev.exs
  8. 45
      config/runtime/prod.exs
  9. 12
      config/runtime/test.exs
  10. 2
      docker-compose/README.md
  11. 0
      docker-compose/docker-compose-no-build-nethermind.yml

@ -1,5 +1,7 @@
import Config
alias EthereumJSONRPC.Variant
config :explorer, Explorer.ExchangeRates, enabled: false, store: :none
config :explorer, Explorer.KnownTokens, enabled: false, store: :none
@ -13,15 +15,7 @@ config :ueberauth, Ueberauth,
logout_url: "example.com/logout",
logout_return_to_url: "example.com/return"
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
variant = Variant.get()
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test")
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test")

@ -1,14 +1,8 @@
import Config
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
alias EthereumJSONRPC.Variant
variant = Variant.get()
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test")
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test")

@ -94,4 +94,15 @@ defmodule EthereumJSONRPC.Variant do
],
EthereumJSONRPC.json_rpc_named_arguments()
) :: {:ok, [raw_trace_params]} | {:error, reason :: term} | :ignore
def get do
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"nethermind"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
end
end

@ -1,5 +1,7 @@
import Config
alias EthereumJSONRPC.Variant
config :explorer, Explorer.ExchangeRates, enabled: false, store: :ets, fetch_btc_value: true
config :explorer, Explorer.Chain.Cache.BlockNumber, enabled: false
@ -24,15 +26,7 @@ config :explorer, Explorer.Tracer, disabled?: false
config :explorer,
realtime_events_sender: Explorer.Chain.Events.SimpleSender
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
variant = Variant.get()
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test")
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test")

@ -25,6 +25,19 @@ defmodule Explorer.Repo.ConfigHelper do
|> Keyword.merge(extract_parameters(url))
end
def get_db_pool_size(default_pool_size), do: String.to_integer(System.get_env("POOL_SIZE", default_pool_size))
def get_account_db_url, do: System.get_env("ACCOUNT_DATABASE_URL") || System.get_env("DATABASE_URL")
def get_account_db_pool_size(default_pool_size),
do: String.to_integer(System.get_env("ACCOUNT_POOL_SIZE", default_pool_size))
def get_api_db_url, do: System.get_env("DATABASE_READ_ONLY_API_URL") || System.get_env("DATABASE_URL")
def get_api_db_pool_size(default_pool_size), do: String.to_integer(System.get_env("POOL_SIZE_API", default_pool_size))
def ssl_enabled?, do: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true")
defp extract_parameters(empty) when empty == nil or empty == "", do: []
# sobelow_skip ["DOS.StringToAtom"]

@ -1,14 +1,8 @@
import Config
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
alias EthereumJSONRPC.Variant
variant = Variant.get()
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../explorer/config/test")
Code.require_file("#{variant}.exs", "#{__DIR__}/../../../indexer/config/test")

@ -1,5 +1,8 @@
import Config
alias EthereumJSONRPC.Variant
alias Explorer.Repo.ConfigHelper
######################
### BlockScout Web ###
######################
@ -41,15 +44,10 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
database = if System.get_env("DATABASE_URL"), do: nil, else: "explorer_dev"
hostname = if System.get_env("DATABASE_URL"), do: nil, else: "localhost"
database_api_url =
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: System.get_env("DATABASE_READ_ONLY_API_URL"),
else: System.get_env("DATABASE_URL")
pool_size =
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: String.to_integer(System.get_env("POOL_SIZE", "30")),
else: String.to_integer(System.get_env("POOL_SIZE", "40"))
do: ConfigHelper.get_db_pool_size("30"),
else: ConfigHelper.get_db_pool_size("40")
# Configure your database
config :explorer, Explorer.Repo,
@ -61,18 +59,12 @@ config :explorer, Explorer.Repo,
database_api = if System.get_env("DATABASE_READ_ONLY_API_URL"), do: nil, else: database
hostname_api = if System.get_env("DATABASE_READ_ONLY_API_URL"), do: nil, else: hostname
pool_size_api = String.to_integer(System.get_env("POOL_SIZE_API", "10"))
# Configure API database
config :explorer, Explorer.Repo.Replica1,
database: database_api,
hostname: hostname_api,
url: database_api_url,
pool_size: pool_size_api
database_account_url = System.get_env("ACCOUNT_DATABASE_URL") || System.get_env("DATABASE_URL")
pool_size_account = String.to_integer(System.get_env("ACCOUNT_POOL_SIZE", "10"))
url: ConfigHelper.get_api_db_url(),
pool_size: ConfigHelper.get_api_db_pool_size("10")
database_account = if System.get_env("ACCOUNT_DATABASE_URL"), do: nil, else: database
hostname_account = if System.get_env("ACCOUNT_DATABASE_URL"), do: nil, else: hostname
@ -81,18 +73,10 @@ hostname_account = if System.get_env("ACCOUNT_DATABASE_URL"), do: nil, else: hos
config :explorer, Explorer.Repo.Account,
database: database_account,
hostname: hostname_account,
url: database_account_url,
pool_size: pool_size_account
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"ganache"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
url: ConfigHelper.get_account_db_url(),
pool_size: ConfigHelper.get_account_db_pool_size("10")
variant = Variant.get()
Code.require_file("#{variant}.exs", "apps/explorer/config/dev")

@ -1,5 +1,8 @@
import Config
alias EthereumJSONRPC.Variant
alias Explorer.Repo.ConfigHelper
######################
### BlockScout Web ###
######################
@ -24,53 +27,33 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
pool_size =
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: String.to_integer(System.get_env("POOL_SIZE", "50")),
else: String.to_integer(System.get_env("POOL_SIZE", "40"))
do: ConfigHelper.get_db_pool_size("50"),
else: ConfigHelper.get_db_pool_size("40")
# Configures the database
config :explorer, Explorer.Repo,
url: System.get_env("DATABASE_URL"),
pool_size: pool_size,
ssl: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true")
database_api_url =
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: System.get_env("DATABASE_READ_ONLY_API_URL"),
else: System.get_env("DATABASE_URL")
ssl: ConfigHelper.ssl_enabled?()
pool_size_api =
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: String.to_integer(System.get_env("POOL_SIZE_API", "50")),
else: String.to_integer(System.get_env("POOL_SIZE_API", "10"))
do: ConfigHelper.get_api_db_pool_size("50"),
else: ConfigHelper.get_api_db_pool_size("10")
# Configures API the database
config :explorer, Explorer.Repo.Replica1,
url: database_api_url,
url: ConfigHelper.get_api_db_url(),
pool_size: pool_size_api,
ssl: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true")
database_account_url =
if System.get_env("ACCOUNT_DATABASE_URL"),
do: System.get_env("ACCOUNT_DATABASE_URL"),
else: System.get_env("DATABASE_URL")
pool_size_account = String.to_integer(System.get_env("ACCOUNT_POOL_SIZE", "50"))
ssl: ConfigHelper.ssl_enabled?()
# Configures Account database
config :explorer, Explorer.Repo.Account,
url: database_account_url,
pool_size: pool_size_account,
ssl: String.equivalent?(System.get_env("ECTO_USE_SSL") || "true", "true")
url: ConfigHelper.get_account_db_url(),
pool_size: ConfigHelper.get_account_db_pool_size("50"),
ssl: ConfigHelper.ssl_enabled?()
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
variant = Variant.get()
Code.require_file("#{variant}.exs", "apps/explorer/config/prod")

@ -1,5 +1,7 @@
import Config
alias EthereumJSONRPC.Variant
######################
### BlockScout Web ###
######################
@ -12,15 +14,7 @@ import Config
### Explorer ###
################
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"
else
System.get_env("ETHEREUM_JSONRPC_VARIANT")
|> String.split(".")
|> List.last()
|> String.downcase()
end
variant = Variant.get()
Code.require_file("#{variant}.exs", "apps/explorer/config/test")

@ -32,7 +32,7 @@ Also, the repo contains built-in configs for different clients without need to b
- Erigon: `docker-compose -f docker-compose-no-build-erigon.yml up -d`
- Geth: `docker-compose -f docker-compose-no-build-geth.yml up -d`
- Nethermind, OpenEthereum: `docker-compose -f docker-compose-no-build-open-ethereum-nethermind up -d`
- Nethermind, OpenEthereum: `docker-compose -f docker-compose-no-build-nethermind up -d`
- Ganache: `docker-compose -f docker-compose-no-build-ganache.yml up -d`
- HardHat network: `docker-compose -f docker-compose-no-build-hardhat-network.yml up -d`
- Running only explorer without DB: `docker-compose -f docker-compose-no-build-no-db-container.yml up -d`. In this case, one container is created - for the explorer itself. And it assumes that the DB credentials are provided through `DATABASE_URL` environment variable.

Loading…
Cancel
Save