Skip to content

Instantly share code, notes, and snippets.

@mhart
Created September 28, 2019 18:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhart/181a8334ab217a1d55dc37aa27442095 to your computer and use it in GitHub Desktop.
Save mhart/181a8334ab217a1d55dc37aa27442095 to your computer and use it in GitHub Desktop.
Simple module caching script, for CI or similar
#!/bin/bash -ex
# Tries to download latest cached node_modules based on package-lock.json
# If it can't, then `npm ci` and push up node_modules to cache
# Assumes S3_BUCKET env var has been set, and that `aws` credentials
# are configured (either in env, or ~/.aws/credentials)
CHECKSUM=$(sha256sum package-lock.json | awk '{print $1}')
if ! aws s3 cp s3://${S3_BUCKET}/cache/${CHECKSUM}.tgz - | tar -xz; then
npm ci
tar -cz node_modules | aws s3 cp - s3://${S3_BUCKET}/cache/${CHECKSUM}.tgz
fi
@mhart
Copy link
Author

mhart commented Sep 28, 2019

Swap out aws s3 for gsutil cp on Google Cloud or azcopy on Azure

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