Browse Source

docker-compose more configurable

Mokhtar Naamani 3 years ago
parent
commit
e48f1c186c
4 changed files with 67 additions and 44 deletions
  1. 28 7
      .env
  2. 26 24
      docker-compose.yml
  3. 4 0
      query-node/start.sh
  4. 9 13
      start.sh

+ 28 - 7
.env

@@ -9,7 +9,7 @@ INDEXER_DB_NAME=query_node_indexer
 DB_NAME=query_node_processor
 DB_USER=postgres
 DB_PASS=postgres
-DB_HOST=db
+DB_HOST=localhost
 DB_PORT=5432
 DEBUG=index-builder:*
 TYPEORM_LOGGING=error
@@ -19,15 +19,36 @@ TYPEORM_LOGGING=error
 # Note, that if there are already some indexed events, this setting is ignored
 BLOCK_HEIGHT=0
 
-# Websocket RPC endpoint hydra indexer will use.
-INDEXER_WS_PROVIDER_ENDPOINT_URI=ws://joystream-node:9944/
-
 # GraphQL ports (WARTHOG_APP_HOST overrides GRAPHQL_SERVER_PORT)
 # So keep them the safe to avoid confusion, as long as each service is
 # run in a separate container on same host then there is no issue.
 # It does not make sense to have both but hydra codegen demands them.
 GRAPHQL_SERVER_PORT=4001
-GRAPHQL_SERVER_HOST=graphql-server
+GRAPHQL_SERVER_HOST=localhost
+WARTHOG_APP_PORT=${GRAPHQL_SERVER_PORT}
+WARTHOG_APP_HOST=localhost
+
+# Websocket RPC endpoint containers will use.
+JOYSTREAM_NODE_WS=ws://joystream-node:9944/
+
+# Query node which colossus will use
+# TODO: Colossus should take a full Url instead
+COLOSSUS_QUERY_NODE_HOST=graphql-server:${GRAPHQL_SERVER_PORT}
+
+# Query node which distributor will use
+DISTRIBUTOR_QUERY_NODE_URL=http://graphql-server:${GRAPHQL_SERVER_PORT}/graphql
+
+# Indexer gateway used by processor. If you don't use the local indexer set this to a remote gateway
+PROCESSOR_INDEXER_GATEWAY=http://hydra-indexer-gateway:${GRAPHQL_SERVER_PORT}/graphql
+
+# Colossus services identities
+COLOSSUS_1_WORKER_ID=0
+COLOSSUS_1_ACCOUNT_URI=//testing//worker//Storage//${COLOSSUS_1_WORKER_ID}
+COLOSSUS_2_WORKER_ID=1
+COLOSSUS_2_ACCOUNT_URI=//testing//worker//Storage//${COLOSSUS_2_WORKER_ID}
 
-WARTHOG_APP_PORT=4001
-WARTHOG_APP_HOST=hydra-indexer-gateway
+# Distributor node services identities
+DISTRIBUTOR_1_WORKER_ID=0
+DISTRIBUTOR_1_ACCOUNT_URI=//testing//worker//Distribution//${DISTRIBUTOR_1_WORKER_ID}
+DISTRIBUTOR_2_WORKER_ID=1
+DISTRIBUTOR_2_ACCOUNT_URI=//testing//worker//Distribution//${DISTRIBUTOR_2_WORKER_ID}

+ 26 - 24
docker-compose.yml

@@ -36,12 +36,12 @@ services:
       - .env
     environment:
       # ACCOUNT_URI overrides command line arg --accountUri
-      - ACCOUNT_URI=//testing//worker//Storage//0
+      - ACCOUNT_URI=${COLOSSUS_1_ACCOUNT_URI}
     command: [
-      'yarn', 'storage-node', 'server', '--worker=0', '--port=3333', '--uploads=/data',
+      'yarn', 'storage-node', 'server', '--worker=${COLOSSUS_1_WORKER_ID}', '--port=3333', '--uploads=/data',
       '--sync', '--syncInterval=1',
-      '--queryNodeHost=graphql-server:${WARTHOG_APP_PORT}',
-      '--apiUrl=ws://joystream-node:9944/'
+      '--queryNodeHost=${COLOSSUS_QUERY_NODE_HOST}',
+      '--apiUrl=${JOYSTREAM_NODE_WS}'
     ]
 
   distributor-1:
@@ -65,11 +65,11 @@ services:
     # Node configuration can be overriden via env, for exampe:
     environment:
       JOYSTREAM_DISTRIBUTOR__ID: distributor-1
