Skip to content

Instantly share code, notes, and snippets.

@siliconcow
Created October 7, 2015 17:47
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 siliconcow/d5c991f49b7550360465 to your computer and use it in GitHub Desktop.
Save siliconcow/d5c991f49b7550360465 to your computer and use it in GitHub Desktop.
Dockerfile cache optimization
#!/bin/bash
platform='unknown'
unamestr=`uname`
if [[ "$OSTYPE" == "linux-gnu" ]]; then
touchutil='touch'
dateutil='date'
elif [[ "$OSTYPE" == darwin* ]]; then
brew install coreutils > /dev/null 2>&1
touchutil='gtouch'
dateutil='gdate'
fi
echo "[Git Hook] Running docker cache optimization..."
find . -exec $touchutil -t 201401010000 {} \;
for x in $(git ls-tree --full-tree --name-only -r HEAD);\
do $touchutil -t \
$($dateutil -d "$(git log -1 --format=%ci "${x}")" +%y%m%d%H%M.%S) \
"${x}";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment