Pipenv 在 Gitlab 中 运行 Docker 时被阻塞

Pipenv gets blocked while running with Docker in Gitlab

我在 Gitlab 中创建了这个简单的项目:

https://gitlab.com/PequeX/deleteme

Pipfile that installs only a couple of packages:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"

[packages]
requests = "*"

[requires]
python_version = "3.7"

而且非常简单.gitlab-ci.yml file:

image: peque/python-devel

before_script:
  - pipenv sync --dev

python36:
  script:
    - pipenv run pytest

还有autogenerated Pipfile.lock file。我不会在这里粘贴,因为它不是很有趣。

现在,问题是 Gitlab 在调用 pipenv sync:

时似乎被阻塞了

https://gitlab.com/PequeX/deleteme/-/jobs/171273142

日志上没有输出,也没有错误。它只会永远被封锁。然后,最终,它会超时(因为 Gitlab 不会让你 运行 永远成为管道)。

有什么问题或者我怎么能成功运行pipenv sync?请注意,我想继续使用来自 Docker Hub 的相同 peque/python-devel image,因为我需要为我的管道安装多个 Python 版本。

更新

按照@Hernan Garcia 在他的回答中建议的那样尝试取消设置 CI 变量,但没有成功:

我也试过 pipenv shell 正如@Hernan Garcia 在他的评论中建议的那样,但没有运气:

我可以使用以下解决方法修复它:
https://github.com/pypa/pipenv/issues/3534#issuecomment-464510351

将以下内容添加到您的 .gitlab-ci.yml 文件以取消设置 CI 变量:

variables:
    CI: ""

检查这个成功的作业:
https://gitlab.com/hernandanielg/deleteme/-/jobs/171342796

;)

如另一个答案中所述,定义一个空 CI 变量将解决构建卡住问题。

然后是由于找不到 pytest 而面临的第二个问题,这是因为 docker 图像缺少 which 包,这使得 pipenv 不存在能够找到 pytest.

最终的 gitlab-ci.yml 文件应该类似于以下内容:

image: peque/python-devel

variables:
  CI: ""

before_script:
  - pipenv sync --dev
  - yum install -y which

python36:
  script:
    - pipenv run pytest

最终输出将是:

$ pipenv run pytest
============================= test session starts ==============================
platform linux -- Python 3.7.2, pytest-4.3.0, py-1.8.0, pluggy-0.9.0
rootdir: /builds/mostafahussein/deleteme, inifile:
collected 0 items

========================= no tests ran in 0.01 seconds =========================


关于这个问题:

termios.error: (25, 'Inappropriate ioctl for device')

这是因为 pipenv shell 需要 tty 到 运行 而不会引发上述错误,但是 GitLab CI 不提供 tty,因为没有用户输入据我所知。所以最好使用第一种方法 pipenv run.

您需要更改文件权限。使其可读可写 使用 chmod 777 命令。 这将赋予文件完全的读写权限