Jakub Josef | 823e542 | 2017-07-31 15:05:27 +0200 | [diff] [blame] | 1 | |
| 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 | */ |
| 9 | common = new com.mirantis.mk.Common() |
| 10 | salt = new com.mirantis.mk.Salt() |
| 11 | jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 12 | def python = new com.mirantis.mk.Python() |
| 13 | |
| 14 | def pepperEnv = "pepperEnv" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 15 | timeout(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"){ |
Jakub Josef | 37ea7a7 | 2018-03-28 15:41:19 +0200 | [diff] [blame] | 31 | salt.cmdRun(pepperEnv, 'I@jenkins:slave', "docker system prune -f", false) // dont verify the result |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 32 | } |
Jakub Josef | 823e542 | 2017-07-31 15:05:27 +0200 | [diff] [blame] | 33 | } |
| 34 | } |