Cache unnecessarily being cleared due to lack of cached SQLite3 version file
Post #907, we are no longer caching a .heroku/python-sqlite3-version version file and instead always running sqlite3_install "$BUILD_DIR/.heroku/python". The missing version file causes builds now to unnecessarily clear their caches.
Because we no longer cache a .heroku/python-sqlite3-version version file, we are clearing all .heroku caches in https://github.com/heroku/heroku-buildpack-python/blob/v162/bin/steps/python#L72 because
if [ -d .heroku/python ] && [ ! -f .heroku/python-sqlite3-version ] && python_sqlite3_check "$PYTHON_VERSION";
in https://github.com/heroku/heroku-buildpack-python/blob/v162/bin/steps/python#L70 will now always evaluate to true (for builds with caches and for python versions requiring sqlite3, i.e. where python_sqlite3_check is true).
I am actually not sure if the cache clearing logic https://github.com/heroku/heroku-buildpack-python/blob/v162/bin/steps/python#L67-L73 (originally introduced in #713) is still needed. If it isn't, a straightforward fix would be to remove those lines of cache-clearing logic. (Otherwise, we could still maintain a cached .heroku/python-sqlite3-version version file as we did before prior to #907)
Relatedly, the following related few lines from https://github.com/heroku/heroku-buildpack-python/pull/713 now appear to be outdated and can be removed now as well:
- https://github.com/heroku/heroku-buildpack-python/blob/v162/bin/compile#L169-L170
- https://github.com/heroku/heroku-buildpack-python/blob/v162/bin/steps/sqlite3#L62-L65
I wonder if this is the reason why builds were taking 25 mins on heroku CI. I had lxml, pandas, numpy in my requirements.txt and pip installing these was what was taking the bulk of the time. These modules need to compile each time. Our actual test run is only 3-4 mins whereas the test setup runs for ~25 mins. I remember this not being an issue earlier, and i always assumed there was some caching going on, but for the few weeks each test run has been taking really long.
...
Running setup.py install for numpy: started
. Running setup.py install for numpy: still running...
. Running setup.py install for numpy: still running...
. Running setup.py install for numpy: still running...
. Running setup.py install for numpy: still running...
. Running setup.py install for numpy: still running...
Running setup.py install for numpy: finished with status 'done'
Running setup.py install for pandas: started
. Running setup.py install for pandas: still running...
. Running setup.py install for pandas: still running...
.. Running setup.py install for pandas: still running...
.. Running setup.py install for pandas: still running...
. Running setup.py install for pandas: still running...
. Running setup.py install for pandas: still running...
. Running setup.py install for pandas: still running...
. Running setup.py install for pandas: still running...
. Running setup.py install for pandas: still running...
Running setup.py install for pandas: finished with status 'done'
...
Also getting:
Need to update SQLite3, clearing cache
This is slowing down deploys considerably.
Any progress here? Still happening for me.
Still an issue for me as well
Is there a work around that is available?
Is there a work around that is available?
I was able to fork the repo, comment out the offending lines, and add my fork as the Heroku buildpack without issue. I hope to switch back to the main branch once the problem is fixed, but in the meantime it significantly sped up my build times.
Hey y'all - thanks for reporting! This is the next item I'm working through, so hope to get some progress on it for y'all soon.
For anyone that's tried this linked pr (#915) - can you confirm if it worked for you? Command below:
heroku buildpacks:set https://github.com/mz026/heroku-buildpack-python#fix-cache-clearing-due-to-sqlite3
internal links: https://heroku.support/829568
@CaseyFaist We're using the fork of PR #915 as our test buildpack to run the tests and it seems to work fine for that. It was only our heroku CI step that kept re-installing numpy, pandas, lxml and weren't caching this stuff. Our actual deploy/build wasn't affected it seems. So we only updated the test build pack. After this our CI build step time went down by ~20 mins.
"environments": {
"test": {
...
"buildpacks": [
{
"url": "https://github.com/MyFork/heroku-buildpack-python.git"
}
],
},
...
}
The fix from #915 works for me! Great to see caching back after all this time.
Two notes:
-----> Python app detected
! Python has released a security update! Please consider upgrading to python-3.8.1
Learn More: https://devcenter.heroku.com/articles/python-runtimes
I am running with 3.8.2!
-----> SQLite3 has been installed before, skip it.
Why is there special handling for sqlite3? Python makes use of zlib, bzlib, libmpdec, etc, why is sqlite3 singled out in messages and causing this whole problem?
I can confirm that #915 worked for me also. Thank you to those who managed a workaround, this has sped up my deploys to a manageable time.
Okay! See #925 for progress update - fix should be going out sometime this week 🎉 Thank you @mz026 for contributing #915 - I took a slightly different route to address the issue but your work highlighted problem areas and made my job easier on this one.
Fix has been merged and released! Please continue to report if you DON'T see your dependencies installing from cache after one redeploy (we have to get your cache set up, so it'll take 2 redeploys for you to see install from cache going into effect). Will leave this issue open for a bit to get more feedback.
This looks good for me (FTR I’m not using git deployment but builds:create command).
I am not seeing the false positive warning anymore (Python has released a security update! Please consider upgrading to python-3.8.1) :slightly_smiling_face:
I would like to repeat my question:
Why is there special handling for sqlite3? Python makes use of zlib, bzlib, libmpdec, etc, why is sqlite3 singled out in messages and causing this whole problem?
Woah I am new to this. Well, still having the issue that it keeps re-installing the same things from the requirements.txt
It is still not using the cache.
Additionally, we started getting strange output during every deployment.
If the cache is clean (after heroku builds:cache:purge):
remote: -----> Python app detected
remote: cp: cannot create regular file '/app/tmp/cache/.heroku/requirements.txt': No such file or directory
And then during the next deployments with upgraded dependencies:
remote: -----> Python app detected
remote: 5d4
remote: < awscli==1.18.36
remote: 8,9c7,8
remote: < boto3==1.12.36
remote: < botocore==1.15.36
remote: ---
remote: > boto3==1.12.34
remote: > botocore==1.15.34
remote: 13c12
remote: < certifi==2020.4.5
remote: ---
remote: > certifi==2019.11.28
remote: 16,17c15
remote: < colorama==0.4.3
remote: < cryptography==2.9
remote: ---
... and so on ...
For some reason, cache is not working anymore for me:
-----> Python app detected
-----> Clearing cached dependencies
-----> Installing python-3.8.2
-----> Installing pip
-----> Installing SQLite3
Sqlite3 successfully installed.
-----> Installing requirements with pip
Hello I am still facing the same issue, dependencies are always re-install (this issue appears few days ago for the first time).
remote: -----> Python app detected remote: -----> Clearing cached dependencies remote: -----> Installing python-3.8.2 remote: -----> Installing pip remote: -----> Installing dependencies with Pipenv 2018.5.18…
I can confirm this now as well. We deploy multiple times a day, and it always clears cached dependency. But our original issue of building lxml, pandas, numpy each time is definitely gone.
-----> stunnel app detected
-----> Moving the configuration generation script into app/bin
-----> Moving the start-stunnel script into app/bin
-----> stunnel done
-----> Python app detected
-----> Clearing cached dependencies
-----> Installing python-3.7.6
-----> Installing pip
-----> Installing SQLite3
Sqlite3 successfully installed.
-----> Installing requirements with pip
Ignoring colorama: markers 'python_version >= "3.4" and sys_platform == "win32" or platform_system == "Windows" or sys_platform == "win32"' don't match your environment
Collecting aioredis==1.3.1
Downloading aioredis-1.3.1-py3-none-any.whl (65 kB)
Can also confirm; app build seems to be working but CI builds still clears cache.
Cache is cleared on every Heroku push
remote: -----> Build succeeded!
remote: -----> Python app detected
remote: -----> Clearing cached dependencies
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip