Skip to content

Instantly share code, notes, and snippets.

@timuckun
Created February 25, 2020 00:45
Show Gist options
  • Save timuckun/b3f57cda0011b452d3c06fb914699091 to your computer and use it in GitHub Desktop.
Save timuckun/b3f57cda0011b452d3c06fb914699091 to your computer and use it in GitHub Desktop.
set -ex
DIRECTORIES_TO_ARCHIVE="vendor/cache vendor/assets tmp/cache/assets public/assets public/packs "
# Fetch tarball archive containing cache and extract it.
# "tmp/assets/cache" and "public/assets".
if wget -q "https://www.googleapis.com/storage/v1/b/${GOOGLE_BUCKET_NAME}/o/${ARCHIVE_FILE_NAME}?alt=media" -O ${ARCHIVE_FILE_NAME} ; then
tar -xzf ${ARCHIVE_FILE_NAME} && rm -f ${ARCHIVE_FILE_NAME}
else
echo "No archive was found in the bucket"
fi
#visually verify the env is set properly
env | grep BUNDLE
# Step 3.
# Install gems from "vendor/cache" and pack up them.
bin/bundle config set deployment 'true'
# --without development test should be set in the dockerfile env vars
bin/bundle install
bin/bundle clean
bin/bundle pack --quiet
# Step 4.
# Precompile assets.
# Note that the "RAILS_ENV" is already defined in Dockerfile
# and will be used implicitly.
DB_ADAPTER=nulldb bin/rake assets:precompile
# Step 5.
# Compress "vendor/cache", "tmp/assets/cache"
# and "public/assets" directories into a tarball archive.
GZIP=-9 tar -zcf ${ARCHIVE_FILE_NAME} ${DIRECTORIES_TO_ARCHIVE}
# Step 6.
# Push the compressed archive containing updated cache to google storage.
wget --no-check-certificate \
--header="Content-type: multipart/form-data boundary=FILEUPLOAD" \
--header="Content-Type: ${OBJECT_CONTENT_TYPE}" \
--post-file ${ARCHIVE_FILE_NAME} \
"https://storage.googleapis.com/upload/storage/v1/b/${GOOGLE_BUCKET_NAME}/o?uploadType=media&name=${ARCHIVE_FILE_NAME}"
# Step 7.
rm -f ${ARCHIVE_FILE_NAME}
# Step 8 Clean up junk before things are added to the docker image.
rm -rf $BUNDLE_PATH/cache/
find $BUNDLE_PATH/ -name "*.c" -delete
find $BUNDLE_PATH/ -name "*.o" -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment