[英]How to cache python dependecies in Gitlab CI/CD without using venv?
[英]How to use python and mongodb on the gitlab (CI/CD)
在gitlab上使用CI / CD时遇到问题。 我一直使用“ python:latest”,但它是2.7.5版本,但我想使用python2.7.15或python3.7。 如何安装?
-
image: python:latest
services:
- mongo:latest
variables:
MONGO_DB: ipc_alert
cache:
paths:
- ~/.cache/pip/
before_script:
- python -V
- pip install -r req.txt
stages:
- test
test:
stage: test
script:
- echo 'Testing'
在您发布的图像上,您遇到了其他问题。 您找不到符合您要求的有效版本的django。
关于问题本身,如果要针对多个版本进行测试,则需要创建多个测试。 例如:
test:
stage: test
script:
- echo 'Testing'
那将是:
test-python2.7:
stage: test
image: python:2.7
script:
- echo 'Testing'
test-python3.4:
stage: test
image: python:3.4
script:
- echo 'Testing'
test-python3.5:
stage: test
image: python:3.5
script:
- echo 'Testing'
test-python3.6:
stage: test
image: python:3.6
script:
- echo 'Testing'
test-python3.7:
stage: test
image: python:3.7
script:
- echo 'Testing'
test-python.latest:
stage: test
image: python:latest
script:
- echo 'Testing'
但是,这可能不起作用,因为您使用的是“ Shell executor”。 如果我没有记错的话,那么该运行程序将在当前计算机上执行您的代码。 您需要安装docker并创建一个使用这些docker的新运行程序。 没有它,您将无法针对不同的环境/版本进行测试。
一个例外是,如果您在计算机上安装了需要安装的所有python版本,并调用每个python具体版本。 这取决于您的环境,但是如果您有多个python版本,则可以检查/ usr / bin。 在我的机器上,我在/ usr / bin上有以下这些文件:
maqui@kanade:~$ python -V
Python 2.7.15+
maqui@kanade:~$ python2.6 -V
Python 2.6.8
maqui@kanade:~$ python2.7 -V
Python 2.7.15+
maqui@kanade:~$ python3.6 -V
Python 3.6.8rc1
maqui@kanade:~$ python3.7 -V
Python 3.7.2rc1
(如您所见,python是python2.7的别名)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.