mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-27 22:40:06 +00:00
Merge pull request #515 from resin-io/build-time-vars
Add ability to specify built-time variables for local build
This commit is contained in:
commit
3a44782c38
@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Add uploading of build logs when present with resin deploy
|
- Add uploading of build logs when present with resin deploy
|
||||||
- Highlight cache usage in a local build
|
- Highlight cache usage in a local build
|
||||||
- Show a progress bar for upload progress
|
- Show a progress bar for upload progress
|
||||||
|
- Add ability to specify build-time variables for local builds
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Generated by CoffeeScript 1.12.5
|
// Generated by CoffeeScript 1.12.5
|
||||||
var cacheHighlightStream, generateConnectOpts, tarDirectory;
|
var cacheHighlightStream, generateConnectOpts, parseBuildArgs, tarDirectory;
|
||||||
|
|
||||||
exports.appendOptions = function(opts) {
|
exports.appendOptions = function(opts) {
|
||||||
return opts.concat([
|
return opts.concat([
|
||||||
@ -35,6 +35,11 @@ exports.appendOptions = function(opts) {
|
|||||||
parameter: 'tag',
|
parameter: 'tag',
|
||||||
description: 'The alias to the generated image',
|
description: 'The alias to the generated image',
|
||||||
alias: 't'
|
alias: 't'
|
||||||
|
}, {
|
||||||
|
signature: 'buildArg',
|
||||||
|
parameter: 'arg',
|
||||||
|
description: 'Set a build-time variable (eg. "-B \'ARG=value\'"). Can be specified multiple times.',
|
||||||
|
alias: 'B'
|
||||||
}, {
|
}, {
|
||||||
signature: 'nocache',
|
signature: 'nocache',
|
||||||
description: "Don't use docker layer caching when building",
|
description: "Don't use docker layer caching when building",
|
||||||
@ -122,6 +127,25 @@ cacheHighlightStream = function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
parseBuildArgs = function(args, onError) {
|
||||||
|
var _, buildArgs;
|
||||||
|
_ = require('lodash');
|
||||||
|
if (!_.isArray(args)) {
|
||||||
|
args = [args];
|
||||||
|
}
|
||||||
|
buildArgs = {};
|
||||||
|
args.forEach(function(str) {
|
||||||
|
var pair;
|
||||||
|
pair = /^([^\s]+?)=(.*)$/.exec(str);
|
||||||
|
if (pair != null) {
|
||||||
|
return buildArgs[pair[1]] = pair[2];
|
||||||
|
} else {
|
||||||
|
return onError(str);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return buildArgs;
|
||||||
|
};
|
||||||
|
|
||||||
exports.runBuild = function(params, options, getBundleInfo, logStreams) {
|
exports.runBuild = function(params, options, getBundleInfo, logStreams) {
|
||||||
var Promise, dockerBuild, doodles, es, logging, logs, resolver;
|
var Promise, dockerBuild, doodles, es, logging, logs, resolver;
|
||||||
Promise = require('bluebird');
|
Promise = require('bluebird');
|
||||||
@ -187,6 +211,11 @@ exports.runBuild = function(params, options, getBundleInfo, logStreams) {
|
|||||||
if (options.nocache != null) {
|
if (options.nocache != null) {
|
||||||
opts['nocache'] = true;
|
opts['nocache'] = true;
|
||||||
}
|
}
|
||||||
|
if (options.buildArg != null) {
|
||||||
|
opts['buildargs'] = parseBuildArgs(options.buildArg, function(arg) {
|
||||||
|
return logging.logWarn(logStreams, "Could not parse variable: '" + arg + "'");
|
||||||
|
});
|
||||||
|
}
|
||||||
return builder.createBuildStream(opts, hooks, reject);
|
return builder.createBuildStream(opts, hooks, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -47,6 +47,12 @@ exports.appendOptions = (opts) ->
|
|||||||
description: 'The alias to the generated image'
|
description: 'The alias to the generated image'
|
||||||
alias: 't'
|
alias: 't'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
signature: 'buildArg'
|
||||||
|
parameter: 'arg'
|
||||||
|
description: 'Set a build-time variable (eg. "-B \'ARG=value\'"). Can be specified multiple times.'
|
||||||
|
alias: 'B'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
signature: 'nocache'
|
signature: 'nocache'
|
||||||
description: "Don't use docker layer caching when building"
|
description: "Don't use docker layer caching when building"
|
||||||
@ -128,6 +134,19 @@ cacheHighlightStream = ->
|
|||||||
data = colors.bgGreen.black(msg)
|
data = colors.bgGreen.black(msg)
|
||||||
return data + EOL
|
return data + EOL
|
||||||
|
|
||||||
|
parseBuildArgs = (args, onError) ->
|
||||||
|
_ = require('lodash')
|
||||||
|
if not _.isArray(args)
|
||||||
|
args = [ args ]
|
||||||
|
buildArgs = {}
|
||||||
|
args.forEach (str) ->
|
||||||
|
pair = /^([^\s]+?)=(.*)$/.exec(str)
|
||||||
|
if pair?
|
||||||
|
buildArgs[pair[1]] = pair[2]
|
||||||
|
else
|
||||||
|
onError(str)
|
||||||
|
return buildArgs
|
||||||
|
|
||||||
# Pass in the command line parameters and options and also
|
# Pass in the command line parameters and options and also
|
||||||
# a function which will return the information about the bundle
|
# a function which will return the information about the bundle
|
||||||
exports.runBuild = (params, options, getBundleInfo, logStreams) ->
|
exports.runBuild = (params, options, getBundleInfo, logStreams) ->
|
||||||
@ -206,6 +225,9 @@ exports.runBuild = (params, options, getBundleInfo, logStreams) ->
|
|||||||
opts['t'] = options.tag
|
opts['t'] = options.tag
|
||||||
if options.nocache?
|
if options.nocache?
|
||||||
opts['nocache'] = true
|
opts['nocache'] = true
|
||||||
|
if options.buildArg?
|
||||||
|
opts['buildargs'] = parseBuildArgs options.buildArg, (arg) ->
|
||||||
|
logging.logWarn(logStreams, "Could not parse variable: '#{arg}'")
|
||||||
|
|
||||||
builder.createBuildStream(opts, hooks, reject)
|
builder.createBuildStream(opts, hooks, reject)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user