Skip to content

Commit a56a9c4

Browse files
committed
chore(ci): add scripts/start.sh to repo and set executable bit for Docker build
1 parent 92ced3d commit a56a9c4

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

scripts/start.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "🚀 Starting Syncio..."
5+
echo "INSTANCE=${INSTANCE:-unknown}"
6+
7+
# Set configuration based on INSTANCE
8+
case "$INSTANCE" in
9+
'private')
10+
export AUTH_ENABLED="false"
11+
export NEXT_PUBLIC_AUTH_ENABLED="false"
12+
export DATABASE_URL="file:/app/data/sqlite.db"
13+
export SCHEMA="/app/prisma/schema.sqlite.prisma"
14+
;;
15+
'public')
16+
export AUTH_ENABLED="true"
17+
export NEXT_PUBLIC_AUTH_ENABLED="true"
18+
export SCHEMA="/app/prisma/schema.postgres.prisma"
19+
# DATABASE_URL should be set by compose file
20+
;;
21+
*)
22+
echo "❌ Unknown INSTANCE: $INSTANCE. Must be 'private' or 'public'"
23+
exit 1
24+
;;
25+
esac
26+
27+
export PRISMA_SCHEMA_PATH="$SCHEMA"
28+
echo "Using Prisma schema: $PRISMA_SCHEMA_PATH"
29+
echo "AUTH_ENABLED=${AUTH_ENABLED} DATABASE_URL=${DATABASE_URL}"
30+
31+
# Ensure SQLite dir exists if using file: URL
32+
if echo "$DATABASE_URL" | grep -q '^file:'; then
33+
DB_FILE=${DATABASE_URL#file:}
34+
DB_DIR=$(dirname "$DB_FILE")
35+
mkdir -p "$DB_DIR" || true
36+
# Try to set permissions, but don't fail if not possible
37+
chmod 755 "$DB_DIR" 2>/dev/null || true
38+
# Ensure the directory is writable by the current user
39+
touch "$DB_DIR/.test" 2>/dev/null && rm -f "$DB_DIR/.test" || {
40+
echo "⚠️ Warning: Cannot write to $DB_DIR, database may not work properly"
41+
}
42+
fi
43+
44+
echo "📊 Generating Prisma client..."
45+
npx prisma generate --schema "$PRISMA_SCHEMA_PATH"
46+
47+
echo "📊 Applying Prisma migrations..."
48+
npx prisma migrate deploy --schema "$PRISMA_SCHEMA_PATH" || true
49+
echo "ℹ️ Ensuring schema is applied (db push)..."
50+
npx prisma db push --schema "$PRISMA_SCHEMA_PATH" --accept-data-loss || true
51+
52+
export NODE_OPTIONS="--dns-result-order=ipv4first"
53+
54+
echo "🌐 Starting frontend server on port ${FRONTEND_PORT:-3000}..."
55+
cd /app/client && PORT=${FRONTEND_PORT:-3000} npm start &
56+
FRONTEND_PID=$!
57+
58+
sleep 2
59+
60+
echo "🔧 Starting backend server on port ${BACKEND_PORT:-4000}..."
61+
cd /app && PORT=${BACKEND_PORT:-4000} AUTH_ENABLED=${AUTH_ENABLED} DATABASE_URL=${DATABASE_URL} node server/database-backend.js &
62+
BACKEND_PID=$!
63+
64+
cleanup() {
65+
echo "🛑 Shutting down services..."
66+
kill $BACKEND_PID 2>/dev/null || true
67+
kill $FRONTEND_PID 2>/dev/null || true
68+
wait
69+
exit 0
70+
}
71+
72+
trap cleanup SIGTERM SIGINT
73+
74+
wait $BACKEND_PID $FRONTEND_PID
75+
76+

0 commit comments

Comments
 (0)