blob: 3975b06ee724e1da8c28b7c3317becf35c389bca [file] [log] [blame]
Sergey Kolekonovba203982016-12-21 18:32:17 +04001package com.mirantis.mk
2
3/**
4 *
5 * Docker functions
6 *
7 */
8
9/**
Jakub Josef1ef81e62017-04-03 19:14:54 +020010 * Build step to build docker image.
Sergey Kolekonovba203982016-12-21 18:32:17 +040011 *
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 Josef1ef81e62017-04-03 19:14:54 +020016 * @return "docker app" - result of docker.build
Sergey Kolekonovba203982016-12-21 18:32:17 +040017 */
Jakub Josef92d3ea12017-04-04 15:35:52 +020018def buildDockerImage(img, baseImg, dockerFile, timestamp) {
Jakub Josef1ef81e62017-04-03 19:14:54 +020019 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 Kolekonovba203982016-12-21 18:32:17 +040022 }
Jakub Josef1ef81e62017-04-03 19:14:54 +020023 return docker.build(
24 "${img}:${timestamp}",
25 [
26 "-f ${dockerFile}",
27 imageDir
28 ].join(' ')
29 )
Sergey Kolekonovba203982016-12-21 18:32:17 +040030}