mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-18 02:39:49 +00:00
Switch from Bluebird.join to native version
Change-type: patch
This commit is contained in:
parent
984d1a3fd6
commit
303c3af061
@ -194,18 +194,18 @@ Examples:
|
||||
})
|
||||
|
||||
.then(function ([app, resolvedArch, resolvedDeviceType]) {
|
||||
return Bluebird.join(
|
||||
return Promise.all([
|
||||
dockerUtils.getDocker(options),
|
||||
dockerUtils.generateBuildOpts(options),
|
||||
compose.generateOpts(options),
|
||||
(docker, buildOpts, composeOpts) =>
|
||||
buildProject(docker, logger, composeOpts, {
|
||||
app,
|
||||
arch: resolvedArch,
|
||||
deviceType: resolvedDeviceType,
|
||||
buildEmulated: !!options.emulated,
|
||||
buildOpts,
|
||||
}),
|
||||
]).then(([docker, buildOpts, composeOpts]) =>
|
||||
buildProject(docker, logger, composeOpts, {
|
||||
app,
|
||||
arch: resolvedArch,
|
||||
deviceType: resolvedDeviceType,
|
||||
buildEmulated: !!options.emulated,
|
||||
buildOpts,
|
||||
}),
|
||||
);
|
||||
});
|
||||
},
|
||||
|
@ -150,22 +150,22 @@ const deployProject = function (docker, logger, composeOpts, opts) {
|
||||
sdk.models.release.get(releaseId, { $select: ['commit'] }),
|
||||
);
|
||||
}
|
||||
return Bluebird.join(
|
||||
return Promise.all([
|
||||
sdk.auth.getUserId(),
|
||||
sdk.auth.getToken(),
|
||||
sdk.settings.get('apiUrl'),
|
||||
(userId, auth, apiEndpoint) =>
|
||||
$deployProject(
|
||||
docker,
|
||||
logger,
|
||||
project.composition,
|
||||
images,
|
||||
opts.app.id,
|
||||
userId,
|
||||
`Bearer ${auth}`,
|
||||
apiEndpoint,
|
||||
!opts.shouldUploadLogs,
|
||||
),
|
||||
]).then(([userId, auth, apiEndpoint]) =>
|
||||
$deployProject(
|
||||
docker,
|
||||
logger,
|
||||
project.composition,
|
||||
images,
|
||||
opts.app.id,
|
||||
userId,
|
||||
`Bearer ${auth}`,
|
||||
apiEndpoint,
|
||||
!opts.shouldUploadLogs,
|
||||
),
|
||||
);
|
||||
})
|
||||
);
|
||||
@ -302,20 +302,20 @@ Examples:
|
||||
})
|
||||
.then(() => helpers.getAppWithArch(appName))
|
||||
.then(function (app) {
|
||||
return Bluebird.join(
|
||||
return Promise.all([
|
||||
dockerUtils.getDocker(options),
|
||||
dockerUtils.generateBuildOpts(options),
|
||||
compose.generateOpts(options),
|
||||
(docker, buildOpts, composeOpts) =>
|
||||
deployProject(docker, logger, composeOpts, {
|
||||
app,
|
||||
appName, // may be prefixed by 'owner/', unlike app.app_name
|
||||
image,
|
||||
shouldPerformBuild: !!options.build,
|
||||
shouldUploadLogs: !options.nologupload,
|
||||
buildEmulated: !!options.emulated,
|
||||
buildOpts,
|
||||
}),
|
||||
]).then(([docker, buildOpts, composeOpts]) =>
|
||||
deployProject(docker, logger, composeOpts, {
|
||||
app,
|
||||
appName, // may be prefixed by 'owner/', unlike app.app_name
|
||||
image,
|
||||
shouldPerformBuild: !!options.build,
|
||||
shouldUploadLogs: !options.nologupload,
|
||||
buildEmulated: !!options.emulated,
|
||||
buildOpts,
|
||||
}),
|
||||
);
|
||||
});
|
||||
},
|
||||
|
@ -368,33 +368,32 @@ export const push: CommandDefinition<
|
||||
|
||||
const app = appOrDevice;
|
||||
await checkLoggedIn();
|
||||
await Bluebird.join(
|
||||
const [token, baseUrl, owner] = await Promise.all([
|
||||
sdk.auth.getToken(),
|
||||
sdk.settings.get('balenaUrl'),
|
||||
getAppOwner(sdk, app),
|
||||
async (token, baseUrl, owner) => {
|
||||
const opts = {
|
||||
dockerfilePath,
|
||||
emulated: options.emulated || false,
|
||||
multiDockerignore: options['multi-dockerignore'] || false,
|
||||
nocache: options.nocache || false,
|
||||
registrySecrets,
|
||||
headless: options.detached || false,
|
||||
convertEol,
|
||||
};
|
||||
const args = {
|
||||
app,
|
||||
owner,
|
||||
source,
|
||||
auth: token,
|
||||
baseUrl,
|
||||
nogitignore,
|
||||
sdk,
|
||||
opts,
|
||||
};
|
||||
return await remote.startRemoteBuild(args);
|
||||
},
|
||||
);
|
||||
]);
|
||||
|
||||
const opts = {
|
||||
dockerfilePath,
|
||||
emulated: options.emulated || false,
|
||||
multiDockerignore: options['multi-dockerignore'] || false,
|
||||
nocache: options.nocache || false,
|
||||
registrySecrets,
|
||||
headless: options.detached || false,
|
||||
convertEol,
|
||||
};
|
||||
const args = {
|
||||
app,
|
||||
owner,
|
||||
source,
|
||||
auth: token,
|
||||
baseUrl,
|
||||
nogitignore,
|
||||
sdk,
|
||||
opts,
|
||||
};
|
||||
await remote.startRemoteBuild(args);
|
||||
break;
|
||||
case BuildTarget.Device:
|
||||
const device = appOrDevice;
|
||||
|
@ -64,7 +64,7 @@ export const login = async () => {
|
||||
}, 1000);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const token = await awaitForToken(options)
|
||||
const token = await awaitForToken(options);
|
||||
await balena.auth.loginWithToken(token);
|
||||
return token
|
||||
return token;
|
||||
};
|
||||
|
@ -269,11 +269,8 @@ function originalTarDirectory(dir, param) {
|
||||
.filter(ignore.filter)
|
||||
.map(function (file) {
|
||||
const relPath = path.relative(path.resolve(dir), file);
|
||||
return Bluebird.join(
|
||||
relPath,
|
||||
fs.stat(file),
|
||||
readFile(file),
|
||||
(filename, stats, data) =>
|
||||
return Promise.all([relPath, fs.stat(file), readFile(file)]).then(
|
||||
([filename, stats, data]) =>
|
||||
pack.entry(
|
||||
{
|
||||
name: toPosixPath(filename),
|
||||
@ -750,7 +747,7 @@ export const pushAndUpdateServiceImages = function (
|
||||
return Bluebird.using(tty.cursorHidden(), () =>
|
||||
Promise.all(
|
||||
images.map(({ serviceImage, localImage, props, logs }, index) =>
|
||||
Bluebird.join(
|
||||
Promise.all([
|
||||
// @ts-ignore
|
||||
localImage.inspect().get('Size'),
|
||||
retry(
|
||||
@ -762,26 +759,29 @@ export const pushAndUpdateServiceImages = function (
|
||||
2000, // `delayMs` - wait 2 seconds before the 1st retry
|
||||
1.4, // `backoffScaler` - wait multiplier for each retry
|
||||
).finally(renderer.end),
|
||||
/** @type {(size: number, digest: string) => void} */
|
||||
function (size, digest) {
|
||||
serviceImage.image_size = size;
|
||||
serviceImage.content_hash = digest;
|
||||
serviceImage.build_log = logs;
|
||||
serviceImage.dockerfile = props.dockerfile;
|
||||
serviceImage.project_type = props.projectType;
|
||||
if (props.startTime) {
|
||||
serviceImage.start_timestamp = props.startTime;
|
||||
}
|
||||
if (props.endTime) {
|
||||
serviceImage.end_timestamp = props.endTime;
|
||||
}
|
||||
serviceImage.push_timestamp = new Date();
|
||||
serviceImage.status = 'success';
|
||||
},
|
||||
)
|
||||
.tapCatch(function (e) {
|
||||
])
|
||||
.then(
|
||||
/** @type {([number, string]) => void} */
|
||||
function ([size, digest]) {
|
||||
serviceImage.image_size = size;
|
||||
serviceImage.content_hash = digest;
|
||||
serviceImage.build_log = logs;
|
||||
serviceImage.dockerfile = props.dockerfile;
|
||||
serviceImage.project_type = props.projectType;
|
||||
if (props.startTime) {
|
||||
serviceImage.start_timestamp = props.startTime;
|
||||
}
|
||||
if (props.endTime) {
|
||||
serviceImage.end_timestamp = props.endTime;
|
||||
}
|
||||
serviceImage.push_timestamp = new Date();
|
||||
serviceImage.status = 'success';
|
||||
},
|
||||
)
|
||||
.catch(function (e) {
|
||||
serviceImage.error_message = '' + e;
|
||||
serviceImage.status = 'failed';
|
||||
throw e;
|
||||
})
|
||||
.finally(() => afterEach?.(serviceImage, props)),
|
||||
),
|
||||
|
@ -36,14 +36,12 @@ const bufferImage = function (docker, imageId, bufferFile) {
|
||||
const image = docker.getImage(imageId);
|
||||
const imageMetadata = image.inspect();
|
||||
|
||||
return Bluebird.join(
|
||||
image.get(),
|
||||
imageMetadata.get('Size'),
|
||||
(imageStream, imageSize) =>
|
||||
return Promise.all([image.get(), imageMetadata.get('Size')]).then(
|
||||
([imageStream, imageSize]) =>
|
||||
streamUtils.buffer(imageStream, bufferFile).then((bufferedStream) => {
|
||||
// @ts-ignore adding an extra property
|
||||
bufferedStream.length = imageSize;
|
||||
return bufferedStream
|
||||
return bufferedStream;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
@ -146,22 +146,21 @@ export async function osProgressHandler(step: InitializeEmitter) {
|
||||
|
||||
export function getAppWithArch(
|
||||
applicationName: string,
|
||||
): Bluebird<BalenaSdk.Application & { arch: string }> {
|
||||
return Bluebird.join(
|
||||
): Promise<BalenaSdk.Application & { arch: string }> {
|
||||
return Promise.all([
|
||||
getApplication(applicationName),
|
||||
getBalenaSdk().models.config.getDeviceTypes(),
|
||||
function (app, deviceTypes) {
|
||||
const config = _.find<BalenaSdk.DeviceType>(deviceTypes, {
|
||||
slug: app.device_type,
|
||||
});
|
||||
]).then(function ([app, deviceTypes]) {
|
||||
const config = _.find<BalenaSdk.DeviceType>(deviceTypes, {
|
||||
slug: app.device_type,
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
throw new Error('Could not read application information!');
|
||||
}
|
||||
if (!config) {
|
||||
throw new Error('Could not read application information!');
|
||||
}
|
||||
|
||||
return { ...app, arch: config.arch };
|
||||
},
|
||||
);
|
||||
return { ...app, arch: config.arch };
|
||||
});
|
||||
}
|
||||
|
||||
function getApplication(applicationName: string) {
|
||||
|
@ -74,7 +74,7 @@ export const tunnelConnectionToDevice = (
|
||||
})
|
||||
.catch((e) => {
|
||||
client.end();
|
||||
throw e
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user