Skip to content

Commit

Permalink
add scripts for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-iohk committed Sep 26, 2024
1 parent 9b36b19 commit 38a068a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
36 changes: 36 additions & 0 deletions scripts/get_archive_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# This script is used to download the archive dump from the mina-archive-dumps bucket
# and extract the archive dump to the sql_scripts directory
# The script will download the archive dump for the last 5 days and extract the first available archive dump
# Usage: ./scripts/get_archive_db.sh <MINA_NETWORK>
# Example: ./scripts/get_archive_db.sh mainnet

MINA_NETWORK=${1}
MINA_ARCHIVE_DUMP_URL=${MINA_ARCHIVE_DUMP_URL:=https://storage.googleapis.com/mina-archive-dumps}
DUMP_TIME=0000
SQL_SCRIPT_PATH=$(pwd)/sql_scripts
TAR_FILE_PATH=${SQL_SCRIPT_PATH}/o1labs-archive-dump.tar.gz

mkdir -p ${SQL_SCRIPT_PATH}

MAX_DAYS_LOOKBACK=5
i=0
while [ $i -lt $MAX_DAYS_LOOKBACK ]; do
DATE=$(date -d "$i days ago" +%G-%m-%d)_${DUMP_TIME}
STATUS_CODE=$(curl -s -o /dev/null --head -w "%{http_code}" "${MINA_ARCHIVE_DUMP_URL}/${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz")
if [[ ! $STATUS_CODE =~ 2[0-9]{2} ]]; then
i=$((i + 1))
else
echo "Download ${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz"
curl "${MINA_ARCHIVE_DUMP_URL}/${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz" -o ${TAR_FILE_PATH}
break
fi
done

[[ $STATUS_CODE =~ 2[0-9]{2} ]] || echo "[WARN] Unable to find archive dump for ${MINA_NETWORK}"

tar -xvf ${SQL_SCRIPT_PATH}/o1labs-archive-dump.tar.gz -C ${SQL_SCRIPT_PATH}
rm -f ${TAR_FILE_PATH}

echo "Extracted ${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz to ${SQL_SCRIPT_PATH}/${MINA_NETWORK}-archive-dump-${DATE}.sql"
17 changes: 17 additions & 0 deletions scripts/wait_for_pg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# This script is used to check if PostgreSQL is available
# Usage: ./scripts/pg_ready.sh <PG_HOST> <PG_PORT>
# Example: ./scripts/pg_ready.sh localhost 5432

# Parameters
PG_HOST="${1:-localhost}"
PG_PORT="${2:-5432}"

# Wait for PostgreSQL to become available
until pg_isready -h "$PG_HOST" -p "$PG_PORT"; do
echo "Waiting for PostgreSQL to become available at ${PG_HOST}:${PG_PORT}..."
sleep 1
done

echo "PostgreSQL is available at ${PG_HOST}:${PG_PORT}"

0 comments on commit 38a068a

Please sign in to comment.