blob: 710b1bbab07fe65205dcb54c58647fec4477bdba [file] [log] [blame]
Jakub Josef823e5422017-07-31 15:05:27 +02001
2/**
3 * Docker cleanup pipeline which can kill old containers (more than a day) and prune docker itself
4 *
5 * SALT_MASTER_URL
6 * SALT_MASTER_CREDENTIALS
7 * TEST_DATE_STRING - string representation of date which will be used for delete matching (ie. yesterday)
8 */
9common = new com.mirantis.mk.Common()
10salt = new com.mirantis.mk.Salt()
11jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
chnyda625f4b42017-10-11 14:10:31 +020012def python = new com.mirantis.mk.Python()
13
14def pepperEnv = "pepperEnv"
Jakub Josefa63f9862018-01-11 17:58:38 +010015timeout(time: 12, unit: 'HOURS') {
16 node{
17 def saltMaster;
18 stage('Setup virtualenv for Pepper') {
19 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
20 }
21 stage("Clean old containers"){
22 salt.cmdRun(pepperEnv, 'I@jenkins:slave', """
23 docker ps --format='{{.ID}}' | xargs -n 1 -r docker inspect \\
24 -f '{{.ID}} {{.State.Running}} {{.State.StartedAt}}' \\
25 | awk '\$2 == "true" && \$3 <= "'\$(date -d '${TEST_DATE_STRING}' -Ins --utc \\
26 | sed 's/+0000/Z/')'" { print \$1 }' \\
27 | xargs -r docker rm -f
28 """, false)
29 }
30 stage("Run docker system prune"){
31 salt.cmdRun(pepperEnv, 'I@jenkins:slave', "docker system prune -f")
32 }
Jakub Josef823e5422017-07-31 15:05:27 +020033 }
34}