Highlight cache usage in resin build

This commit will highlight the usage of the cache when doing a docker
build via `resin build`, which not only helps the user understand what
the build is doing, but also achieves more parity with the cloud
builder.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2017-05-02 13:27:18 +01:00
parent 4d2af251b2
commit 404348f92e
No known key found for this signature in database
GPG Key ID: E76D7ACBEE436E12
3 changed files with 56 additions and 7 deletions

View File

@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Add uploading of build logs when present with resin deploy
- Highlight cache usage in a local build
### Fixed

View File

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.12.5
var generateConnectOpts, tarDirectory;
var cacheHighlightStream, generateConnectOpts, tarDirectory;
exports.appendOptions = function(opts) {
return opts.concat([
@ -98,6 +98,30 @@ exports.tarDirectory = tarDirectory = function(dir) {
});
};
cacheHighlightStream = function() {
var EOL, colors, es, extractArrowMessage;
colors = require('colors/safe');
es = require('event-stream');
EOL = require('os').EOL;
extractArrowMessage = function(message) {
var arrowTest, match;
arrowTest = /^\s*-+>\s*(.+)/i;
if ((match = arrowTest.exec(message))) {
return match[1];
} else {
return void 0;
}
};
return es.mapSync(function(data) {
var msg;
msg = extractArrowMessage(data);
if ((msg != null) && msg.toLowerCase() === 'using cache') {
data = colors.bgGreen.black(msg);
}
return data + EOL;
});
};
exports.runBuild = function(params, options, getBundleInfo, logStreams) {
var Promise, dockerBuild, doodles, es, logging, logs, resolver;
Promise = require('bluebird');
@ -115,15 +139,17 @@ exports.runBuild = function(params, options, getBundleInfo, logStreams) {
var builder, connectOpts, hooks, opts;
hooks = {
buildSuccess: function(image) {
var doodle;
if (options.tag != null) {
console.log("Tagging image as " + options.tag);
}
doodle = doodles.getDoodle();
console.log();
console.log(doodles.getDoodle());
console.log(doodle);
console.log();
return resolve({
image: image,
log: logs
log: logs + '\n' + doodle + '\n'
});
},
buildFailure: reject,
@ -147,7 +173,7 @@ exports.runBuild = function(params, options, getBundleInfo, logStreams) {
logs += data.toString();
return this.emit('data', data);
});
return stream.pipe(es.pipe(throughStream, logStreams.build));
return stream.pipe(throughStream).pipe(cacheHighlightStream()).pipe(logStreams.build);
}
};
connectOpts = generateConnectOpts(options);

View File

@ -110,6 +110,24 @@ exports.tarDirectory = tarDirectory = (dir) ->
pack.finalize()
return pack
cacheHighlightStream = ->
colors = require('colors/safe')
es = require('event-stream')
{ EOL } = require('os')
extractArrowMessage = (message) ->
arrowTest = /^\s*-+>\s*(.+)/i
if (match = arrowTest.exec(message))
match[1]
else
undefined
es.mapSync (data) ->
msg = extractArrowMessage(data)
if msg? and msg.toLowerCase() == 'using cache'
data = colors.bgGreen.black(msg)
return data + EOL
# Pass in the command line parameters and options and also
# a function which will return the information about the bundle
exports.runBuild = (params, options, getBundleInfo, logStreams) ->
@ -136,11 +154,12 @@ exports.runBuild = (params, options, getBundleInfo, logStreams) ->
console.log("Tagging image as #{options.tag}")
# Show charlie. In the interest of cloud parity,
# use console.log, not the standard logging streams
doodle = doodles.getDoodle()
console.log()
console.log(doodles.getDoodle())
console.log(doodle)
console.log()
resolve({ image, log: logs } )
resolve({ image, log: logs + '\n' + doodle + '\n' } )
buildFailure: reject
buildStream: (stream) ->
@ -168,7 +187,10 @@ exports.runBuild = (params, options, getBundleInfo, logStreams) ->
logs += data.toString()
this.emit('data', data)
stream.pipe(es.pipe(throughStream, logStreams.build))
stream
.pipe(throughStream)
.pipe(cacheHighlightStream())
.pipe(logStreams.build)
# Create a builder
connectOpts = generateConnectOpts(options)