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