在项目中想利用bitbucket pipeline的cache机制节省build时间
项目采用poetry 安装 python 依赖库, 在pipeline上每次执行安装耗时非常长。
尝试用pipeline caches来引入poetry cache:
definitions:
caches:
sonar: ~/.sonar/cache
poetry: ~/.poetry/cache
services:
docker:
memory: 2048
steps:
- step: &code-style
name: "Code Style"
script:
- pycodestyle --config .pycodestyle **/**.py
- step: &sonar-scan
image: atlassian/default-image:2
name: "Sonar Scan and Quality Gate"
size: 2x
caches:
- docker
script:
- pipe: sonarsource/sonarcloud-scan:1.1.0
- pipe: sonarsource/sonarcloud-quality-gate:0.1.3
services:
- docker
pipelines:
custom:
regression-test:
- variables:
- name: AS_RPT_CUSTOMER
- name: AS_RPT_MARKET
- name: AS_RPT_DB_SCHEMA
- name: AS_RPT_OPTIONS
- step:
name: "Test"
size: 2x
caches:
- docker
- poetry
services:
- docker
artifacts:
- test-reports/*.html
script:
- poetry install --no-root
- pytest --market $AS_RPT_MARKET --schema $AS_RPT_DB_SCHEMA $AS_RPT_OPTIONS
--html="test-reports/$AS_RPT_CUSTOMER-$BITBUCKET_BUILD_NUMBER.html"
--html-title="$AS_RPT_CUSTOMER $AS_RPT_MARKET $AS_RPT_DB_SCHEMA Regression Test" $AS_RPT_CUSTOMER
after-script:
- pipe: atlassian/bitbucket-upload-file:0.1.8
variables:
BITBUCKET_USERNAME: $BITBUCKET_USER
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
FILENAME: "test-reports/$AS_RPT_CUSTOMER-$BITBUCKET_BUILD_NUMBER.html"
然并卵, poetry 安装依赖会从lock.file解析,并不会直接用到cache....
参考: https://python-poetry.org/docs/basic-usage/#initialising-a-pre-existing-project