【发布时间】:2021-07-20 19:11:19
【问题描述】:
我正在努力完成我的学校作业,即:
- 分叉https://github.com/aaronjolson/flask-pytest-example
- 编写 Jenkinsfile、Dockerfile -> 在您的 dockerhub 存储库中生成一个新标签
- 拉码头
- 构建泊坞窗
- 运行泊坞窗
- curl localhost:5000 查看结果
目前我处于第 5 阶段,尝试运行 docker 映像时出现此错误:
Traceback (most recent call last):
File "app.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
配置:
- Jenkins 正在开发 Debian 9
- 使用适用于 Windows 的 Docker 客户端拉取和运行 Docker 映像
- Jenkins 文件:
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.txt
it@debian:~/flask-pytest-example$ cat requirements.txt
flask
pytest
- ls -la
it@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
【问题讨论】:
标签: python docker flask jenkins-pipeline pytest