Add ability to specify built-time variables for local build

Change-Type: patch
This commit is contained in:
Akis Kesoglou 2017-05-10 22:02:52 +03:00
parent 8cb862359b
commit 66876a2c85
3 changed files with 53 additions and 1 deletions

View File

@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Add uploading of build logs when present with resin deploy
- Highlight cache usage in a local build
- Show a progress bar for upload progress
- Add ability to specify build-time variables for local builds
### Fixed

View File

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.12.5
var cacheHighlightStream, generateConnectOpts, tarDirectory;
var cacheHighlightStream, generateConnectOpts, parseBuildArgs, tarDirectory;
exports.appendOptions = function(opts) {
return opts.concat([
@ -35,6 +35,11 @@ exports.appendOptions = function(opts) {
parameter: 'tag',
description: 'The alias to the generated image',
alias: 't'
}, {
signature: 'arg',
parameter: 'arg',
description: 'Set a build-time variable (eg. "-e \'ARG=value\'"). Can be specified multiple times.',
alias: 'e'
}, {
signature: 'nocache',
description: "Don't use docker layer caching when building",
@ -122,6 +127,25 @@ cacheHighlightStream = function() {
});
};
parseBuildArgs = function(args, onError) {
var _, obj;
_ = require('lodash');
if (!_.isArray(args)) {
args = [args];
}
obj = {};
args.forEach(function(str) {
var pair;
pair = /^([^\s]+?)=(.*)$/.exec(str);
if (pair != null) {
return obj[pair[1]] = pair[2];
} else {
return onError(str);
}
});
return obj;
};
exports.runBuild = function(params, options, getBundleInfo, logStreams) {
var Promise, dockerBuild, doodles, es, logging, logs, resolver;
Promise = require('bluebird');
@ -187,6 +211,11 @@ exports.runBuild = function(params, options, getBundleInfo, logStreams) {
if (options.nocache != null) {
opts['nocache'] = true;
}
if (options.arg != null) {
opts['buildargs'] = parseBuildArgs(options.arg, function(arg) {
return logging.logWarn(logStreams, "Could not parse variable: '" + arg + "'");
});
}
return builder.createBuildStream(opts, hooks, reject);
});
});

View File

@ -47,6 +47,12 @@ exports.appendOptions = (opts) ->
description: 'The alias to the generated image'
alias: 't'
},
{
signature: 'arg'
parameter: 'arg'
description: 'Set a build-time variable (eg. "-e \'ARG=value\'"). Can be specified multiple times.'
alias: 'e'
},
{
signature: 'nocache'
description: "Don't use docker layer caching when building"
@ -128,6 +134,19 @@ cacheHighlightStream = ->
data = colors.bgGreen.black(msg)
return data + EOL
parseBuildArgs = (args, onError) ->
_ = require('lodash')
if not _.isArray(args)
args = [ args ]
obj = {}
args.forEach (str) ->
pair = /^([^\s]+?)=(.*)$/.exec(str)
if pair?
obj[pair[1]] = pair[2]
else
onError(str)
return obj
# 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) ->
@ -206,6 +225,9 @@ exports.runBuild = (params, options, getBundleInfo, logStreams) ->
opts['t'] = options.tag
if options.nocache?
opts['nocache'] = true
if options.arg?
opts['buildargs'] = parseBuildArgs options.arg, (arg) ->
logging.logWarn(logStreams, "Could not parse variable: '#{arg}'")
builder.createBuildStream(opts, hooks, reject)