Skip to content

Commit 5702ef8

Browse files
Update local changes for 1.28.0 branch overwrite
1 parent 6849e0e commit 5702ef8

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ RUN mkdir /etc/nginx/sites-enabled && \
141141

142142
COPY ./config.env /usr/local/bin/config.env
143143
COPY --chmod=755 ./docker_entrypoint.sh /usr/local/bin/
144+
COPY --chmod=755 ./migrate-db.sh /usr/local/bin/
144145
COPY --chmod=755 ./check-synced.sh /usr/local/bin/
145146
COPY --chmod=755 ./check-api.sh /usr/local/bin/
146147
COPY --chmod=755 ./check-mysql.sh /usr/local/bin/
147148
COPY --chmod=755 ./check-pushtx.sh /usr/local/bin/
148149
COPY --chmod=755 ./check-soroban.sh /usr/local/bin/
149150
COPY --chmod=755 ./functions.sh /usr/local/bin/
150-
COPY --chmod=755 ./samourai-dojo/docker/my-dojo/soroban/restart.sh /usr/local/bin/soroban-restart.sh
151+
COPY --chmod=755 ./samourai-dojo/docker/my-dojo/soroban/restart.sh /usr/local/bin/soroban-restart.sh

docker_entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ EOF
7979
echo
8080

8181
# Run initial SQL scripts
82-
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
83-
8482
for f in /docker-entrypoint-initdb.d/*; do
8583
case "$f" in
8684
*.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
9896
/usr/bin/mysqld_safe --user=mysql --datadir='/var/lib/mysql' &
9997
db_process=$!
10098

99+
# Run database migration to ensure api_keys table exists
100+
echo "[i] Running database migration..."
101+
/usr/local/bin/migrate-db.sh
102+
101103
# Config tor and explorer
102104
echo "[i] Reading Dojo Tor address from config..."
103105
TOR_ADDRESS=$(yq e '.tor-address' /root/start9/config.yaml)

manifest.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,12 @@ health-checks:
7070
inject: true
7171
system: false
7272
io-format: yaml
73-
soroban:
74-
name: Soroban
75-
success-message: Soroban P2P relay service is online and ready
76-
type: docker
77-
image: main
78-
entrypoint: 'check-soroban.sh'
79-
args: []
80-
inject: true
81-
system: false
82-
io-format: yaml
8373
soroban:
8474
name: Soroban
8575
success-message: Soroban is running
8676
type: docker
8777
image: main
88-
entrypoint: "check-soroban.sh"
78+
entrypoint: 'check-soroban.sh'
8979
args: []
9080
inject: true
9181
system: false

migrate-db.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# Database migration script to ensure api_keys table exists
4+
# This script should be run when the database is already initialized but missing the api_keys table
5+
6+
source /usr/local/bin/config.env
7+
8+
MYSQL_DATABASE=${MYSQL_DATABASE:-"samourai-main"}
9+
MYSQL_USER=${MYSQL_USER:-"samourai"}
10+
MYSQL_PASSWORD=${MYSQL_PASSWORD:-"samourai"}
11+
12+
# Determine the database client binary to use (mysql if present, mariadb otherwise)
13+
if command -v mysql &> /dev/null; then
14+
DBCLIENT="mysql"
15+
else
16+
DBCLIENT="mariadb"
17+
fi
18+
19+
echo "[i] Checking if MySQL is running..."
20+
# Wait for MySQL to be ready
21+
for i in {30..0}; do
22+
if echo "SELECT 1" | "$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" &> /dev/null; then
23+
echo "[i] MySQL is ready"
24+
break
25+
fi
26+
echo "[i] MySQL init process in progress..."
27+
sleep 1
28+
done
29+
30+
if [ "$i" = 0 ]; then
31+
echo "[!] MySQL failed to start"
32+
exit 1
33+
fi
34+
35+
echo "[i] Checking if api_keys table exists..."
36+
# Check if api_keys table exists
37+
TABLE_EXISTS=$("$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -e "SHOW TABLES LIKE 'api_keys';" | wc -l)
38+
39+
if [ "$TABLE_EXISTS" -eq 0 ]; then
40+
echo "[i] api_keys table does not exist, creating it..."
41+
42+
# Create the api_keys table
43+
"$DBCLIENT" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" << 'EOF'
44+
--
45+
-- Create table "api_keys"
46+
--
47+
CREATE TABLE IF NOT EXISTS `api_keys` (
48+
`apikeyID` INT AUTO_INCREMENT PRIMARY KEY,
49+
`label` VARCHAR(255) NOT NULL,
50+
`apikey` VARCHAR(255) NOT NULL UNIQUE,
51+
`active` BOOLEAN NOT NULL DEFAULT TRUE,
52+
`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
53+
`expiresAt` TIMESTAMP NOT NULL
54+
);
55+
EOF
56+
57+
if [ $? -eq 0 ]; then
58+
echo "[i] Successfully created api_keys table"
59+
else
60+
echo "[!] Failed to create api_keys table"
61+
exit 1
62+
fi
63+
else
64+
echo "[i] api_keys table already exists"
65+
fi
66+
67+
echo "[i] Database migration completed successfully"

0 commit comments

Comments
 (0)