Skip to content

Instantly share code, notes, and snippets.

@mortenson
Created October 31, 2019 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenson/5ffeb47189ad9c07d21618a127d955cc to your computer and use it in GitHub Desktop.
Save mortenson/5ffeb47189ad9c07d21618a127d955cc to your computer and use it in GitHub Desktop.
An example script that caches Tome Static builds by copying the static directory and database to /tmp between builds. Useful on CI.
#!/bin/bash
# This directory should persist between builds.
CACHE_DIR=/tmp/tome_static
set -e
composer install
mkdir -p "$CACHE_DIR"
# Load the last database backup if available.
if [ -f "$CACHE_DIR/.ht.sqlite" ]; then
echo "Cache database found - running partial import"
# Copy the database.
mkdir -p ./web/sites/default/files
# Cleanup old sqlite tmp files if they exist.
if [ -f "./web/sites/default/files/.ht.sqlite" ]; then
rm ./web/sites/default/files/.ht.sqlite*
fi
cp "$CACHE_DIR/.ht.sqlite" ./web/sites/default/files/.ht.sqlite
# Run a partial import.
./vendor/bin/drush tome:import-partial -y
# Load the last static build if available.
if [ -f "$CACHE_DIR/html" ]; then
echo "Cached static build found"
cp -r "$CACHE_DIR/html" ./html
fi
else
echo "No cached build - running full install"
./vendor/bin/drush tome:install -y
fi
# Run the static build.
./vendor/bin/drush tome:static
# Export database backup.
cp ./web/sites/default/files/.ht.sqlite "$CACHE_DIR/.ht.sqlite"
# Delete old export if it exists.
if [ -f "$CACHE_DIR/html" ]; then
rm -rf "$CACHE_DIR/html"
fi
# Export static build.
cp -r ./html "$CACHE_DIR/html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment