Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Load Apibara Script Variables from Environment #25

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -113,4 +116,4 @@ volumes:
postgres:
devnet:
apibara:
deployment:
configs:
4 changes: 2 additions & 2 deletions indexer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 5 additions & 1 deletion indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
26 changes: 0 additions & 26 deletions indexer/docker-script.js

This file was deleted.

8 changes: 5 additions & 3 deletions indexer/script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export const config = {
streamUrl: "http://localhost:7171",
streamUrl: Deno.env.get("APIBARA_STREAM_URL"),
startingBlock: 0,
network: "starknet",
finality: "DATA_STATUS_PENDING",
filter: {
events: [
{
fromAddress: Deno.env.get("ART_PEACE_CONTRACT_ADDRESS"),
keys: ["0x2D7B50EBF415606D77C7E7842546FC13F8ACFBFD16F7BCF2BC2D08F54114C23"],
keys: [
"0x2D7B50EBF415606D77C7E7842546FC13F8ACFBFD16F7BCF2BC2D08F54114C23",
],
includeReverted: false,
includeTransaction: false,
includeReceipt: false,
Expand All @@ -16,7 +18,7 @@ export const config = {
},
sinkType: "webhook",
sinkOptions: {
targetUrl: "http://localhost:8080/consumeIndexerMsg"
targetUrl: Deno.env.get("BACKEND_TARGET_URL"),
},
};

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/docker/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/docker/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 7 additions & 2 deletions tests/integration/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down