Skip to content

Instantly share code, notes, and snippets.

@ervinb
Last active July 24, 2018 11:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ervinb/f93274b56ae7eab198224cba5a1fe7eb to your computer and use it in GitHub Desktop.
Save ervinb/f93274b56ae7eab198224cba5a1fe7eb to your computer and use it in GitHub Desktop.
#----------------------------------------------
## add this snippet to ./config/application.rb
#----------------------------------------------
if ENV["SEMAPHORE_CACHE_DIR"]
config.assets.configure do |env|
env.cache = ActiveSupport::Cache::FileStore.new("#{ENV["SEMAPHORE_CACHE_DIR"]}/assets-cache")
end
end
#---------------------------------------
## add to the setup
## bash ./scripts/restore-asset-cache.sh
#---------------------------------------
#!/usr/bin/env bash
set -eo pipefail
assets_cache_archive="$SEMAPHORE_CACHE_DIR/assets-cache.tar.gz"
if [ -e $assets_cache_archive ]; then
echo "Restoring assets cache..."
tar -xf $assets_cache_archive -C $SEMAPHORE_CACHE_DIR
echo "Assets cache restored."
fi
#--------------------------------
## put in an after job
## bash ./scripts/cache-assets.sh
#--------------------------------
#!/usr/bin/env bash
assets_dir="assets-cache"
assets_path="$SEMAPHORE_CACHE_DIR/$assets_dir"
assets_archive="$SEMAPHORE_CACHE_DIR/${assets_dir}.tar.gz"
if [ -d $assets_path ]; then
echo "Removing old archive..."
rm -f $assets_archive
echo "Creating new archive ..."
tar -czf $assets_archive -C $SEMAPHORE_CACHE_DIR $assets_dir
echo "Removing uncompressed assets..."
rm -rf $assets_path
echo "Done."
else
echo "No asset cache found. Skipping compressing."
fi
@jmgarnier
Copy link

There is a typo in the application.rb change:

if ENV["SEMAPHORE_CACHE_DIR"]
  config.assets.configure do |env|
    env.cache = ActiveSupport::Cache::FileStore.new("#{ENV["SEMAPHORE_CACHE_DIR"]}/assets-cache")
  end # WAS MISSING
end

@ervinb
Copy link
Author

ervinb commented Jun 20, 2018

Fixed. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment