From 1a1d9eedd1673ce125d7df0b65056f9a35ee7b44 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Mon, 15 Apr 2024 21:07:45 -0500 Subject: [PATCH] Environment setup to use a single script.js file for indexing --- README.md | 1 + docker-compose.yml | 11 +++++++---- indexer/Dockerfile | 4 ++-- indexer/README.md | 6 +++++- indexer/docker-compose.yml | 3 --- indexer/{docker-script.js => script.js} | 2 +- tests/integration/docker/deploy.sh | 4 ++-- tests/integration/docker/initialize.sh | 2 +- tests/integration/local/run.sh | 9 +++++++-- 9 files changed, 26 insertions(+), 16 deletions(-) rename indexer/{docker-script.js => script.js} (92%) diff --git a/README.md b/README.md index 3f05f367..5a45f84f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ docker compose build ```bash # Must install all the dependencies first +# Use npm install inside the `frontend` directory # Change the user on `configs/database.config.json` for postgres make integration-test-local ``` diff --git a/docker-compose.yml b/docker-compose.yml index 78ebcc0e..25796567 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,7 +54,7 @@ services: environment: - SCARB=/root/.local/bin/scarb volumes: - - deployment:/deployment + - configs:/configs apibara: image: quay.io/apibara/starknet:1.5.0 command: @@ -86,8 +86,11 @@ services: links: - backend - apibara + environment: + - APIBARA_STREAM_URL=http://art-peace-apibara-1:7171 + - BACKEND_TARGET_URL=http://art-peace-backend-1:8080/consumeIndexerMsg volumes: - - deployment:/deployment + - configs:/configs restart: on-failure frontend: build: @@ -102,7 +105,7 @@ services: - backend - devnet volumes: - - deployment:/deployment + - configs:/configs - ./frontend/package.json:/app/package.json - ./frontend/package-lock.json:/app/package-lock.json - ./frontend/public/:/app/public @@ -113,4 +116,4 @@ volumes: postgres: devnet: apibara: - deployment: + configs: diff --git a/indexer/Dockerfile b/indexer/Dockerfile index 993bcb38..69dad95e 100644 --- a/indexer/Dockerfile +++ b/indexer/Dockerfile @@ -1,6 +1,6 @@ FROM quay.io/apibara/sink-webhook:0.6.0 as sink-webhook WORKDIR /indexer -COPY ./indexer/docker-script.js . +COPY ./indexer/script.js . -CMD ["run", "docker-script.js", "--allow-env", "/deployment/.env"] +CMD ["run", "script.js", "--allow-env", "/configs/configs.env", "--allow-env-from-env", "BACKEND_TARGET_URL,APIBARA_STREAM_URL"] diff --git a/indexer/README.md b/indexer/README.md index 9380a3d1..ebfff6f2 100644 --- a/indexer/README.md +++ b/indexer/README.md @@ -6,5 +6,9 @@ This directory contains the Apibara indexer setup for `art/peace`, which indexes ``` # Setup Indexer/DNA w/ docker compose or other options -apibara run scripts.js +# Create an indexer.env file with the following : +# ART_PEACE_CONTRACT_ADDRESS=... # Example: 0x78223f7ab13216727ed426380079c169578cafad83a3178c7b33ba7ca307713 +# APIBARA_STREAM_URL=... # Example: http://localhost:7171 +# BACKEND_TARGET_URL=... # Example: http://localhost:8080/consumeIndexerMsg +apibara run scripts.js --allow-env indexer.env ``` diff --git a/indexer/docker-compose.yml b/indexer/docker-compose.yml index 5a6f94d4..1d7018fb 100644 --- a/indexer/docker-compose.yml +++ b/indexer/docker-compose.yml @@ -23,9 +23,6 @@ services: - --address=0.0.0.0:7171 environment: - XDG_DATA_HOME=/data - - APIBARA_STREAM_URL=http://art-peace-apibara-1:7171 - - TARGET_URL=http://art-peace-backend-1:8080/consumeIndexerMsg - volumes: - dna:/data ports: diff --git a/indexer/docker-script.js b/indexer/script.js similarity index 92% rename from indexer/docker-script.js rename to indexer/script.js index 1012c938..0390248a 100644 --- a/indexer/docker-script.js +++ b/indexer/script.js @@ -18,7 +18,7 @@ export const config = { }, sinkType: "webhook", sinkOptions: { - targetUrl: Deno.env.get("TARGET_URL"), + targetUrl: Deno.env.get("BACKEND_TARGET_URL"), }, }; diff --git a/tests/integration/docker/deploy.sh b/tests/integration/docker/deploy.sh index ada9913b..16b07b55 100755 --- a/tests/integration/docker/deploy.sh +++ b/tests/integration/docker/deploy.sh @@ -58,8 +58,8 @@ CONTRACT_ADDRESS=$(echo $CONTRACT_DEPLOY_RESULT | jq -r '.contract_address') echo "Deployed contract \"$CLASS_NAME\" with address $CONTRACT_ADDRESS" # TODO: Remove these lines? -echo "ART_PEACE_CONTRACT_ADDRESS=$CONTRACT_ADDRESS" > /deployment/.env -echo "REACT_APP_ART_PEACE_CONTRACT_ADDRESS=$CONTRACT_ADDRESS" >> /deployment/.env +echo "ART_PEACE_CONTRACT_ADDRESS=$CONTRACT_ADDRESS" > /configs/configs.env +echo "REACT_APP_ART_PEACE_CONTRACT_ADDRESS=$CONTRACT_ADDRESS" >> /configs/configs.env # TODO # MULTICALL_TEMPLATE_DIR=$CONTRACT_DIR/tests/multicalls diff --git a/tests/integration/docker/initialize.sh b/tests/integration/docker/initialize.sh index a12e888c..d21279b2 100755 --- a/tests/integration/docker/initialize.sh +++ b/tests/integration/docker/initialize.sh @@ -9,5 +9,5 @@ echo "Initializing the canvas" curl http://backend:8080/initCanvas -X POST echo "Set the contract address" -CONTRACT_ADDRESS=$(cat /deployment/.env | tail -n 1 | cut -d '=' -f2) +CONTRACT_ADDRESS=$(cat /configs/configs.env | tail -n 1 | cut -d '=' -f2) curl http://backend:8080/setContractAddress -X POST -d "$CONTRACT_ADDRESS" diff --git a/tests/integration/local/run.sh b/tests/integration/local/run.sh index 318fc40f..8e06d47b 100755 --- a/tests/integration/local/run.sh +++ b/tests/integration/local/run.sh @@ -77,7 +77,12 @@ INDEXER_SCRIPT_LOG_FILE=$LOG_DIR/indexer_script.log touch $INDEXER_SCRIPT_LOG_FILE cd $WORK_DIR/indexer #TODO: apibara -> postgres automatically? -ART_PEACE_CONTRACT_ADDRESS=$ART_PEACE_CONTRACT_ADDRESS apibara run script.js --allow-env-from-env ART_PEACE_CONTRACT_ADDRESS 2>&1 > $INDEXER_SCRIPT_LOG_FILE & +rm -f $TMP_DIR/indexer.env +touch $TMP_DIR/indexer.env +echo "ART_PEACE_CONTRACT_ADDRESS=$ART_PEACE_CONTRACT_ADDRESS" >> $TMP_DIR/indexer.env +echo "APIBARA_STREAM_URL=http://localhost:7171" >> $TMP_DIR/indexer.env +echo "BACKEND_TARGET_URL=http://localhost:8080/consumeIndexerMsg" >> $TMP_DIR/indexer.env +apibara run script.js --allow-env $TMP_DIR/indexer.env 2>&1 > $INDEXER_SCRIPT_LOG_FILE & INDEXER_SCRIPT_PID=$! sleep 2 # Wait for indexer script to start; TODO: Check if indexer script is actually running @@ -96,7 +101,7 @@ REACT_CANVAS_CONFIG_FILE=$WORK_DIR/frontend/src/configs/canvas.config.json REACT_BACKEND_CONFIG_FILE=$WORK_DIR/frontend/src/configs/backend.config.json cp $CANVAS_CONFIG_FILE $REACT_CANVAS_CONFIG_FILE #TODO: Use a symlink instead? cp $BACKEND_CONFIG_FILE $REACT_BACKEND_CONFIG_FILE -REACT_APP_ART_PEACE_CONTRACT_ADDRESS=$ART_PEACE_CONTRACT_ADDRESS REACT_APP_CANVAS_CONFIG_FILE=$REACT_CANVAS_CONFIG_FILE REACT_APP_BACKEND_CONFIG_FILE=$REACT_BACKEND_CONFIG_FILE npm start 2>&1 > $FRONTEND_LOG_FILE & +npm start 2>&1 > $FRONTEND_LOG_FILE & FRONTEND_PID=$! sleep 2 # Wait for frontend to start; TODO: Check if frontend is actually running