mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Merge pull request #2887 from balena-io/refactor-build
Refactor balena build for clarity
This commit is contained in:
commit
92fd9e0883
24
npm-shrinkwrap.json
generated
24
npm-shrinkwrap.json
generated
@ -6943,9 +6943,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/cross-env/node_modules/cross-spawn": {
|
"node_modules/cross-env/node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz",
|
||||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
"integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
@ -8261,9 +8261,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint/node_modules/cross-spawn": {
|
"node_modules/eslint/node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz",
|
||||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
"integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
@ -9221,9 +9221,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/foreground-child/node_modules/cross-spawn": {
|
"node_modules/foreground-child/node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz",
|
||||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
"integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
"shebang-command": "^2.0.0",
|
"shebang-command": "^2.0.0",
|
||||||
@ -14081,9 +14081,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/patch-package/node_modules/cross-spawn": {
|
"node_modules/patch-package/node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz",
|
||||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
"integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
"shebang-command": "^2.0.0",
|
"shebang-command": "^2.0.0",
|
||||||
|
@ -36,14 +36,16 @@ import { buildProject, composeCliFlags } from '../../utils/compose_ts';
|
|||||||
import type { BuildOpts, DockerCliFlags } from '../../utils/docker';
|
import type { BuildOpts, DockerCliFlags } from '../../utils/docker';
|
||||||
import { dockerCliFlags } from '../../utils/docker';
|
import { dockerCliFlags } from '../../utils/docker';
|
||||||
|
|
||||||
// TODO: For this special one we can't use Interfaces.InferredFlags/InferredArgs
|
type ComposeGenerateOptsParam = Parameters<typeof compose.generateOpts>[0];
|
||||||
// because of the 'registry-secrets' type which is defined in the actual code
|
|
||||||
// as a path (string | undefined) but then the cli turns it into an object
|
interface PrepareBuildOpts
|
||||||
interface FlagsDef extends ComposeCliFlags, DockerCliFlags {
|
extends ComposeCliFlags,
|
||||||
|
DockerCliFlags,
|
||||||
|
ComposeGenerateOptsParam {
|
||||||
arch?: string;
|
arch?: string;
|
||||||
deviceType?: string;
|
deviceType?: string;
|
||||||
fleet?: string;
|
fleet?: string;
|
||||||
source?: string; // Not part of command profile - source param copied here.
|
source?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class BuildCmd extends Command {
|
export default class BuildCmd extends Command {
|
||||||
@ -113,29 +115,31 @@ ${dockerignoreHelp}
|
|||||||
const logger = Logger.getLogger();
|
const logger = Logger.getLogger();
|
||||||
logger.logDebug('Parsing input...');
|
logger.logDebug('Parsing input...');
|
||||||
|
|
||||||
// `build` accepts `source` as a parameter, but compose expects it as an option
|
const prepareBuildOpts = {
|
||||||
options.source = params.source;
|
...options,
|
||||||
delete params.source;
|
source: params.source,
|
||||||
|
};
|
||||||
|
|
||||||
await this.resolveArchFromDeviceType(sdk, options);
|
await this.resolveArchFromDeviceType(sdk, prepareBuildOpts);
|
||||||
|
|
||||||
await this.validateOptions(options, sdk);
|
await this.validateOptions(prepareBuildOpts, sdk);
|
||||||
|
|
||||||
// Build args are under consideration for removal - warn user
|
// Build args are under consideration for removal - warn user
|
||||||
if (options.buildArg) {
|
if (prepareBuildOpts.buildArg) {
|
||||||
console.log(buildArgDeprecation);
|
console.log(buildArgDeprecation);
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = await this.getAppAndResolveArch(options);
|
const app = await this.getAppAndResolveArch(prepareBuildOpts);
|
||||||
|
|
||||||
const { docker, buildOpts, composeOpts } = await this.prepareBuild(options);
|
const { docker, buildOpts, composeOpts } =
|
||||||
|
await this.prepareBuild(prepareBuildOpts);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.buildProject(docker, logger, composeOpts, {
|
await this.buildProject(docker, logger, composeOpts, {
|
||||||
appType: app?.application_type?.[0],
|
appType: app?.application_type?.[0],
|
||||||
arch: options.arch!,
|
arch: prepareBuildOpts.arch!,
|
||||||
deviceType: options.deviceType!,
|
deviceType: prepareBuildOpts.deviceType!,
|
||||||
buildEmulated: options.emulated,
|
buildEmulated: prepareBuildOpts.emulated,
|
||||||
buildOpts,
|
buildOpts,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -147,7 +151,7 @@ ${dockerignoreHelp}
|
|||||||
logger.logSuccess('Build succeeded!');
|
logger.logSuccess('Build succeeded!');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async validateOptions(opts: FlagsDef, sdk: BalenaSDK) {
|
protected async validateOptions(opts: PrepareBuildOpts, sdk: BalenaSDK) {
|
||||||
// Validate option combinations
|
// Validate option combinations
|
||||||
if (
|
if (
|
||||||
(opts.fleet == null && (opts.arch == null || opts.deviceType == null)) ||
|
(opts.fleet == null && (opts.arch == null || opts.deviceType == null)) ||
|
||||||
@ -175,7 +179,10 @@ ${dockerignoreHelp}
|
|||||||
opts['registry-secrets'] = registrySecrets;
|
opts['registry-secrets'] = registrySecrets;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async resolveArchFromDeviceType(sdk: BalenaSDK, opts: FlagsDef) {
|
protected async resolveArchFromDeviceType(
|
||||||
|
sdk: BalenaSDK,
|
||||||
|
opts: PrepareBuildOpts,
|
||||||
|
) {
|
||||||
if (opts.deviceType != null && opts.arch == null) {
|
if (opts.deviceType != null && opts.arch == null) {
|
||||||
try {
|
try {
|
||||||
const deviceTypeOpts = {
|
const deviceTypeOpts = {
|
||||||
@ -208,7 +215,7 @@ ${dockerignoreHelp}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getAppAndResolveArch(opts: FlagsDef) {
|
protected async getAppAndResolveArch(opts: PrepareBuildOpts) {
|
||||||
if (opts.fleet) {
|
if (opts.fleet) {
|
||||||
const { getAppWithArch } = await import('../../utils/helpers');
|
const { getAppWithArch } = await import('../../utils/helpers');
|
||||||
const app = await getAppWithArch(opts.fleet);
|
const app = await getAppWithArch(opts.fleet);
|
||||||
@ -218,7 +225,7 @@ ${dockerignoreHelp}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async prepareBuild(options: FlagsDef) {
|
protected async prepareBuild(options: PrepareBuildOpts) {
|
||||||
const { getDocker, generateBuildOpts } = await import('../../utils/docker');
|
const { getDocker, generateBuildOpts } = await import('../../utils/docker');
|
||||||
const [docker, buildOpts, composeOpts] = await Promise.all([
|
const [docker, buildOpts, composeOpts] = await Promise.all([
|
||||||
getDocker(options),
|
getDocker(options),
|
||||||
|
Loading…
Reference in New Issue
Block a user