-      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__QUERY_NODE: http://graphql-server:${WARTHOG_APP_PORT}/graphql
-      JOYSTREAM_DISTRIBUTOR__KEYS: "[{\"suri\":\"//testing//workers//Distribution//0\"}]"
-      JOYSTREAM_DISTRIBUTOR__WORKER_ID: 0
+      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__QUERY_NODE: ${DISTRIBUTOR_QUERY_NODE_URL}
+      JOYSTREAM_DISTRIBUTOR__KEYS: "[{\"suri\":\"${DISTRIBUTOR_1_ACCOUNT_URI}\"}]"
+      JOYSTREAM_DISTRIBUTOR__WORKER_ID: ${DISTRIBUTOR_1_WORKER_ID}
       JOYSTREAM_DISTRIBUTOR__PORT: 3334
-      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__JOYSTREAM_NODE_WS: ws://joystream-node:9944/
+      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__JOYSTREAM_NODE_WS: ${JOYSTREAM_NODE_WS}
     #   JOYSTREAM_DISTRIBUTOR__ENDPOINTS__ELASTIC_SEARCH: es-endpoint
     #   JOYSTREAM_DISTRIBUTOR__DIRECTORIES__ASSETS: assets-dir
     #   JOYSTREAM_DISTRIBUTOR__DIRECTORIES__CACHE_STATE: cache-state-dir
@@ -99,12 +99,12 @@ services:
       - .env
     environment:
       # ACCOUNT_URI overrides command line arg --accountUri
-      - ACCOUNT_URI=//testing//worker//Storage//1
+      - ACCOUNT_URI=${COLOSSUS_2_ACCOUNT_URI}
     command: [
-      'yarn', 'storage-node', 'server', '--worker=1', '--port=3333', '--uploads=/data',
+      'yarn', 'storage-node', 'server', '--worker=${COLOSSUS_2_WORKER_ID}', '--port=3333', '--uploads=/data',
       '--sync', '--syncInterval=1',
-      '--queryNodeHost=graphql-server:${WARTHOG_APP_PORT}',
-      '--apiUrl=ws://joystream-node:9944/'
+      '--queryNodeHost=${COLOSSUS_QUERY_NODE_HOST}',
+      '--apiUrl=${JOYSTREAM_NODE_WS}'
     ]
 
   distributor-2:
@@ -128,11 +128,11 @@ services:
     # Node configuration can be overriden via env, for exampe:
     environment:
       JOYSTREAM_DISTRIBUTOR__ID: distributor-2
-      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__QUERY_NODE: http://graphql-server:${WARTHOG_APP_PORT}/graphql
-      JOYSTREAM_DISTRIBUTOR__KEYS: "[{\"suri\":\"//testing//workers//Distribution//1\"}]"
-      JOYSTREAM_DISTRIBUTOR__WORKER_ID: 1
+      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__QUERY_NODE: ${DISTRIBUTOR_QUERY_NODE_URL}
+      JOYSTREAM_DISTRIBUTOR__KEYS: "[{\"suri\":\"${DISTRIBUTOR_2_ACCOUNT_URI}\"}]"
+      JOYSTREAM_DISTRIBUTOR__WORKER_ID: ${DISTRIBUTOR_2_WORKER_ID}
       JOYSTREAM_DISTRIBUTOR__PORT: 3334
-      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__JOYSTREAM_NODE_WS: ws://joystream-node:9944/
+      JOYSTREAM_DISTRIBUTOR__ENDPOINTS__JOYSTREAM_NODE_WS: ${JOYSTREAM_NODE_WS}
     #   JOYSTREAM_DISTRIBUTOR__ENDPOINTS__ELASTIC_SEARCH: es-endpoint
     #   JOYSTREAM_DISTRIBUTOR__DIRECTORIES__ASSETS: assets-dir
     #   JOYSTREAM_DISTRIBUTOR__DIRECTORIES__CACHE_STATE: cache-state-dir
@@ -149,7 +149,7 @@ services:
     container_name: db
     restart: always
     ports:
-      - '127.0.0.1:${DB_PORT}:5432'
+      - '127.0.0.1:${DB_PORT}:${DB_PORT}'
     volumes:
       - /var/lib/postgresql/data
     env_file:
@@ -167,6 +167,8 @@ services:
     env_file:
       # relative to working directory where docker-compose was run from
       - .env
