From ea350a66949662641eccdb4fe7a7a2f1a31a36e0 Mon Sep 17 00:00:00 2001 From: Casey Date: Tue, 21 Apr 2020 16:41:57 -0400 Subject: [PATCH] Bugfix: Caching on subsequent redeploys (#948) * Don't clear the cache on first app deploy * Add output for debugging cache behavior * Debug output of changes, clean up whitespace * Update hatchet to use latest getting started guide * Clean up caching output logs This output was confusing and unhelptul to most users * Changelog * Test if we need these lines * dang fi * Remove unnecessary code * Remove confusing output of change * Update log output * Update test to match new expected log output * Update changelog --- CHANGELOG.md | 2 ++ bin/compile | 2 +- bin/steps/python | 13 ++++--------- bin/steps/sqlite3 | 1 - hatchet.lock | 2 +- spec/hatchet/python_spec.rb | 30 ++++++++++++++++++++++-------- test/run-deps | 1 - 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0e35bd..17072eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ # Master +- Bugfix: Caching on subsequent redeploys + -------------------------------------------------------------------------------- # 168 (2020-04-06) diff --git a/bin/compile b/bin/compile index 170026c..89c4051 100755 --- a/bin/compile +++ b/bin/compile @@ -175,7 +175,7 @@ cd "$BUILD_DIR" # - Once the build is complete, `~/.heroku/{known-paths}` is copied back into the cache. # Create the cache directory, if it doesn't exist. -mkdir -p "$CACHE_DIR" +mkdir -p "$CACHE_DIR/.heroku" # Restore old artifacts from the cache. mkdir -p .heroku diff --git a/bin/steps/python b/bin/steps/python index f613c11..068e147 100755 --- a/bin/steps/python +++ b/bin/steps/python @@ -100,22 +100,17 @@ if [[ ! -f "$CACHE_DIR/.heroku/requirements.txt" ]]; then # IF there's no cached dependencies, update cached version of requirements.txt # This should only run for new apps and first deploys after this update cp -R "$BUILD_DIR/requirements.txt" "$CACHE_DIR/.heroku/requirements.txt" - # If we don't already have a python version, this is a new app - if [ -f .heroku/python-version ]; then - puts-step "Clearing cached dependencies" - # if there are any differences, clear the Python cache - # Installing Python over again does not take noticably more time - rm -rf .heroku/python - unset SKIP_INSTALL - fi else # IF there IS a cached directory, check for differences with the new one if ! diff "$BUILD_DIR/requirements.txt" "$CACHE_DIR/.heroku/requirements.txt" &> /dev/null; then - puts-step "Clearing cached dependencies" + puts-step "Requirements file has been changed, clearing cached dependencies" # if there are any differences, clear the Python cache # Installing Python over again does not take noticably more time + cp -R "$BUILD_DIR/requirements.txt" "$CACHE_DIR/.heroku/requirements.txt" rm -rf .heroku/python unset SKIP_INSTALL + else + puts-step "No change in requirements detected, installing from cache" fi fi diff --git a/bin/steps/sqlite3 b/bin/steps/sqlite3 index 2d8dc91..469207f 100755 --- a/bin/steps/sqlite3 +++ b/bin/steps/sqlite3 @@ -67,7 +67,6 @@ buildpack_sqlite3_install() { puts-step "Installing SQLite3" if sqlite3_install "$BUILD_DIR/.heroku/python" ; then - echo "Sqlite3 successfully installed." mcount "success.python.sqlite3" else echo "Sqlite3 failed to install." diff --git a/hatchet.lock b/hatchet.lock index 1e334cb..1dbcd8d 100644 --- a/hatchet.lock +++ b/hatchet.lock @@ -1,3 +1,3 @@ --- - - "./repos/python/python-getting-started" - - f56b90499ec11e1c9576da2f8c7331300e189db3 + - 443a90c58be6881583cd7ef628e3869e3c30bb98 diff --git a/spec/hatchet/python_spec.rb b/spec/hatchet/python_spec.rb index ac6c3e1..24c2d3b 100644 --- a/spec/hatchet/python_spec.rb +++ b/spec/hatchet/python_spec.rb @@ -3,26 +3,40 @@ require_relative '../spec_helper' describe "Default Python Deploy" do it "🐍" do Hatchet::Runner.new('python-getting-started', stack: DEFAULT_STACK).deploy do |app| + + # What should happen on first deploy expect(app.output).to match(/Installing pip/) - expect(app.run('python -V')).to match(/3.6.10/) + # What should not happen + expect(app.output).to_not match("Requirements file has been changed, updating cache") + expect(app.output).to_not match("No change in requirements detected, installing from cache") + expect(app.output).to_not match("No such file or directory") + expect(app.output).to_not match("cp: cannot create regular file") - expect(app.output).to_not match("Clearing cached dependencies") - - # Redeploy + # Redeploy with changed requirements file + run!(%Q{echo "" >> requirements.txt}) run!(%Q{echo "flask" >> requirements.txt}) run!(%Q{git add . ; git commit --allow-empty -m next}) app.push! - # Check for the cache tohave cleared - expect(app.output).to match("Clearing cached dependencies") + # Check for the cache to have cleared + expect(app.output).to match("Requirements file has been changed, updating cache") + + # What should not happen when the requirements file is changed + expect(app.output).to_not match("No dependencies found, preparing to install") + expect(app.output).to_not match("No change in requirements detected, installing from cache") run!(%Q{git commit --allow-empty -m next}) app.push! - # The cache should not clear with no changes - expect(app.output).to_not match("Clearing cached dependencies") + # With no changes on redeploy, the cache should + expect(app.output).to match("No change in requirements detected, installing from cache") + # With no changes on redeploy, the cache should not + expect(app.output).to_not match("Requirements file has been changed, updating cache") + expect(app.output).to_not match("No dependencies found, preparing to install") + + expect(app.run('python -V')).to match(/3.7.3/) end end end diff --git a/test/run-deps b/test/run-deps index f40c304..f65ec9d 100755 --- a/test/run-deps +++ b/test/run-deps @@ -56,7 +56,6 @@ testPysqlite() { testSqliteInstall() { compile "pythonDefault" - assertCaptured "Sqlite3 successfully installed." assertNotCaptured "Sqlite3 failed to install." assertCapturedSuccess }