我正在努力完成我的学校作业,那就是:
https://github.com/aaronjolson/flask-pytest-example
112curl localhost:5000查看结果H 213/code>G 214
目前,我正处于第5阶段,当我试图运行一个码头映像时,我得到了这个错误:
Traceback (most recent call last):
File "app.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask配置:
Windows
Jenkinsfile:
的
Jenkins正在开发Debian 9,使用docker来提取和运行码头映像。it@debian:~/flask-pytest-example$ cat Jenkinsfile
pipeline {
environment {
registry = "tslaceo/flask-pytest"
imageName = 'flask-pytest'
registryCred = 'tslaceo'
gitProject = "https://github.com/tslaceo/flask-pytest-example.git"
}
agent any
options {
timeout(time: 1, unit: 'HOURS')
}
stages {
stage ('preparation') {
steps {
deleteDir()
}
}
stage ('get src from git') {
steps {
git 'https://github.com/tslaceo/flask-pytest-example.git'
}
}
stage ('build docker') {
steps {
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage ('docker publish') {
steps {
script {
docker.withRegistry( '', registryCred ) {
dockerImage.push()
}
}
}
}
stage ('cleaning') {
steps {
sh "docker rmi $registry:$BUILD_NUMBER"
}
}
}
}Dockerfile:it@debian:~/flask-pytest-example$ cat Dockerfile
FROM python
WORKDIR /flask-pytest-example
RUN python --version
RUN pip freeze > requirements.txt
RUN pip install --upgrade pip && pip install -r requirements.txt
COPY . .
CMD ["python", "-u", "app.py"]requirements.txtit@debian:~/flask-pytest-example$ cat requirements.txt
flask
pytestls -lait@debian:~/flask-pytest-example$ ls -la
total 52
drwxr-xr-x 5 it it 4096 Apr 27 15:28 .
drwxr-xr-x 19 it it 4096 Apr 27 14:42 ..
-rw-r--r-- 1 it it 178 Apr 27 10:32 app.py
-rw-r--r-- 1 it it 202 Apr 27 15:06 Dockerfile
-rw-r--r-- 1 it it 152 Apr 27 12:39 Dockerfile.save
drwxr-xr-x 8 it it 4096 Apr 27 15:06 .git
-rw-r--r-- 1 it it 38 Apr 27 10:32 .gitignore
drwxr-xr-x 2 it it 4096 Apr 27 10:32 handlers
-rw-r--r-- 1 it it 0 Apr 27 10:32 __init__.py
-rw-r--r-- 1 it it 1147 Apr 27 10:48 Jenkinsfile
-rw-r--r-- 1 it it 1071 Apr 27 10:32 LICENSE
-rw-r--r-- 1 it it 491 Apr 27 10:32 README.md
-rw-r--r-- 1 it it 13 Apr 27 10:32 requirements.txt
drwxr-xr-x 2 it it 4096 Apr 27 10:32 tests发布于 2021-04-27 12:47:04
删除RUN pip freeze ...行;将其替换为COPY requirements.txt .,以获取与应用程序其他部分签入的文件的副本。
您显示的Dockerfile中的流是
从一个干净的、空的Python installation;
requirements.txt.
中列出的所有包(即空包)写入requirements.txt;
应该将requirements.txt文件作为应用程序源代码的一部分签入,因此如果您将它放入其中而不是重新生成它,那么它将包含其中列出的包,并且它将是您在非Docker虚拟环境中测试的包的确切版本。
我可能会把基于Jenkins的构建设置作为这个序列中的最后一件事。一个更好的办法可以是:
python3 -m venv venv .venv/bin/激活pip安装-r requirements.txt pytest ./app.py curl requirements.txt
使用上面显示的Dockerfile,
码头建造-t tslaceo/瓶-pytest。docker run -p 5000:5000 tslaceo/烧瓶-pytest curl -p
如果您的应用程序有问题(这是通常的情况),虚拟环境设置将更容易调试,并且您可以使用普通编辑器、IDE、调试器等,而无需任何特殊设置。如果您的打包有问题,那么在本地运行docker build将比在CI环境中尝试再现它更容易调试和调整。
https://stackoverflow.com/questions/67283112
复制相似问题