From 1747d878406d1c39b9e96e479a6886b82b573688 Mon Sep 17 00:00:00 2001 From: Oluwaseun Obajobi Date: Sun, 4 Jun 2017 13:28:43 +0400 Subject: [PATCH] use buildid instead of imageID which default to latest if the image exist --- src/builder.js | 8 ++++---- src/docker.js | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/builder.js b/src/builder.js index cda8ed9..b67ebf1 100644 --- a/src/builder.js +++ b/src/builder.js @@ -154,11 +154,11 @@ builder.build = function(project, uuid, path, gitBranch, branch, dockerOptions) buildLogger.info('[%s] Created tarball for %s', buildId, uuid); return docker.buildImage(project, tarPath, imageId + ':' + branch, buildId, buildLogger, dockerOptions, uuid); - }).then(function() { - buildLogger.info('[%s] %s built succesfully', buildId, uuid); - buildLogger.info('[%s] Tagging %s', buildId, uuid); + }).then(function(realBuildId) { + buildLogger.info('[%s] %s built succesfully as imageId: %s', buildId, uuid, realBuildId); + buildLogger.info('[%s] Tagging %s as imageId: %s', buildId, uuid, realBuildId); - return docker.tag(imageId, buildId, branch, buildLogger); + return docker.tag(imageId, realBuildId, branch, buildLogger); }).then(function(image) { return publisher.publish(docker.client, buildId, project, buildLogger).then(function() { return image; diff --git a/src/docker.js b/src/docker.js index 3bafa96..db6aeed 100644 --- a/src/docker.js +++ b/src/docker.js @@ -76,6 +76,7 @@ docker.buildImage = function(project, tarPath, imageId, buildId, buildLogger, do return Q.promise(function(resolve, reject) { dockerOptions = dockerOptions || {}; var tag = imageId + ((dockerOptions.dockerfile) ? '-builder' : ''); + var realBuildId = buildId; docker.client.buildImage(tarPath, _.extend({t: tag}, dockerOptions), function(err, response) { if (err) { @@ -105,6 +106,9 @@ docker.buildImage = function(project, tarPath, imageId, buildId, buildLogger, do } buildLogger.info('[%s] %s', tag, result.stream || result.status); + if (result.stream && result.stream.indexOf('Successfully built ') == 0) { + realBuildId = result.stream.split('Successfully built ')[1].replace('\n', ''); + } }); response.on('end', function() { @@ -115,7 +119,7 @@ docker.buildImage = function(project, tarPath, imageId, buildId, buildLogger, do return; } - resolve(); + resolve(realBuildId); }); }); }); @@ -128,10 +132,10 @@ docker.buildImage = function(project, tarPath, imageId, buildId, buildLogger, do */ docker.tag = function(imageId, buildId, branch) { var deferred = Q.defer(); - var image = docker.client.getImage(imageId); + var image = docker.client.getImage(buildId); image.tag({repo: imageId, tag: branch}, function() { - deferred.resolve(image); + deferred.resolve(docker.client.getImage(imageId)); }); return deferred.promise;