Cache Layer according to "Pipfile.lock" or "poetry.lock".
dnp1 opened this issue · 1 comments
Considering that layer contains only the dependencies, we could just cache e avoid redeploy according to "Pipfile.lock", it is possible?
I'm not sure if my case is the same or needs a new ticket.
We're using dockerizePip: true
. Running serverless package
multiple times locally will result in about 19s packaging time. The CI process takes about 5min in total incl deployment, but a large chunk is packaging. I assume this is due to the docker build process, as "docker" is not being executed locally in consequent runs.
Log from CI:
...
Generating requirements.txt from "pyproject.toml"
Parsed requirements.txt from pyproject.toml in /home/runner/work/<proj>/<proj>/.serverless/requirements.txt
Installing requirements from "/home/runner/.cache/serverless-python-requirements/df293b6184a94fbfd982a4f95fea1698fe858cb805f178dd2112d29905e6a12e_x86_64_slspyc/requirements.txt"
Docker Image: sls-py-reqs-custom
Using download cache directory /home/runner/.cache/serverless-python-requirements/downloadCacheslspyc
Running docker run --rm -v /home/runner/.cache/serverless-python-requirements/df293b6184a94fbfd982a4f95fea[16]...
Python executable not found for "runtime": python3.9
...
Config:
pythonRequirements:
slim: true
# If changes do not reflect, use `serverless requirements cleanCache`
# See See https://github.com/serverless/serverless-python-requirements/issues/437
slimPatterns:
- "**/tests/**"
# Removal of boto3 due to Lambda size limitation.
# This should ideally be packaged with the app.
- "**/botocore/**"
- "**/boto3/**"
# Django files we don't need for the API.
- "**/locale/!(en|en_*)/**"
strip: false
dockerizePip: true
dockerFile: ./deploy/Dockerfile-requirements
#dockerImage: public.ecr.aws/sam/build-python3.9
zip: false
# Set to `true` to cleanup cache in case of requirements issues.
invalidateCaches: false
useDownloadCache: true
useStaticCache: true
layer: true
- Is there a current solution to speed up or circumvent the docker build if requirements have not changed?
- Are there ideas about a future solution to reduce the runtime if requirements have not changed?
UPDATE:
After further investigation I found the following line and realised the issue is with the caching in GitHub actions:
Using static cache of requirements found at /Users/me/Library/Caches/serverless-python-requirements/64ee303d22f5bbbd46285b7b97c678c83eee6084133162ae1866640723712dd5_x86_64_slspyc
The correct approach needs to include the hash of the poetry.lock
.
- uses: actions/cache@v3
with:
key: serverless-python-requirements-${{ hashFiles('poetry.lock') }}
path: |
/home/runner/.cache/serverless-python-requirements
Hope this helps someone having the same issue.