I was using cimg/python:3.9 but it updated the hotfix version, and now my cache is all messed up. I’d like to include python version as the cache key but I’m not finding an easy way to do this. Only option I have is to export an env var with the python version in a separate step and then then use that in the key. Is there a better way?
Hey. Not really. I think this is a good idea though and I created a GitHub Issue to track it: https://github.com/CircleCI-Public/cimg-shared/issues/38
For now, my suggestion would be to use
python --version to output the version to a text file. Then use the
checksum feature of CircleCI cache and checkson the version file. This way, whenever the version changes, the checksum changes thus the cache busts.
Lastly, the image tag you are using a designed to change as you left out the patch version. So instead, I would suggest using a full SemVer tag such as
cimg/python:3.9.0 or maybe
cimg/python:3.9.3. These won’t change Python versions on you.