Skip to content

Commit

Permalink
use buildid instead of imageID which default to latest if the image e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
oba11 committed Jul 5, 2017
1 parent 82ab73a commit 1747d87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -115,7 +119,7 @@ docker.buildImage = function(project, tarPath, imageId, buildId, buildLogger, do
return;
}

resolve();
resolve(realBuildId);
});
});
});
Expand All @@ -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;
Expand Down

0 comments on commit 1747d87

Please sign in to comment.