forked from merovigen/student-exam2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
94 lines (69 loc) · 2.32 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
pipeline {
agent {
label 'ssh-docker-agent'
}
environment {
DOCKERHUB_PASS=credentials('dockerhub-pass')
}
stages {
stage("startup") {
steps {
echo '---------------------- start startup --------------------------'
sh '''#!/bin/bash -x
docker run -it -dp 8888:80 --name cont1 -w /student-exam2/ python:3.8-slim-buster
docker cp . cont1:/student-exam2/
docker exec -it cont1 pip install -e .
docker exec -d --env FLASK_APP=js_example cont1 python3 -m flask run --host=0.0.0.0 --port=80
docker rm --force cont1
'''
echo '----------------------- end startup ---------------------------'
}
}
stage("test") {
steps {
echo '---------------------- start testing --------------------------'
sh '''#!/bin/bash -x
docker run -it -dp 8888:80 --name cont1 -w /student-exam2/ python:3.8-slim-buster
docker cp . cont1:/student-exam2/
docker exec cont1 pip install -e '.[test]'
docker exec cont1 coverage run -m pytest
docker exec cont1 coverage report
docker rm --force cont1
'''
echo '----------------------- end testing ---------------------------'
}
}
stage("build image") {
steps {
echo '---------------------- start build image --------------------------'
sh '''#!/bin/bash -x
cat > Dockerfile <<- EOF
FROM python:3.8-slim-buster
COPY . /student-exam2/
WORKDIR /student-exam2
RUN pip install -e .
ENV FLASK_APP=js_example
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=80"]
EXPOSE 80/tcp
EOF
docker build -t alexanderkiyanov/appimg:latest .
docker run -it -dp 8888:80 --name cont1 alexanderkiyanov/appimg:latest
'''
echo '----------------------- end build image ---------------------------'
}
}
stage("docker hub") {
steps {
echo '---------------------- start push to docker hub --------------------------'
sh '''#!/bin/bash -x
docker images
echo $DOCKERHUB_PASS_PSW | docker login -u $DOCKERHUB_PASS_USR --password-stdin
docker push alexanderkiyanov/appimg:latest
docker rm --force cont1
docker rmi alexanderkiyanov/appimg:latest
'''
echo '----------------------- end push to docker hub ---------------------------'
}
}
}
}