+    environment:
+      - DB_HOST=db
     ports:
       - '127.0.0.1:8081:${WARTHOG_APP_PORT}'
     depends_on:
@@ -186,11 +188,11 @@ services:
       # relative to working directory where docker-compose was run from
       - .env
     environment:
-      - INDEXER_ENDPOINT_URL=http://hydra-indexer-gateway:${WARTHOG_APP_PORT}/graphql
-      - TYPEORM_HOST=${DB_HOST}
+      - INDEXER_ENDPOINT_URL=${PROCESSOR_INDEXER_GATEWAY}
+      - TYPEORM_HOST=db
       - TYPEORM_DATABASE=${DB_NAME}
     depends_on:
-      - hydra-indexer-gateway
+      - db
     volumes:
       - type: bind
         source: .
@@ -210,7 +212,8 @@ services:
       - INDEXER_WORKERS=5
       - REDIS_URI=redis://redis:6379/0
       - TYPES_JSON=types.json
-      - WS_PROVIDER_ENDPOINT_URI=${INDEXER_WS_PROVIDER_ENDPOINT_URI}
+      - WS_PROVIDER_ENDPOINT_URI=${JOYSTREAM_NODE_WS}
+      - DB_HOST=db
     depends_on:
       - db
       - redis
@@ -228,7 +231,7 @@ services:
       - .env
     environment:
       - WARTHOG_STARTER_DB_DATABASE=${INDEXER_DB_NAME}
-      - WARTHOG_STARTER_DB_HOST=${DB_HOST}
+      - WARTHOG_STARTER_DB_HOST=db
       - WARTHOG_STARTER_DB_PASSWORD=${DB_PASS}
       - WARTHOG_STARTER_DB_PORT=${DB_PORT}
       - WARTHOG_STARTER_DB_USERNAME=${DB_USER}
@@ -239,9 +242,8 @@ services:
     ports:
       - '127.0.0.1:4000:${WARTHOG_APP_PORT}'
     depends_on:
-      - redis
       - db
-      - indexer
+      - redis
 
   redis:
     image: redis:6.0-alpine

+ 4 - 0
query-node/start.sh

@@ -30,6 +30,10 @@ yarn workspace query-node-root db:migrate
 # Set DB_HOST back to docker-service one
 export DB_HOST=db
 
+# Start indexer and gateway
+docker-compose up -d indexer
+docker-compose up -d hydra-indexer-gateway
+
 # Start processor and graphql server
 docker-compose up -d processor
 docker-compose up -d graphql-server

+ 9 - 13
start.sh

@@ -5,10 +5,6 @@ set -e
 # Make sure to run build-docker-images.sh prior to running this script to use
 # the local build.
 
-set -a
-. .env
-set +a
-
 # Clean start!
 docker-compose down -v
 
@@ -23,8 +19,8 @@ trap down EXIT
 ## Run a local development chain
 docker-compose up -d joystream-node
 
-WS_PROVIDER_ENDPOINT_URI=ws://localhost:9944 SKIP_MOCK_CONTENT=true \
-  ./tests/network-tests/run-test-scenario.sh setup-new-chain
+## Init the chain with some state
+SKIP_MOCK_CONTENT=true ./tests/network-tests/run-test-scenario.sh setup-new-chain
 
 ## Set sudo as the membership screening authority
 yarn workspace api-scripts set-sudo-as-screening-auth
@@ -34,15 +30,15 @@ yarn workspace api-scripts set-sudo-as-screening-auth
 # Initialize a new database for the query node infrastructure
 docker-compose up -d db
 
-# Override DB_HOST for db setup
 # Make sure we use dev config for db migrations (prevents "Cannot create database..." and some other errors)
-export DB_HOST=localhost
-yarn workspace query-node config:dev
+docker-compose run --rm --entrypoint sh graphql-server -c "yarn workspace query-node config:dev"
 # Migrate the databases
-yarn workspace query-node-root db:prepare
-yarn workspace query-node-root db:migrate
-# Set DB_HOST back to docker-service one
-export DB_HOST=db
+docker-compose run --rm --entrypoint sh graphql-server -c "yarn workspace query-node-root db:prepare"
+docker-compose run --rm --entrypoint sh graphql-server -c "yarn workspace query-node-root db:migrate"
+
+# Start indexer and gateway
+docker-compose up -d indexer
+docker-compose up -d hydra-indexer-gateway
 
 # Start processor and graphql server
 docker-compose up -d processor