Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * Docker functions |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /** |
Jakub Josef | 1ef81e6 | 2017-04-03 19:14:54 +0200 | [diff] [blame] | 10 | * Build step to build docker image. |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 11 | * |
| 12 | * @param img Image name |
| 13 | * @param baseImg Base image to use (can be empty) |
| 14 | * @param dockerFile Dockerfile to use |
| 15 | * @param timestamp Image tag |
Jakub Josef | 1ef81e6 | 2017-04-03 19:14:54 +0200 | [diff] [blame] | 16 | * @return "docker app" - result of docker.build |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 17 | */ |
Jakub Josef | 92d3ea1 | 2017-04-04 15:35:52 +0200 | [diff] [blame] | 18 | def buildDockerImage(img, baseImg, dockerFile, timestamp) { |
Jakub Josef | 1ef81e6 | 2017-04-03 19:14:54 +0200 | [diff] [blame] | 19 | def imageDir = dockerFile.substring(0, dockerFile.lastIndexOf("/")) |
| 20 | if (baseImg) { |
| 21 | sh "git checkout -f ${dockerFile}; sed -i -e 's,^FROM.*,FROM ${baseImg},g' ${dockerFile}" |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 22 | } |
Jakub Josef | 1ef81e6 | 2017-04-03 19:14:54 +0200 | [diff] [blame] | 23 | return docker.build( |
| 24 | "${img}:${timestamp}", |
| 25 | [ |
| 26 | "-f ${dockerFile}", |
| 27 | imageDir |
| 28 | ].join(' ') |
| 29 | ) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 30 | } |