From 1e7a804c3effceb6e99b0c3e2bd42a17f1e9d547 Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Wed, 16 Feb 2022 13:24:04 +0300 Subject: [PATCH] Docker-compose configs --- .gitignore | 2 + CHANGELOG.md | 1 + apps/block_scout_web/config/prod.exs | 2 +- apps/explorer/lib/explorer/application.ex | 45 ++++++- .../docker-compose-no-build-ganache.yml | 37 +++++ .../docker-compose-no-build-geth.yml | 37 +++++ ...ocker-compose-no-build-hardhat-network.yml | 37 +++++ ...ocker-compose-no-build-no-db-container.yml | 20 +++ ...pose-no-build-open-ethereum-nethermind.yml | 38 ++++++ docker-compose/docker-compose.yml | 33 +++++ docker-compose/envs/common-blockscout.env | 127 ++++++++++++++++++ docker/Makefile | 10 +- 12 files changed, 380 insertions(+), 9 deletions(-) create mode 100644 docker-compose/docker-compose-no-build-ganache.yml create mode 100644 docker-compose/docker-compose-no-build-geth.yml create mode 100644 docker-compose/docker-compose-no-build-hardhat-network.yml create mode 100644 docker-compose/docker-compose-no-build-no-db-container.yml create mode 100644 docker-compose/docker-compose-no-build-open-ethereum-nethermind.yml create mode 100644 docker-compose/docker-compose.yml create mode 100644 docker-compose/envs/common-blockscout.env diff --git a/.gitignore b/.gitignore index b4d6d0f792..a7de35c4d1 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ screenshots/ # mix phx.gen.cert self-signed certs for dev /apps/block_scout_web/priv/cert + +/docker-compose/postgres-data diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bbf7cd72d..1947c2c52b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#5200](https://github.com/blockscout/blockscout/pull/5200) - Docker-compose configuration - [#5105](https://github.com/blockscout/blockscout/pull/5105) - Redesign token page - [#4690](https://github.com/blockscout/blockscout/pull/4690) - Improve pagination: introduce pagination with random access to pages; Integrate it to the Transactions List page diff --git a/apps/block_scout_web/config/prod.exs b/apps/block_scout_web/config/prod.exs index 2882ea50f6..2277d38ef0 100644 --- a/apps/block_scout_web/config/prod.exs +++ b/apps/block_scout_web/config/prod.exs @@ -17,7 +17,7 @@ config :block_scout_web, BlockScoutWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json", force_ssl: false, secret_key_base: System.get_env("SECRET_KEY_BASE"), - check_origin: System.get_env("CHECK_ORIGIN") || false, + check_origin: System.get_env("CHECK_ORIGIN", "false") == "true" || false, http: [port: System.get_env("PORT")], url: [ scheme: System.get_env("BLOCKSCOUT_PROTOCOL") || "https", diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 7ebab0b72f..a6b7e28e57 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -113,12 +113,51 @@ defmodule Explorer.Application do end end + defp datadog_port do + if System.get_env("DATADOG_PORT") do + case Integer.parse(System.get_env("DATADOG_PORT")) do + {integer, ""} -> integer + _ -> 8126 + end + else + 8126 + end + end + + defp spandex_batch_size do + if System.get_env("SPANDEX_BATCH_SIZE") do + case Integer.parse(System.get_env("SPANDEX_BATCH_SIZE")) do + {integer, ""} -> integer + _ -> 100 + end + else + 100 + end + end + + defp spandex_sync_threshold do + if System.get_env("SPANDEX_SYNC_THRESHOLD") do + case Integer.parse(System.get_env("SPANDEX_SYNC_THRESHOLD")) do + {integer, ""} -> integer + _ -> 100 + end + else + 100 + end + end + defp datadog_opts do + datadog_port = datadog_port() + + spandex_batch_size = spandex_batch_size() + + spandex_sync_threshold = spandex_sync_threshold() + [ host: System.get_env("DATADOG_HOST") || "localhost", - port: System.get_env("DATADOG_PORT") || 8126, - batch_size: System.get_env("SPANDEX_BATCH_SIZE") || 100, - sync_threshold: System.get_env("SPANDEX_SYNC_THRESHOLD") || 100, + port: datadog_port, + batch_size: spandex_batch_size, + sync_threshold: spandex_sync_threshold, http: HTTPoison ] end diff --git a/docker-compose/docker-compose-no-build-ganache.yml b/docker-compose/docker-compose-no-build-ganache.yml new file mode 100644 index 0000000000..0f080ef2a1 --- /dev/null +++ b/docker-compose/docker-compose-no-build-ganache.yml @@ -0,0 +1,37 @@ +version: '3.8' + +services: + db: + image: postgres:13.6 + restart: always + container_name: 'postgres' + environment: + POSTGRES_PASSWORD: '' + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 7432:5432 + + blockscout: + depends_on: + - postgres + image: blockscout/blockscout:${DOCKER_TAG:-latest} + restart: always + container_name: 'blockscout' + links: + - db:database + command: 'mix do ecto.create, ecto.migrate, phx.server' + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./envs/common-blockscout.env + environment: + ETHEREUM_JSONRPC_VARIANT: 'ganache' + ETHEREUM_JSONRPC_HTTP_URL: http://host.docker.internal:8545/ + ETHEREUM_JSONRPC_WS_URL: ws://host.docker.internal:8545/ + INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER: true + DATABASE_URL: postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false + ECTO_USE_SSL: false + ports: + - 4000:4000 + diff --git a/docker-compose/docker-compose-no-build-geth.yml b/docker-compose/docker-compose-no-build-geth.yml new file mode 100644 index 0000000000..e16a3c5b6e --- /dev/null +++ b/docker-compose/docker-compose-no-build-geth.yml @@ -0,0 +1,37 @@ +version: '3.8' + +services: + db: + image: postgres:13.6 + restart: always + container_name: 'postgres' + environment: + POSTGRES_PASSWORD: '' + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + volumes: + - ./postgres-data:/var/lib/postgresql/data + ports: + - 7432:5432 + + blockscout: + depends_on: + - postgres + image: blockscout/blockscout:${DOCKER_TAG:-latest} + restart: always + container_name: 'blockscout' + links: + - db:database + command: 'mix do ecto.create, ecto.migrate, phx.server' + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./envs/common-blockscout.env + environment: + ETHEREUM_JSONRPC_VARIANT: 'geth' + ETHEREUM_JSONRPC_HTTP_URL: http://host.docker.internal:8545/ + DATABASE_URL: postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false + ECTO_USE_SSL: false + ports: + - 4000:4000 + diff --git a/docker-compose/docker-compose-no-build-hardhat-network.yml b/docker-compose/docker-compose-no-build-hardhat-network.yml new file mode 100644 index 0000000000..6fefe35657 --- /dev/null +++ b/docker-compose/docker-compose-no-build-hardhat-network.yml @@ -0,0 +1,37 @@ +version: '3.8' + +services: + db: + image: postgres:13.6 + restart: always + container_name: 'postgres' + environment: + POSTGRES_PASSWORD: '' + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 7432:5432 + + blockscout: + depends_on: + - postgres + image: blockscout/blockscout:${DOCKER_TAG:-latest} + restart: always + container_name: 'blockscout' + links: + - db:database + command: 'mix do ecto.create, ecto.migrate, phx.server' + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./envs/common-blockscout.env + environment: + ETHEREUM_JSONRPC_VARIANT: 'geth' + ETHEREUM_JSONRPC_HTTP_URL: http://host.docker.internal:8545/ + ETHEREUM_JSONRPC_WS_URL: ws://host.docker.internal:8545/ + INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER: true + DATABASE_URL: postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false + ECTO_USE_SSL: false + ports: + - 4000:4000 + diff --git a/docker-compose/docker-compose-no-build-no-db-container.yml b/docker-compose/docker-compose-no-build-no-db-container.yml new file mode 100644 index 0000000000..df11860b84 --- /dev/null +++ b/docker-compose/docker-compose-no-build-no-db-container.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + blockscout: + image: blockscout/blockscout:${DOCKER_TAG:-latest} + restart: always + container_name: 'blockscout' + command: 'mix do ecto.create, ecto.migrate, phx.server' + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./envs/common-blockscout.env + environment: + ETHEREUM_JSONRPC_VARIANT: 'geth' + ETHEREUM_JSONRPC_HTTP_URL: http://host.docker.internal:8545/ + DATABASE_URL: postgresql://postgres:@host.docker.internal:5432/blockscout?ssl=false + ECTO_USE_SSL: false + ports: + - 4000:4000 + diff --git a/docker-compose/docker-compose-no-build-open-ethereum-nethermind.yml b/docker-compose/docker-compose-no-build-open-ethereum-nethermind.yml new file mode 100644 index 0000000000..c6f3b551a6 --- /dev/null +++ b/docker-compose/docker-compose-no-build-open-ethereum-nethermind.yml @@ -0,0 +1,38 @@ +version: '3.8' + +services: + db: + image: postgres:13.6 + restart: always + container_name: 'postgres' + environment: + POSTGRES_PASSWORD: '' + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + volumes: + - ./postgres-data:/var/lib/postgresql/data + ports: + - 7432:5432 + + blockscout: + depends_on: + - postgres + image: blockscout/blockscout:${DOCKER_TAG:-latest} + restart: always + container_name: 'blockscout' + links: + - db:database + command: 'mix do ecto.create, ecto.migrate, phx.server' + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./envs/common-blockscout.env + environment: + ETHEREUM_JSONRPC_VARIANT: 'parity' + ETHEREUM_JSONRPC_HTTP_URL: http://host.docker.internal:8545/ + ETHEREUM_JSONRPC_TRACE_URL: http://host.docker.internal:8545/ + DATABASE_URL: postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false + ECTO_USE_SSL: false + ports: + - 4000:4000 + diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml new file mode 100644 index 0000000000..5f926ab7b6 --- /dev/null +++ b/docker-compose/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.8' + +services: + db: + image: postgres:13.6 + restart: always + container_name: 'postgres' + environment: + POSTGRES_PASSWORD: '' + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 7432:5432 + + blockscout: + depends_on: + - postgres + image: blockscout/blockscout:${DOCKER_TAG:-latest} + build: + context: .. + dockerfile: ./docker/Dockerfile + restart: always + container_name: 'blockscout' + links: + - db:database + command: 'mix do ecto.create, ecto.migrate, phx.server' + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./envs/common-blockscout.env + ports: + - 4000:4000 + diff --git a/docker-compose/envs/common-blockscout.env b/docker-compose/envs/common-blockscout.env new file mode 100644 index 0000000000..b1db041e59 --- /dev/null +++ b/docker-compose/envs/common-blockscout.env @@ -0,0 +1,127 @@ +# DOCKER_TAG= +ETHEREUM_JSONRPC_VARIANT=geth +ETHEREUM_JSONRPC_HTTP_URL=http://host.docker.internal:8545/ +DATABASE_URL=postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false +ETHEREUM_JSONRPC_TRACE_URL=http://host.docker.internal:8545/ +NETWORK= +SUBNETWORK=Awesome chain +LOGO=/images/blockscout_logo.svg +LOGO_FOOTER=/images/blockscout_logo.svg +# ETHEREUM_JSONRPC_WS_URL= +ETHEREUM_JSONRPC_TRANSPORT=http +IPC_PATH= +NETWORK_PATH=/ +API_PATH=/ +SOCKET_ROOT=/ +BLOCKSCOUT_HOST= +BLOCKSCOUT_PROTOCOL= +# SECRET_KEY_BASE= +# CHECK_ORIGIN= +PORT=4000 +# COIN= +# COIN_NAME= +# COINGECKO_COIN_ID= +# METADATA_CONTRACT= +# VALIDATORS_CONTRACT= +# KEYS_MANAGER_CONTRACT= +# REWARDS_CONTRACT= +# TOKEN_BRIDGE_CONTRACT= +EMISSION_FORMAT=DEFAULT +# CHAIN_SPEC_PATH= +# SUPPLY_MODULE= +# SOURCE_MODULE= +POOL_SIZE=40 +POOL_SIZE_API=10 +ECTO_USE_SSL=false +# DATADOG_HOST= +# DATADOG_PORT= +# SPANDEX_BATCH_SIZE= +# SPANDEX_SYNC_THRESHOLD= +HEART_BEAT_TIMEOUT=30 +# HEART_COMMAND= +BLOCKSCOUT_VERSION= +RELEASE_LINK= +BLOCK_TRANSFORMER=base +# GRAPHIQL_TRANSACTION= +# FIRST_BLOCK= +# LAST_BLOCK= +# TRACE_FIRST_BLOCK= +# TRACE_LAST_BLOCK= +LINK_TO_OTHER_EXPLORERS=false +OTHER_EXPLORERS={} +SUPPORTED_CHAINS={} +BLOCK_COUNT_CACHE_PERIOD=7200 +TXS_COUNT_CACHE_PERIOD=7200 +ADDRESS_COUNT_CACHE_PERIOD=7200 +ADDRESS_SUM_CACHE_PERIOD=3600 +TOTAL_GAS_USAGE_CACHE_PERIOD=3600 +ADDRESS_TRANSACTIONS_GAS_USAGE_COUNTER_CACHE_PERIOD=1800 +TOKEN_HOLDERS_COUNTER_CACHE_PERIOD=3600 +TOKEN_TRANSFERS_COUNTER_CACHE_PERIOD=3600 +ADDRESS_WITH_BALANCES_UPDATE_INTERVAL=1800 +TOKEN_METADATA_UPDATE_INTERVAL=172800 +AVERAGE_BLOCK_CACHE_PERIOD=1800 +MARKET_HISTORY_CACHE_PERIOD=21600 +ADDRESS_TRANSACTIONS_CACHE_PERIOD=1800 +ADDRESS_TOKENS_USD_SUM_CACHE_PERIOD=1800 +ADDRESS_TOKEN_TRANSFERS_COUNTER_CACHE_PERIOD=1800 +BRIDGE_MARKET_CAP_UPDATE_INTERVAL=1800 +TOKEN_EXCHANGE_RATE_CACHE_PERIOD=1800 +ALLOWED_EVM_VERSIONS=homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg,istanbul,berlin,london,default +UNCLES_IN_AVERAGE_BLOCK_TIME=false +DISABLE_WEBAPP=false +DISABLE_READ_API=false +DISABLE_WRITE_API=false +DISABLE_INDEXER=false +INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER=false +INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false +# WEBAPP_URL= +# API_URL= +WOBSERVER_ENABLED=false +SHOW_ADDRESS_MARKETCAP_PERCENTAGE=true +CHECKSUM_ADDRESS_HASHES=true +CHECKSUM_FUNCTION=eth +DISABLE_EXCHANGE_RATES=true +DISABLE_KNOWN_TOKENS=false +ENABLE_TXS_STATS=true +SHOW_PRICE_CHART=false +SHOW_TXS_CHART=true +HISTORY_FETCH_INTERVAL=30 +TXS_HISTORIAN_INIT_LAG=0 +TXS_STATS_DAYS_TO_COMPILE_AT_INIT=10 +COIN_BALANCE_HISTORY_DAYS=90 +APPS_MENU=true +EXTERNAL_APPS=[] +# ETH_OMNI_BRIDGE_MEDIATOR= +# BSC_OMNI_BRIDGE_MEDIATOR= +# AMB_BRIDGE_MEDIATORS= +# GAS_PRICE= +# FOREIGN_JSON_RPC= +# RESTRICTED_LIST= +# RESTRICTED_LIST_KEY= +DISABLE_BRIDGE_MARKET_CAP_UPDATER=true +# POS_STAKING_CONTRACT= +ENABLE_POS_STAKING_IN_MENU=false +SHOW_MAINTENANCE_ALERT=false +MAINTENANCE_ALERT_MESSAGE= +SHOW_STAKING_WARNING=false +STAKING_WARNING_MESSAGE= +CUSTOM_CONTRACT_ADDRESSES_TEST_TOKEN= +ENABLE_SOURCIFY_INTEGRATION=false +SOURCIFY_SERVER_URL= +SOURCIFY_REPO_URL= +# CHAIN_ID= +MAX_SIZE_UNLESS_HIDE_ARRAY=50 +HIDE_BLOCK_MINER=false +DISPLAY_TOKEN_ICONS=false +SHOW_TENDERLY_LINK=false +TENDERLY_CHAIN_PATH= +MAX_STRING_LENGTH_WITHOUT_TRIMMING=2040 +RE_CAPTCHA_SECRET_KEY= +RE_CAPTCHA_CLIENT_KEY= +# JSON_RPC= +API_RATE_LIMIT=50 +API_RATE_LIMIT_BY_KEY=50 +API_RATE_LIMIT_BY_IP=50 +API_RATE_LIMIT_WHITELISTED_IPS= +API_RATE_LIMIT_STATIC_API_KEY= diff --git a/docker/Makefile b/docker/Makefile index 591c0877f3..1effa31028 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,9 +1,9 @@ SYSTEM = $(shell uname -s) HOST = host.docker.internal -DOCKER_IMAGE = blockscout_prod +DOCKER_IMAGE = blockscout BS_CONTAINER_NAME = blockscout -PG_CONTAINER_NAME = postgres -PG_CONTAINER_IMAGE = postgres:12.5 +PG_CONTAINER_NAME = db +PG_CONTAINER_IMAGE = postgres:13.6 THIS_FILE = $(lastword $(MAKEFILE_LIST)) ifeq ($(SYSTEM), Linux) @@ -13,7 +13,7 @@ endif ifdef DATABASE_URL DB_URL = $(DATABASE_URL) else - DB_URL = postgresql://postgres:@$(HOST):5432/explorer?ssl=false + DB_URL = postgresql://postgres:@$(HOST):5432/blockscout?ssl=false endif BLOCKSCOUT_CONTAINER_PARAMS = -e 'MIX_ENV=prod' \ -e 'DATABASE_URL=$(DB_URL)' @@ -382,7 +382,7 @@ ifdef INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER BLOCKSCOUT_CONTAINER_PARAMS += -e 'INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=$(INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER)' endif -HAS_BLOCKSCOUT_IMAGE := $(shell docker images | grep -sw ${DOCKER_IMAGE}) +HAS_BLOCKSCOUT_IMAGE := $(shell docker images | grep -sw "${DOCKER_IMAGE} ") build: @echo "==> Checking for blockscout image $(DOCKER_IMAGE)" ifdef HAS_BLOCKSCOUT_IMAGE