Skip to content

Commit

Permalink
litestram - restore and replicate scripts, replicate before new deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dcordz committed Jun 6, 2024
1 parent 80aba6e commit d12b382
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
13 changes: 6 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
!/storage/seeds/data/locales.json
!/storage/seeds/data/united_states/congress
!/storage/seeds/data/united_states/maryland/baltimore
!/storage/geojson/baltimore-maryland-united_states.geojson
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

/public/assets

Expand All @@ -54,10 +49,14 @@ doc/

/app/assets/.well-known
/app/assets/builds/*
!/app/assets/builds/.keep

tf/secrets.tfvars
tf/.terraform*
tf/plans

litestream/config/litestream.yml
litestream/config/*
litestream/dbs/*



!**/**/.keep
Empty file added litestream/config/.keep
Empty file.
Empty file added litestream/dbs/.keep
Empty file.
27 changes: 27 additions & 0 deletions litestream/replicate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env zsh

export GOOGLE_APPLICATION_CREDENTIALS="${HOME}/.config/gcloud/application_default_credentials.json"

echo ""
echo "###################################################################################################"
echo ""
echo "replicate.sh - Replicating the production db to Digial Ocean via Litestream"
echo ""

rm -rf litestream/dbs
mkdir -p litestream/dbs
touch litestream/dbs/.keep

gsutil cp gs://sway-sqlite/production.sqlite3 litestream/dbs/production.sqlite3

litestream replicate -exec "sleep 10" -config litestream/config/replicate.yml

rm -rf litestream/dbs
mkdir -p litestream/dbs
touch litestream/dbs/.keep

echo ""
echo "replicate.sh - Finished replicating the production db to Digial Ocean via Litestream"
echo ""
echo "###################################################################################################"
echo ""
14 changes: 13 additions & 1 deletion litestream/restore.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#!/usr/bin/env zsh

litestream restore -config litestream/config/litestream.yml ./storage/production.db
echo ""
echo "###################################################################################################"
echo ""
echo "restore.sh - Restoring the production db from Digial Ocean via Litestream to storage/production.db"
echo ""

litestream restore -config litestream/config/restore.yml storage/production.db

echo ""
echo "restore.sh - Finished restoring the production db from Digial Ocean via Litestream to stroage/production.db"
echo ""
echo "###################################################################################################"
echo ""
3 changes: 2 additions & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ export $(cat .env.github | xargs)
SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:clobber
RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:clobber

./litestream/replicate.sh

gcloud storage cp --recursive $(pwd)/storage/geojson gs://sway-sqlite/

gcloud storage cp --recursive $(pwd)/storage/seeds/data gs://sway-sqlite/seeds/


# Cloud Run requires AMD64 images
docker buildx build . -f docker/dockerfiles/production.dockerfile --platform linux/amd64 -t us-central1-docker.pkg.dev/sway-421916/sway/sway:latest --push --compress

Expand Down

0 comments on commit d12b382

Please sign in to comment.