-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
82 lines (73 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
pipeline {
// The agent requires docker to be installed on it. as this code is run on a single node and WILL NOT be run in any other location, the is real need to specify agents.1
agent any
triggers {
pollSCM('H * * * *')
}
environment {
IMAGE_NAME = 'mattisafur/wog'
IMAGE_TAG = 'latest'
DOCKER_REGISTRY = 'docker.io'
}
stages {
stage('Build') {
steps{
// check is docker is installled
script {
def dockerStatus = sh(script: 'docker --version', returnStatus: true)
if(dockerStatus != 0) {
error('Docker is not installed on the node')
}
}
// build docker container
script {
docker.build('mattisafur/wog:latest')
}
}
}
stage('Run') {
steps {
// start web server
sh 'docker compose up -d'
}
}
stage('Test') {
steps {
// check if python3 is installed on the system
script {
def pythonState = sh(script: 'python3 --version', returnStatus: true)
if(pythonState != 0) {
error('Python 3 is not installed on the node')
}
}
// create and activate venv, install requirements
// run end to end test
sh '''
python3 -m venv .venv
. ./.venv/bin/activate
pip install -r requirements.txt
python3 e2e.py
deactivate
'''
}
}
stage('Finalize') {
steps {
// stop web server
sh 'docker compose down'
// push image to dockerhub
withDockerRegistry([credentialsId: 'dockerhub-mattisafur', url: '']) {
sh 'docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}'
}
}
}
}
post {
always {
// delete venv
sh 'rm -r .venv'
// prune docker
sh 'docker system prune -af'
}
}
}