-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjenkinsfile
84 lines (64 loc) · 2.85 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
pipeline {
agent any
stages {
stage('Build'){
steps {
sh '''
#!/usr/bin/env bash
# Names to identify images and containers of this app
# TAG=$BUILD_NUMBER
TAG=1.0
build_all() {
echo "Starting BaseImage Build"
current_base_image_id=$(docker images | grep "projectmirror/baseimage 1.0" | awk '{ print $3 }')
docker build -t projectmirror/baseimage:1.0 ./baseimage/
new_base_image_id=$(docker images | grep "projectmirror/baseimage 1.0" | awk '{ print $3 }')
docker push projectmirror/baseimage:1.0
echo "the current base_image id is $current_base_image_id"
echo "the new base_image id is $new_base_image_id"
if [ "$current_base_image_id" != "$new_base_image_id" ];
then
echo "The base image has been rebuilt. Deleting all other containers and images ahead of rebuild"
docker rm -f $(docker ps -a -q) || true
# For now, deleting all images other than the the one with id=IMAGE_ID. If this turns out to be over-raeaching it can be susbtitutued with the below
# docker rmi $(docker images | grep -Ei $TAG | grep -Eiv $new_base_image_id)
docker rmi -f $(docker images -q | grep -Eiv $new_base_image_id) || true
else
echo "The base image hasn't been rebuilt. So no need to rebuild all images from scratch";
fi;
## Now building remaining microservices
docker-compose -f docker-compose-dev.yml build
}
build_all
'''
}
}
stage('Test'){
steps {
sh '''docker-compose -f docker-compose-dev.yml down
docker-compose -f docker-compose-dev.yml up -d
docker ps
python3 -m virtualenv venv -p $(which python3)
. venv/bin/activate
pip3 install -r webapp/requirements.txt
export PYTHONPATH=:$PWD
python3 webapp/tests/tests.py
docker-compose -f docker-compose-dev.yml down
rm -rf venv
'''
}
}
stage('Push to DockerHub'){
steps {
sh '''
docker-compose -f docker-compose-dev.yml push
'''
}
}
stage('Deploy via RunDeck'){
steps {
build 'Project Mirror - Deploy'
}
}
}
}