Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dockerode and fix tagging wrong image #39

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
},
"homepage": "https://github.com/namshi/roger",
"dependencies": {
"aws-sdk": "^2.1.8",
"aws-sdk": "^2.6.4",
"body-parser": "^1.10.2",
"dockerode": "2.3.1",
"dockerode": "2.4.3",
"express": "^4.11.1",
"express-session": "^1.11.3",
"github": "^0.2.3",
Expand Down
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', '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very hack-ish, it's prone to error :) maybe check if dockerode provides other ways to give you the image name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find a cleaner way around it. To avoid potential issue, did set the realBuildId as buildID as initial value.

}
});

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