From 5702ef89a5a9895ddedcc496a6adcfaa0ad3cbf7 Mon Sep 17 00:00:00 2001 From: linkinparkrulz Date: Mon, 27 Oct 2025 15:41:32 -0500 Subject: [PATCH 1/3] Update local changes for 1.28.0 branch overwrite --- Dockerfile | 3 +- docker_entrypoint.sh | 6 ++-- manifest.yaml | 12 +------- migrate-db.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 migrate-db.sh diff --git a/Dockerfile b/Dockerfile index fc1ff52..a33fc05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -141,10 +141,11 @@ RUN mkdir /etc/nginx/sites-enabled && \ COPY ./config.env /usr/local/bin/config.env COPY --chmod=755 ./docker_entrypoint.sh /usr/local/bin/ +COPY --chmod=755 ./migrate-db.sh /usr/local/bin/ COPY --chmod=755 ./check-synced.sh /usr/local/bin/ COPY --chmod=755 ./check-api.sh /usr/local/bin/ COPY --chmod=755 ./check-mysql.sh /usr/local/bin/ COPY --chmod=755 ./check-pushtx.sh /usr/local/bin/ COPY --chmod=755 ./check-soroban.sh /usr/local/bin/ COPY --chmod=755 ./functions.sh /usr/local/bin/ -COPY --chmod=755 ./samourai-dojo/docker/my-dojo/soroban/restart.sh /usr/local/bin/soroban-restart.sh \ No newline at end of file +COPY --chmod=755 ./samourai-dojo/docker/my-dojo/soroban/restart.sh /usr/local/bin/soroban-restart.sh diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 3037266..1f0486e 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -79,8 +79,6 @@ EOF echo # Run initial SQL scripts - sed "1iUSE \`$MYSQL_DATABASE\`;" /docker-entrypoint-initdb.d/2_update.sql | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 - for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sql) echo "$0: running $f"; sed "1iUSE \`$MYSQL_DATABASE\`;" "$f" | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0; echo ;; @@ -98,6 +96,10 @@ fi /usr/bin/mysqld_safe --user=mysql --datadir='/var/lib/mysql' & db_process=$! +# Run database migration to ensure api_keys table exists +echo "[i] Running database migration..." +/usr/local/bin/migrate-db.sh + # Config tor and explorer echo "[i] Reading Dojo Tor address from config..." TOR_ADDRESS=$(yq e '.tor-address' /root/start9/config.yaml) diff --git a/manifest.yaml b/manifest.yaml index 1c6cce8..ef5f9a0 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -70,22 +70,12 @@ health-checks: inject: true system: false io-format: yaml - soroban: - name: Soroban - success-message: Soroban P2P relay service is online and ready - type: docker - image: main - entrypoint: 'check-soroban.sh' - args: [] - inject: true - system: false - io-format: yaml soroban: name: Soroban success-message: Soroban is running type: docker image: main - entrypoint: "check-soroban.sh" + entrypoint: 'check-soroban.sh' args: [] inject: true system: false diff --git a/migrate-db.sh b/migrate-db.sh new file mode 100644 index 0000000..f5fb9b5 --- /dev/null +++ b/migrate-db.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Database migration script to ensure api_keys table exists +# This script should be run when the database is already initialized but missing the api_keys table + +source /usr/local/bin/config.env + +MYSQL_DATABASE=${MYSQL_DATABASE:-"samourai-main"} +MYSQL_USER=${MYSQL_USER:-"samourai"} +MYSQL_PASSWORD=${MYSQL_PASSWORD:-"samourai"} + +# Determine the database client binary to use (mysql if present, mariadb otherwise) +if command -v mysql &> /dev/null; then + DBCLIENT="mysql" +else + DBCLIENT="mariadb" +fi + +echo "[i] Checking if MySQL is running..." +# Wait for MySQL to be ready +for i in {30..0}; do + if echo "SELECT 1" | "$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" &> /dev/null; then + echo "[i] MySQL is ready" + break + fi + echo "[i] MySQL init process in progress..." + sleep 1 +done + +if [ "$i" = 0 ]; then + echo "[!] MySQL failed to start" + exit 1 +fi + +echo "[i] Checking if api_keys table exists..." +# Check if api_keys table exists +TABLE_EXISTS=$("$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -e "SHOW TABLES LIKE 'api_keys';" | wc -l) + +if [ "$TABLE_EXISTS" -eq 0 ]; then + echo "[i] api_keys table does not exist, creating it..." + + # Create the api_keys table + "$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" << 'EOF' +-- +-- Create table "api_keys" +-- +CREATE TABLE IF NOT EXISTS `api_keys` ( + `apikeyID` INT AUTO_INCREMENT PRIMARY KEY, + `label` VARCHAR(255) NOT NULL, + `apikey` VARCHAR(255) NOT NULL UNIQUE, + `active` BOOLEAN NOT NULL DEFAULT TRUE, + `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `expiresAt` TIMESTAMP NOT NULL +); +EOF + + if [ $? -eq 0 ]; then + echo "[i] Successfully created api_keys table" + else + echo "[!] Failed to create api_keys table" + exit 1 + fi +else + echo "[i] api_keys table already exists" +fi + +echo "[i] Database migration completed successfully" From 3288d9d3d51237d5563c45b4e58bf872666a310b Mon Sep 17 00:00:00 2001 From: Eric P Date: Mon, 27 Oct 2025 19:27:07 -0500 Subject: [PATCH 2/3] Use existing database migrations which includes api_keys --- Dockerfile | 1 - docker_entrypoint.sh | 23 +++++++-------- migrate-db.sh | 67 -------------------------------------------- 3 files changed, 10 insertions(+), 81 deletions(-) delete mode 100644 migrate-db.sh diff --git a/Dockerfile b/Dockerfile index a33fc05..cfef181 100644 --- a/Dockerfile +++ b/Dockerfile @@ -141,7 +141,6 @@ RUN mkdir /etc/nginx/sites-enabled && \ COPY ./config.env /usr/local/bin/config.env COPY --chmod=755 ./docker_entrypoint.sh /usr/local/bin/ -COPY --chmod=755 ./migrate-db.sh /usr/local/bin/ COPY --chmod=755 ./check-synced.sh /usr/local/bin/ COPY --chmod=755 ./check-api.sh /usr/local/bin/ COPY --chmod=755 ./check-mysql.sh /usr/local/bin/ diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 1f0486e..1468c8b 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -78,28 +78,25 @@ EOF echo 'MySQL init process done. Starting mysqld...' echo - # Run initial SQL scripts - for f in /docker-entrypoint-initdb.d/*; do - case "$f" in - *.sql) echo "$0: running $f"; sed "1iUSE \`$MYSQL_DATABASE\`;" "$f" | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0; echo ;; - *) echo "$0: ignoring or entrypoint initdb empty $f" ;; - esac - echo - done - touch /var/lib/mysql/.dojo_db_initialized else echo "[i] MySQL data directory already initialized, skipping initial DB creation." fi +# Migrate database tables +echo "[i] Running database migration..." +for f in /docker-entrypoint-initdb.d/*; do + case "$f" in + *.sql) echo "$0: running $f"; sed "1iUSE \`$MYSQL_DATABASE\`;" "$f" | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0; echo ;; + *) echo "$0: ignoring or entrypoint initdb empty $f" ;; + esac + echo +done + # Start mysql /usr/bin/mysqld_safe --user=mysql --datadir='/var/lib/mysql' & db_process=$! -# Run database migration to ensure api_keys table exists -echo "[i] Running database migration..." -/usr/local/bin/migrate-db.sh - # Config tor and explorer echo "[i] Reading Dojo Tor address from config..." TOR_ADDRESS=$(yq e '.tor-address' /root/start9/config.yaml) diff --git a/migrate-db.sh b/migrate-db.sh deleted file mode 100644 index f5fb9b5..0000000 --- a/migrate-db.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -# Database migration script to ensure api_keys table exists -# This script should be run when the database is already initialized but missing the api_keys table - -source /usr/local/bin/config.env - -MYSQL_DATABASE=${MYSQL_DATABASE:-"samourai-main"} -MYSQL_USER=${MYSQL_USER:-"samourai"} -MYSQL_PASSWORD=${MYSQL_PASSWORD:-"samourai"} - -# Determine the database client binary to use (mysql if present, mariadb otherwise) -if command -v mysql &> /dev/null; then - DBCLIENT="mysql" -else - DBCLIENT="mariadb" -fi - -echo "[i] Checking if MySQL is running..." -# Wait for MySQL to be ready -for i in {30..0}; do - if echo "SELECT 1" | "$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" &> /dev/null; then - echo "[i] MySQL is ready" - break - fi - echo "[i] MySQL init process in progress..." - sleep 1 -done - -if [ "$i" = 0 ]; then - echo "[!] MySQL failed to start" - exit 1 -fi - -echo "[i] Checking if api_keys table exists..." -# Check if api_keys table exists -TABLE_EXISTS=$("$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -e "SHOW TABLES LIKE 'api_keys';" | wc -l) - -if [ "$TABLE_EXISTS" -eq 0 ]; then - echo "[i] api_keys table does not exist, creating it..." - - # Create the api_keys table - "$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" << 'EOF' --- --- Create table "api_keys" --- -CREATE TABLE IF NOT EXISTS `api_keys` ( - `apikeyID` INT AUTO_INCREMENT PRIMARY KEY, - `label` VARCHAR(255) NOT NULL, - `apikey` VARCHAR(255) NOT NULL UNIQUE, - `active` BOOLEAN NOT NULL DEFAULT TRUE, - `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `expiresAt` TIMESTAMP NOT NULL -); -EOF - - if [ $? -eq 0 ]; then - echo "[i] Successfully created api_keys table" - else - echo "[!] Failed to create api_keys table" - exit 1 - fi -else - echo "[i] api_keys table already exists" -fi - -echo "[i] Database migration completed successfully" From 37a59b451d5e954488cb5ee8d92f7645395a9d29 Mon Sep 17 00:00:00 2001 From: Eric P Date: Mon, 27 Oct 2025 20:32:27 -0500 Subject: [PATCH 3/3] Remove .dojo_db_initialized check since it overwrites old MySQL databases --- docker_entrypoint.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 1468c8b..f7670f4 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -25,7 +25,7 @@ MYSQL_DATABASE=${MYSQL_DATABASE:-"samourai-main"} MYSQL_USER=${MYSQL_USER:-"samourai"} MYSQL_PASSWORD=${MYSQL_PASSWORD:-"samourai"} -if [ ! -f /var/lib/mysql/.dojo_db_initialized ]; then +if [ ! -d /var/lib/mysql/mysql ]; then echo "[i] MySQL data directory not found or not initialized, creating initial DBs" mkdir -p /var/lib/mysql @@ -77,8 +77,6 @@ EOF echo echo 'MySQL init process done. Starting mysqld...' echo - - touch /var/lib/mysql/.dojo_db_initialized else echo "[i] MySQL data directory already initialized, skipping initial DB creation." fi