blob: 1357dc176e3305dd39fdf94507183a80cd6ba98c [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
chnyda16535ab2017-05-25 16:28:28 +020016 * @param params Other parameters for docker
Jakub Josef1ef81e62017-04-03 19:14:54 +020017 * @return "docker app" - result of docker.build
Sergey Kolekonovba203982016-12-21 18:32:17 +040018 */
chnyda16535ab2017-05-25 16:28:28 +020019def buildDockerImage(img, baseImg, dockerFile, timestamp, params=[]) {
Jakub Josef1ef81e62017-04-03 19:14:54 +020020 def imageDir = dockerFile.substring(0, dockerFile.lastIndexOf("/"))
21 if (baseImg) {
22 sh "git checkout -f ${dockerFile}; sed -i -e 's,^FROM.*,FROM ${baseImg},g' ${dockerFile}"
Sergey Kolekonovba203982016-12-21 18:32:17 +040023 }
chnyda16535ab2017-05-25 16:28:28 +020024
25 params << "-f ${dockerFile}"
26 params << imageDir
27
Jakub Josef1ef81e62017-04-03 19:14:54 +020028 return docker.build(
29 "${img}:${timestamp}",
chnyda16535ab2017-05-25 16:28:28 +020030 params.join(' ')
Jakub Josef1ef81e62017-04-03 19:14:54 +020031 )
Sergey Kolekonovba203982016-12-21 18:32:17 +040032}
chnyda1cf6f0d2017-06-02 11:01:04 +020033
34/**
35 * Build step to build docker image.
36 *
37 * @param dockerHubImg Name of image on dockerhub (ie: tcpcloud/salt-models-testing)
38 * @param defaultImg Image to use if dockerHubImg is not found
39 * @return img Docker image
40 */
41
42def getImage(dockerHubImg, defaultImg="ubuntu:latest") {
43
44 def img
45
46 try {
47 img = docker.image(dockerHubImg)
48 img.pull()
49 } catch (Throwable e) {
50 img = docker.image(defaultImg)
51 }
52
53 return img
54}