Commit 6fd9b8f3 authored by Hunter Loftis's avatar Hunter Loftis

test and implementation to invalidate cache on runtime signature changes

parent 7a40a987
## Upcoming
- Fix runtime signature cache invalidation
## v77 ## v77
- Skip npm bootstrapping with iojs - Skip npm bootstrapping with iojs
...@@ -15,8 +19,8 @@ ...@@ -15,8 +19,8 @@
## v73 (24/4/2015) ## v73 (24/4/2015)
- Patch for caching to disable cache restoration if node_modules already exists (eg from being git submoduled or checked into git) - Disable cache restoration if node_modules already exists (eg from being git submoduled or checked into git)
## v72 (23/4/2015) ## v72 (23/4/2015)
* Accepts `cacheDirectories` array in package.json to override default `node_modules` caching * Accept `cacheDirectories` array in package.json to override default `node_modules` caching
...@@ -89,13 +89,9 @@ header "Installing binaries" ...@@ -89,13 +89,9 @@ header "Installing binaries"
install_bins | indent install_bins | indent
restore_cache() { restore_cache() {
local cache_status=$(get_cache_status) local cache_status="$(get_cache_status)"
if [ "$cache_status" == "disabled" ]; then if [ "$cache_status" == "valid" ]; then
echo "Skipping (cache disabled)"
elif [ "$cache_status" == "invalidated" ]; then
echo "Skipping (cache invalidated)"
else
local cache_directories=$(get_cache_directories) local cache_directories=$(get_cache_directories)
if [ "$cache_directories" == "" ]; then if [ "$cache_directories" == "" ]; then
echo "Loading 1 from cacheDirectories (default):" echo "Loading 1 from cacheDirectories (default):"
...@@ -104,6 +100,8 @@ restore_cache() { ...@@ -104,6 +100,8 @@ restore_cache() {
echo "Loading $(echo $cache_directories | wc -w | xargs) from cacheDirectories (package.json):" echo "Loading $(echo $cache_directories | wc -w | xargs) from cacheDirectories (package.json):"
restore_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories restore_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories
fi fi
else
echo "Skipping cache ($cache_status)"
fi fi
} }
...@@ -124,6 +122,7 @@ build_dependencies | indent ...@@ -124,6 +122,7 @@ build_dependencies | indent
cache_build() { cache_build() {
local cache_directories=$(get_cache_directories) local cache_directories=$(get_cache_directories)
echo "Clearing previous node cache" echo "Clearing previous node cache"
clear_cache clear_cache
if [ "$cache_directories" == "" ]; then if [ "$cache_directories" == "" ]; then
...@@ -133,6 +132,7 @@ cache_build() { ...@@ -133,6 +132,7 @@ cache_build() {
echo "Saving $(echo $cache_directories | wc -w | xargs) cacheDirectories (package.json):" echo "Saving $(echo $cache_directories | wc -w | xargs) cacheDirectories (package.json):"
save_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories save_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories
fi fi
save_signature
} }
header "Caching build" header "Caching build"
......
...@@ -5,7 +5,7 @@ create_signature() { ...@@ -5,7 +5,7 @@ create_signature() {
} }
save_signature() { save_signature() {
echo "$(get_signature)" > $CACHE_DIR/node/signature echo "$(create_signature)" > $CACHE_DIR/node/signature
} }
load_signature() { load_signature() {
...@@ -16,19 +16,11 @@ load_signature() { ...@@ -16,19 +16,11 @@ load_signature() {
fi fi
} }
signature_changed() {
if ! [ "$(create_signature)" == "$(load_signature)" ]; then
return 1
else
return 0
fi
}
get_cache_status() { get_cache_status() {
if ! ${NODE_MODULES_CACHE:-true}; then if ! ${NODE_MODULES_CACHE:-true}; then
echo "disabled" echo "disabled by config"
elif signature_changed; then elif [ "$(create_signature)" != "$(load_signature)" ]; then
echo "invalidated" echo "new runtime signature"
else else
echo "valid" echo "valid"
fi fi
...@@ -66,6 +58,7 @@ restore_cache_directories() { ...@@ -66,6 +58,7 @@ restore_cache_directories() {
clear_cache() { clear_cache() {
rm -rf $CACHE_DIR/node rm -rf $CACHE_DIR/node
mkdir -p $CACHE_DIR/node
} }
save_cache_directories() { save_cache_directories() {
......
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
},
"engines": {
"node": "0.12.6"
}
}
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
},
"engines": {
"node": "0.12.7"
}
}
#!/usr/bin/env bash #!/usr/bin/env bash
# See README.md for info on running these tests. # See README.md for info on running these tests.
testBuildWithCache() {
cache=$(mktmpdir)
compile "stable-node" $cache
assertCaptured "Skipping cache (new runtime"
assertEquals "1" "$(ls -1 $cache/node | grep node_modules | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "stable-node" $cache
assertNotCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess
rm -rf "$cache/node/node_modules"
compile "stable-node" $cache
assertCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess
}
testSignatureInvalidation() {
cache=$(mktmpdir)
env_dir=$(mktmpdir)
compile "node-0.12.6" $cache
assertCaptured "Downloading and installing node 0.12.6"
assertCapturedSuccess
compile "node-0.12.7" $cache
assertCaptured "Downloading and installing node 0.12.7"
assertCaptured "Skipping cache (new runtime"
assertCapturedSuccess
}
testModulesCheckedIn() { testModulesCheckedIn() {
cache=$(mktmpdir) cache=$(mktmpdir)
compile "modules-checked-in" $cache compile "modules-checked-in" $cache
...@@ -205,19 +237,6 @@ testNodeModulesCached() { ...@@ -205,19 +237,6 @@ testNodeModulesCached() {
assertCapturedSuccess assertCapturedSuccess
} }
testBuildWithCache() {
cache=$(mktmpdir)
compile "stable-node" $cache
assertCaptured "- node_modules (not cached - skipping)"
assertEquals "1" "$(ls -1 $cache/node | grep node_modules | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "stable-node" $cache
assertNotCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess
}
testBuildWithUserCacheDirectories() { testBuildWithUserCacheDirectories() {
cache=$(mktmpdir) cache=$(mktmpdir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment