使用 GitLab CI 和 Python 'onbuild' 图像,requirements.txt 中的包似乎没有安装
Using GitLab CI with the Python 'onbuild' image, the packages in requirements.txt don't seem to get installed
我正在尝试熟悉 Gitlab CI environment with a test project, https://gitlab.com/khpeek/CI-test。该项目有以下.gitlab-ci.yml
:
image: python:2.7-onbuild
services:
- rethinkdb:latest
test_job:
script:
- pytest
问题是 CI 管道中的 test_job
作业失败并显示以下错误消息:
Running with gitlab-ci-multi-runner 9.0.1 (a3da309)
on docker-auto-scale (e11ae361)
Using Docker executor with image python:2.7-onbuild ...
Starting service rethinkdb:latest ...
Pulling docker image rethinkdb:latest ...
Using docker image rethinkdb:latest ID=sha256:23ecfb08823bc5483c6a955b077a9bc82899a0df2f33899b64992345256f22dd for service rethinkdb...
Waiting for services to be up and running...
Using docker image sha256:aaecf574604a31dd49a9d4151b11739837e4469df1cf7b558787048ce4ba81aa ID=sha256:aaecf574604a31dd49a9d4151b11739837e4469df1cf7b558787048ce4ba81aa for predefined container...
Pulling docker image python:2.7-onbuild ...
Using docker image python:2.7-onbuild ID=sha256:5754a7fac135b9cae7e02e34cc7ba941f03a33fb00cf31f12fbb71b8d389ece2 for build container...
Running on runner-e11ae361-project-3083420-concurrent-0 via runner-e11ae361-machine-1491819341-82630004-digital-ocean-2gb...
Cloning repository...
Cloning into '/builds/khpeek/CI-test'...
Checking out d0937f33 as master...
Skipping Git submodules setup
$ pytest
/bin/bash: line 56: pytest: command not found
ERROR: Job failed: exit code 1
但是,存储库中有一个 requirements.txt
,其中只有一行 pytest==3.0.7
。然而,从 python:2.7-onbuild
图像的 Dockerfile 看来,pip install -r requirements.txt
应该在构建时得到 运行。那么为什么找不到 pytest
?
如果您查看 Dockerfile you linked to, you'll see pip install -r requirements.txt
is part of an onbuild 命令。如果您想从第一个容器创建一个新容器并安装一堆需求,这将很有用。因此,pip install -r requirements.txt
命令不会在您的 CI 管道的容器内执行,如果是,它将在最开始执行,甚至在您的 gitlab 存储库被克隆之前执行。
我建议您以这种方式修改 .gitlab-ci.yml
文件
image: python:2.7-onbuild
services:
- rethinkdb:latest
test_job:
script:
- pip install -r requirements.txt
- pytest
问题似乎是间歇性的:虽然第一次 运行 测试需要 61 分钟(最初失败),但现在大约需要一分钟(见下面的屏幕截图)。
作为参考,测试存储库位于 https://gitlab.com/khpeek/CI-test。 (我必须添加一个 before_script
和一些 pip install
才能使工作成功)。
我正在尝试熟悉 Gitlab CI environment with a test project, https://gitlab.com/khpeek/CI-test。该项目有以下.gitlab-ci.yml
:
image: python:2.7-onbuild
services:
- rethinkdb:latest
test_job:
script:
- pytest
问题是 CI 管道中的 test_job
作业失败并显示以下错误消息:
Running with gitlab-ci-multi-runner 9.0.1 (a3da309)
on docker-auto-scale (e11ae361)
Using Docker executor with image python:2.7-onbuild ...
Starting service rethinkdb:latest ...
Pulling docker image rethinkdb:latest ...
Using docker image rethinkdb:latest ID=sha256:23ecfb08823bc5483c6a955b077a9bc82899a0df2f33899b64992345256f22dd for service rethinkdb...
Waiting for services to be up and running...
Using docker image sha256:aaecf574604a31dd49a9d4151b11739837e4469df1cf7b558787048ce4ba81aa ID=sha256:aaecf574604a31dd49a9d4151b11739837e4469df1cf7b558787048ce4ba81aa for predefined container...
Pulling docker image python:2.7-onbuild ...
Using docker image python:2.7-onbuild ID=sha256:5754a7fac135b9cae7e02e34cc7ba941f03a33fb00cf31f12fbb71b8d389ece2 for build container...
Running on runner-e11ae361-project-3083420-concurrent-0 via runner-e11ae361-machine-1491819341-82630004-digital-ocean-2gb...
Cloning repository...
Cloning into '/builds/khpeek/CI-test'...
Checking out d0937f33 as master...
Skipping Git submodules setup
$ pytest
/bin/bash: line 56: pytest: command not found
ERROR: Job failed: exit code 1
但是,存储库中有一个 requirements.txt
,其中只有一行 pytest==3.0.7
。然而,从 python:2.7-onbuild
图像的 Dockerfile 看来,pip install -r requirements.txt
应该在构建时得到 运行。那么为什么找不到 pytest
?
如果您查看 Dockerfile you linked to, you'll see pip install -r requirements.txt
is part of an onbuild 命令。如果您想从第一个容器创建一个新容器并安装一堆需求,这将很有用。因此,pip install -r requirements.txt
命令不会在您的 CI 管道的容器内执行,如果是,它将在最开始执行,甚至在您的 gitlab 存储库被克隆之前执行。
我建议您以这种方式修改 .gitlab-ci.yml
文件
image: python:2.7-onbuild
services:
- rethinkdb:latest
test_job:
script:
- pip install -r requirements.txt
- pytest
问题似乎是间歇性的:虽然第一次 运行 测试需要 61 分钟(最初失败),但现在大约需要一分钟(见下面的屏幕截图)。
作为参考,测试存储库位于 https://gitlab.com/khpeek/CI-test。 (我必须添加一个 before_script
和一些 pip install
才能使工作成功)。