-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathJenkinsfile
More file actions
60 lines (54 loc) · 1.42 KB
/
Jenkinsfile
File metadata and controls
60 lines (54 loc) · 1.42 KB
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
node {
checkout scm
def PIPENV = "~/.local/bin/pipenv"
stage("Build") {
dir("restapi") {
sh "pip3 install pipenv"
sh "${PIPENV} install"
}
}
stage("Test") {
def PORT = 3306
def ROOT = "secret_root"
def DB = "movieapp"
def USER = "movieapp"
def PASS = "secret_user"
try {
docker.image("mariadb:latest").withRun("-p ${PORT}:${PORT} -e MYSQL_ROOT_PASSWORD=${ROOT} -e MYSQL_DATABASE=${DB} -e MYSQL_USER=${USER} -e MYSQL_PASSWORD=${PASS}") { c ->
docker.image("mariadb:latest").inside("--link ${c.id}:db") {
sh 'while ! mysqladmin ping -hdb --silent; do sleep 1; done'
}
dir("restapi") {
withEnv(["DATABASE=${DB}","DBUSER=${USER}","PASSWORD=${PASS}"]){
sh "${PIPENV} run python tests/MoviesTest.py"
sh "${PIPENV} run python tests/CategoriesTest.py"
}
}
}
}
catch (Exception e) {
error "Unable to launch tests.Probably because something is running on port 3306."
}
}
stage("Deploy") {
docker.withRegistry("" , "DockerCreds") {
dir("restapi") {
docker.build("${params.REGISTRY}/restapi").push("latest")
}
dir("webapp") {
docker.build("${params.REGISTRY}/webapp").push("latest")
}
}
}
stage("Run") {
try {
sh "docker-compose up --build -d"
}
catch (Exception e) {
error "Unable to start services.Probably because something is running on port 80 or 8000."
}
finally {
sh "docker system prune -f"
}
}
}