python deptry触发镜像构建失败
Deptry简介
它本身有一个类似于日志的错误登记,在ignore
字段来配置,如下面配置文件中所示,这篇文章只针对检测“引用但是未安装的包”,具体配置详情可参考:deptry 官网文档
Docker构建镜像,使用deptry检测包是否安装,触发构建过程失败
- 在构建目录创建deptry配置文件: pyproject.toml
[tool.deptry]
ignore_notebooks = false
requirements_files = ["requirements.txt"]
ignore = ["DEP002", "DEP003", "DEP004", "DEP005"]
json_output = "deptry_report.json"
known_first_party = ["app"]
- 在Dockerfile文件中添加如下命令:
RUN pip install deptry
RUN deptry ./app --config pyproject.toml
deptry如果检测到"引用但是未安装的包",则返回1,触发构建过程报错,触发构建失败