【问题标题】:Should I run pytest in the Dockerfile in CI?我应该在 CI 的 Dockerfile 中运行 pytest 吗?
【发布时间】:2022-08-22 15:48:43
【问题描述】:

我想要一个用于 python 应用程序的 CI 过程,它基本上执行以下操作:

  • 运行 pytest 以检查应用程序是否正常工作
  • 如果 pytest 成功 - 将应用程序打包为 Docker 映像并将其推送到注册表

我怀疑如何做到这一点。一方面,这种方法:

# requirements.txt
numpy
some-other-dependecncy
...

# Dockerfile
RUN pip install -r requirements
COPY application .

CMD [\"python3\", \"application\"]

# CI pipeline

// in python base image 
1. pip install -r  requirements.txt (requirements doesn\'t contain pytest)
2. pip install pytest
3. pytest
// on host
4. docker build
5. docker push

更好,因为我不想在我的最终图像中使用 pytest。缺点是我运行 pip install 两次。

另一种方法是:

# requirements.txt
numpy
...
pytest

# Dockerfile
RUN pip install -r requirements.txt
COPY application .
RUN pytest

CMD [\"python3\", \"application\"]

# CI pipeline
1. docker build
2. docker push

这更节省时间,因为我只运行一次 pip install ,但将我的图像留给 pytest,这是不必要的。

哪个是首选?

    标签: continuous-integration pytest


    【解决方案1】:

    您可以使用带有 pytest 的图像来运行测试,因此您无需安装它。

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 2023-02-12
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      相关资源
      最近更新 更多