-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dbs: | ||
- path: /app/db/deploy.db | ||
replicas: | ||
- type: gcs | ||
bucket: ${LITESTREAM_BUCKET} | ||
path: deploy.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Generate litestream.yml in the app directory where node user has write permission | ||
envsubst < /etc/litestream.yml.template > /app/litestream.yml | ||
|
||
# Remove existing db if exists | ||
if [ -f /app/db/deploy.db ]; then | ||
mv /app/db/deploy.db /app/db/deploy.db.bak | ||
fi | ||
|
||
# Restore database from GCS if exists | ||
litestream restore -if-replica-exists -config /app/litestream.yml /app/db/deploy.db | ||
|
||
if [ -f /app/db/deploy.db ]; then | ||
echo "Successfully restored database from Cloud Storage" | ||
rm -f /app/db/deploy.db.bak | ||
else | ||
echo "No database backup found in Cloud Storage, using original" | ||
mv /app/db/deploy.db.bak /app/db/deploy.db | ||
fi | ||
|
||
# Before starting the app, ensure WAL mode is disabled for Prisma compatibility | ||
sqlite3 /app/db/deploy.db "PRAGMA journal_mode=DELETE;" | ||
|
||
# Start Litestream replication with the app as the subprocess | ||
exec litestream replicate \ | ||
-config /app/litestream.yml \ | ||
-exec "node node_modules/@remix-run/serve/dist/cli.js build/server/index.js" |