@@ -13,6 +13,7 @@ unset DEIS_DEBUG
1313app_dir=/app
1414build_root=/tmp/build
1515cache_root=/tmp/cache
16+ cache_file=/tmp/cache.tgz
1617env_root=/tmp/env
1718buildpack_root=/tmp/buildpacks
1819
@@ -60,6 +61,24 @@ function ensure_indent() {
6061 done
6162}
6263
64+ function cache_fingerprint() {
65+ md5deep -r ${cache_root} | sort | uniq | md5sum
66+ }
67+
68+ # Restore cache when a $CACHE_PATH was supplied
69+ if ! [[ -z " ${CACHE_PATH} " ]]; then
70+ echo_title " Restoring cache..."
71+ restore_cache
72+ if [[ -f ${cache_file} ]]; then
73+ tar -xzf ${cache_file} -C ${cache_root}
74+ echo_normal " Done!"
75+ else
76+ echo_normal " No cache file could be found. If you're deploying for the first time, it'll be created now."
77+ fi
78+
79+ original_cache_fingerprint=$( cache_fingerprint)
80+ fi
81+
6382# # Copy application code over
6483if [ -d " /tmp/app" ]; then
6584 cp -rf /tmp/app/. $app_dir
@@ -191,6 +210,31 @@ if [[ ! -f "$build_root/Procfile" ]]; then
191210 fi
192211fi
193212
213+ # Compress and save cache
214+ if ! [[ -z " ${CACHE_PATH} " ]]; then
215+ echo_title " Checking for changes inside the cache directory..."
216+ # If there's any files in the cache_root folder, we'll create a tar and upload
217+ # it for future use
218+ if [ " $( ls -A ${cache_root} ) " ]; then
219+ # Let's check if the fingerprint changed, if it did, we'll be updating
220+ # the cache
221+ if [[ " $original_cache_fingerprint " != " $( cache_fingerprint) " ]]; then
222+ echo_normal " Files inside cache folder changed, uploading new cache..."
223+
224+ # Create a new cache file and check if it requires to be updated
225+ tar -z -C ${cache_root} -cf ${cache_file} .
226+ cache_size=$( du -Sh " $cache_file " | cut -f1)
227+
228+ store_cache
229+ echo_normal " Done: Uploaded cache (${cache_size} )"
230+ else
231+ echo_normal " Cache unchanged, not updating"
232+ fi
233+ else
234+ echo_normal " No files were added to the cache folder, cache wasn't updated"
235+ fi
236+ fi
237+
194238if [[ " $slug_file " != " -" ]]; then
195239 slug_size=$( du -Sh " $slug_file " | cut -f1)
196240 echo_title " Compiled slug size is $slug_size "
0 commit comments