mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-22 10:11:01 +00:00
Merge pull request #1902 from balena-io/reduce-bluebird
Reduce bluebird usage
This commit is contained in:
commit
4fc62017ae
@ -103,7 +103,8 @@ async function buildPkg() {
|
|||||||
['*', ['opn', 'xdg-open'], ['xdg-open-402']],
|
['*', ['opn', 'xdg-open'], ['xdg-open-402']],
|
||||||
['darwin', ['denymount', 'bin', 'denymount'], ['denymount']],
|
['darwin', ['denymount', 'bin', 'denymount'], ['denymount']],
|
||||||
];
|
];
|
||||||
await Bluebird.map(paths, ([platform, source, dest]) => {
|
await Promise.all(
|
||||||
|
paths.map(([platform, source, dest]) => {
|
||||||
if (platform === '*' || platform === process.platform) {
|
if (platform === '*' || platform === process.platform) {
|
||||||
// eg copy from node_modules/open/xdg-open to build-bin/xdg-open
|
// eg copy from node_modules/open/xdg-open to build-bin/xdg-open
|
||||||
return fs.copy(
|
return fs.copy(
|
||||||
@ -111,7 +112,8 @@ async function buildPkg() {
|
|||||||
path.join(ROOT, 'build-bin', ...dest),
|
path.join(ROOT, 'build-bin', ...dest),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
const nativeExtensionPaths: string[] = await filehound
|
const nativeExtensionPaths: string[] = await filehound
|
||||||
.create()
|
.create()
|
||||||
.paths(path.join(ROOT, 'node_modules'))
|
.paths(path.join(ROOT, 'node_modules'))
|
||||||
@ -120,7 +122,8 @@ async function buildPkg() {
|
|||||||
|
|
||||||
console.log(`\nCopying to build-bin:\n${nativeExtensionPaths.join('\n')}`);
|
console.log(`\nCopying to build-bin:\n${nativeExtensionPaths.join('\n')}`);
|
||||||
|
|
||||||
await Bluebird.map(nativeExtensionPaths, (extPath) =>
|
await Promise.all(
|
||||||
|
nativeExtensionPaths.map((extPath) =>
|
||||||
fs.copy(
|
fs.copy(
|
||||||
extPath,
|
extPath,
|
||||||
extPath.replace(
|
extPath.replace(
|
||||||
@ -128,6 +131,7 @@ async function buildPkg() {
|
|||||||
path.join(ROOT, 'build-bin'),
|
path.join(ROOT, 'build-bin'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import { flags } from '@oclif/command';
|
import { flags } from '@oclif/command';
|
||||||
import type * as BalenaSdk from 'balena-sdk';
|
import type * as BalenaSdk from 'balena-sdk';
|
||||||
import Bluebird = require('bluebird');
|
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import Command from '../../command';
|
import Command from '../../command';
|
||||||
@ -263,9 +262,8 @@ export default class OsConfigureCmd extends Command {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (options['system-connection']) {
|
if (options['system-connection']) {
|
||||||
const files = await Bluebird.map(
|
const files = await Promise.all(
|
||||||
options['system-connection'],
|
options['system-connection'].map(async (filePath) => {
|
||||||
async (filePath) => {
|
|
||||||
const content = await fs.readFile(filePath, 'utf8');
|
const content = await fs.readFile(filePath, 'utf8');
|
||||||
const name = path.basename(filePath);
|
const name = path.basename(filePath);
|
||||||
|
|
||||||
@ -273,10 +271,10 @@ export default class OsConfigureCmd extends Command {
|
|||||||
name,
|
name,
|
||||||
content,
|
content,
|
||||||
};
|
};
|
||||||
},
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
await Bluebird.each(files, async ({ name, content }) => {
|
for (const { name, content } of files) {
|
||||||
await imagefs.writeFile(
|
await imagefs.writeFile(
|
||||||
{
|
{
|
||||||
image,
|
image,
|
||||||
@ -286,7 +284,7 @@ export default class OsConfigureCmd extends Command {
|
|||||||
content,
|
content,
|
||||||
);
|
);
|
||||||
console.info(`Copied system-connection file: ${name}`);
|
console.info(`Copied system-connection file: ${name}`);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,9 +105,8 @@ export default class ScanCmd extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query devices for info
|
// Query devices for info
|
||||||
const devicesInfo = await Bluebird.map(
|
const devicesInfo = await Promise.all(
|
||||||
activeLocalDevices,
|
activeLocalDevices.map(({ host, address }) => {
|
||||||
({ host, address }) => {
|
|
||||||
const docker = dockerUtils.createClient({
|
const docker = dockerUtils.createClient({
|
||||||
host: address,
|
host: address,
|
||||||
port: dockerPort,
|
port: dockerPort,
|
||||||
@ -123,7 +122,7 @@ export default class ScanCmd extends Command {
|
|||||||
.versionAsync()
|
.versionAsync()
|
||||||
.catchReturn('Could not get Docker version'),
|
.catchReturn('Could not get Docker version'),
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reduce properties if not --verbose
|
// Reduce properties if not --verbose
|
||||||
|
@ -194,11 +194,11 @@ 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,
|
||||||
|
@ -150,11 +150,11 @@ 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,
|
||||||
@ -302,11 +302,11 @@ 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
|
||||||
|
@ -255,8 +255,6 @@ Examples:
|
|||||||
primary: true,
|
primary: true,
|
||||||
options: preloadOptions,
|
options: preloadOptions,
|
||||||
action(params, options, done) {
|
action(params, options, done) {
|
||||||
let certificates;
|
|
||||||
const Bluebird = require('bluebird');
|
|
||||||
const balena = getBalenaSdk();
|
const balena = getBalenaSdk();
|
||||||
const balenaPreload = require('balena-preload');
|
const balenaPreload = require('balena-preload');
|
||||||
const visuals = getVisuals();
|
const visuals = getVisuals();
|
||||||
@ -309,6 +307,7 @@ Examples:
|
|||||||
options.pinDevice = options['pin-device-to-release'] || false;
|
options.pinDevice = options['pin-device-to-release'] || false;
|
||||||
delete options['pin-device-to-release'];
|
delete options['pin-device-to-release'];
|
||||||
|
|
||||||
|
let certificates;
|
||||||
if (Array.isArray(options['add-certificate'])) {
|
if (Array.isArray(options['add-certificate'])) {
|
||||||
certificates = options['add-certificate'];
|
certificates = options['add-certificate'];
|
||||||
} else if (options['add-certificate'] === undefined) {
|
} else if (options['add-certificate'] === undefined) {
|
||||||
@ -358,7 +357,7 @@ Examples:
|
|||||||
preloader.on('progress', progressHandler);
|
preloader.on('progress', progressHandler);
|
||||||
preloader.on('spinner', spinnerHandler);
|
preloader.on('spinner', spinnerHandler);
|
||||||
|
|
||||||
return new Bluebird(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
preloader.on('error', reject);
|
preloader.on('error', reject);
|
||||||
|
|
||||||
return preloader
|
return preloader
|
||||||
|
@ -368,11 +368,12 @@ 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 = {
|
const opts = {
|
||||||
dockerfilePath,
|
dockerfilePath,
|
||||||
emulated: options.emulated || false,
|
emulated: options.emulated || false,
|
||||||
@ -392,9 +393,7 @@ export const push: CommandDefinition<
|
|||||||
sdk,
|
sdk,
|
||||||
opts,
|
opts,
|
||||||
};
|
};
|
||||||
return await remote.startRemoteBuild(args);
|
await remote.startRemoteBuild(args);
|
||||||
},
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case BuildTarget.Device:
|
case BuildTarget.Device:
|
||||||
const device = appOrDevice;
|
const device = appOrDevice;
|
||||||
|
@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import type { CommandDefinition } from 'capitano';
|
import type { CommandDefinition } from 'capitano';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { createServer, Server, Socket } from 'net';
|
import { createServer, Server, Socket } from 'net';
|
||||||
@ -196,7 +195,7 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
|||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
(server) =>
|
(server) =>
|
||||||
new Bluebird.Promise<Server>((resolve, reject) => {
|
new Promise<Server>((resolve, reject) => {
|
||||||
server.on('error', reject);
|
server.on('error', reject);
|
||||||
server.listen(localPort, localAddress, () => {
|
server.listen(localPort, localAddress, () => {
|
||||||
resolve(server);
|
resolve(server);
|
||||||
|
@ -64,5 +64,7 @@ export const login = async () => {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
const balena = getBalenaSdk();
|
const balena = getBalenaSdk();
|
||||||
return awaitForToken(options).tap(balena.auth.loginWithToken);
|
const token = await awaitForToken(options);
|
||||||
|
await balena.auth.loginWithToken(token);
|
||||||
|
return token;
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import type { Socket } from 'net';
|
import type { Socket } from 'net';
|
||||||
@ -79,10 +78,10 @@ export function shutdownServer() {
|
|||||||
export const awaitForToken = (options: {
|
export const awaitForToken = (options: {
|
||||||
path: string;
|
path: string;
|
||||||
port: number;
|
port: number;
|
||||||
}): Bluebird<string> => {
|
}): Promise<string> => {
|
||||||
const { app, server } = createServer({ port: options.port });
|
const { app, server } = createServer({ port: options.port });
|
||||||
|
|
||||||
return new Bluebird<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
app.post(options.path, async (request, response) => {
|
app.post(options.path, async (request, response) => {
|
||||||
server.close(); // stop listening for new connections
|
server.close(); // stop listening for new connections
|
||||||
try {
|
try {
|
||||||
|
@ -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),
|
||||||
@ -367,13 +364,15 @@ export function buildProject(
|
|||||||
}
|
}
|
||||||
logger.logInfo('Emulation is enabled');
|
logger.logInfo('Emulation is enabled');
|
||||||
// Copy qemu into all build contexts
|
// Copy qemu into all build contexts
|
||||||
return Bluebird.map(imageDescriptors, function (d) {
|
return Promise.all(
|
||||||
|
imageDescriptors.map(function (d) {
|
||||||
if (typeof d.image === 'string' || d.image.context == null) {
|
if (typeof d.image === 'string' || d.image.context == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// external image
|
// external image
|
||||||
return qemu.copyQemu(path.join(projectPath, d.image.context), arch);
|
return qemu.copyQemu(path.join(projectPath, d.image.context), arch);
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.then((
|
.then((
|
||||||
needsQemu, // Tar up the directory, ready for the build stream
|
needsQemu, // Tar up the directory, ready for the build stream
|
||||||
@ -488,9 +487,11 @@ export function buildProject(
|
|||||||
})
|
})
|
||||||
.then(function (tasks) {
|
.then(function (tasks) {
|
||||||
logger.logDebug('Prepared tasks; building...');
|
logger.logDebug('Prepared tasks; building...');
|
||||||
return Bluebird.map(
|
return builder
|
||||||
builder.performBuilds(tasks, docker, BALENA_ENGINE_TMP_PATH),
|
.performBuilds(tasks, docker, BALENA_ENGINE_TMP_PATH)
|
||||||
function (builtImage) {
|
.then(function (builtImages) {
|
||||||
|
return Promise.all(
|
||||||
|
builtImages.map(function (builtImage) {
|
||||||
if (!builtImage.successful) {
|
if (!builtImage.successful) {
|
||||||
/** @type {Error & {serviceName?: string}} */
|
/** @type {Error & {serviceName?: string}} */
|
||||||
const error = builtImage.error ?? new Error();
|
const error = builtImage.error ?? new Error();
|
||||||
@ -499,7 +500,9 @@ export function buildProject(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const d = imageDescriptorsByServiceName[builtImage.serviceName];
|
const d = imageDescriptorsByServiceName[builtImage.serviceName];
|
||||||
const task = _.find(tasks, { serviceName: builtImage.serviceName });
|
const task = _.find(tasks, {
|
||||||
|
serviceName: builtImage.serviceName,
|
||||||
|
});
|
||||||
|
|
||||||
const image = {
|
const image = {
|
||||||
serviceName: d.serviceName,
|
serviceName: d.serviceName,
|
||||||
@ -528,8 +531,10 @@ export function buildProject(
|
|||||||
image.props.size = size;
|
image.props.size = size;
|
||||||
})
|
})
|
||||||
.return(image);
|
.return(image);
|
||||||
},
|
}),
|
||||||
).tap(function (images) {
|
);
|
||||||
|
})
|
||||||
|
.then(function (images) {
|
||||||
const summary = _(images)
|
const summary = _(images)
|
||||||
.map(({ serviceName, props }) => [
|
.map(({ serviceName, props }) => [
|
||||||
serviceName,
|
serviceName,
|
||||||
@ -538,6 +543,7 @@ export function buildProject(
|
|||||||
.fromPairs()
|
.fromPairs()
|
||||||
.value();
|
.value();
|
||||||
renderer.end(summary);
|
renderer.end(summary);
|
||||||
|
return images;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.finally(renderer.end);
|
.finally(renderer.end);
|
||||||
@ -598,10 +604,11 @@ export const createRelease = function (
|
|||||||
* @param {import('docker-toolbelt')} docker
|
* @param {import('docker-toolbelt')} docker
|
||||||
* @param {Array<import('./compose-types').BuiltImage>} images
|
* @param {Array<import('./compose-types').BuiltImage>} images
|
||||||
* @param {Partial<import('balena-release/build/models').ImageModel>} serviceImages
|
* @param {Partial<import('balena-release/build/models').ImageModel>} serviceImages
|
||||||
* @returns {Bluebird<Array<import('./compose-types').TaggedImage>>}
|
* @returns {Promise<Array<import('./compose-types').TaggedImage>>}
|
||||||
*/
|
*/
|
||||||
export const tagServiceImages = (docker, images, serviceImages) =>
|
export const tagServiceImages = (docker, images, serviceImages) =>
|
||||||
Bluebird.map(images, function (d) {
|
Promise.all(
|
||||||
|
images.map(function (d) {
|
||||||
const serviceImage = serviceImages[d.serviceName];
|
const serviceImage = serviceImages[d.serviceName];
|
||||||
const imageName = serviceImage.is_stored_at__image_location;
|
const imageName = serviceImage.is_stored_at__image_location;
|
||||||
const match = /(.*?)\/(.*?)(?::([^/]*))?$/.exec(imageName);
|
const match = /(.*?)\/(.*?)(?::([^/]*))?$/.exec(imageName);
|
||||||
@ -623,7 +630,8 @@ export const tagServiceImages = (docker, images, serviceImages) =>
|
|||||||
logs: d.logs,
|
logs: d.logs,
|
||||||
props: d.props,
|
props: d.props,
|
||||||
}));
|
}));
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {*} sdk
|
* @param {*} sdk
|
||||||
@ -655,15 +663,19 @@ export const getPreviousRepos = (sdk, docker, logger, appID) =>
|
|||||||
// grab all images from the latest release, return all image locations in the registry
|
// grab all images from the latest release, return all image locations in the registry
|
||||||
if (release.length > 0) {
|
if (release.length > 0) {
|
||||||
const images = release[0].contains__image;
|
const images = release[0].contains__image;
|
||||||
return Bluebird.map(images, function (d) {
|
return Promise.all(
|
||||||
|
images.map(function (d) {
|
||||||
const imageName = d.image[0].is_stored_at__image_location;
|
const imageName = d.image[0].is_stored_at__image_location;
|
||||||
return docker.getRegistryAndName(imageName).then(function (registry) {
|
return docker
|
||||||
|
.getRegistryAndName(imageName)
|
||||||
|
.then(function (registry) {
|
||||||
logger.logDebug(
|
logger.logDebug(
|
||||||
`Requesting access to previously pushed image repo (${registry.imageName})`,
|
`Requesting access to previously pushed image repo (${registry.imageName})`,
|
||||||
);
|
);
|
||||||
return registry.imageName;
|
return registry.imageName;
|
||||||
});
|
});
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -733,8 +745,9 @@ export const pushAndUpdateServiceImages = function (
|
|||||||
const reporters = progress.aggregateProgress(images.length, renderer);
|
const reporters = progress.aggregateProgress(images.length, renderer);
|
||||||
|
|
||||||
return Bluebird.using(tty.cursorHidden(), () =>
|
return Bluebird.using(tty.cursorHidden(), () =>
|
||||||
Bluebird.map(images, ({ serviceImage, localImage, props, logs }, index) =>
|
Promise.all(
|
||||||
Bluebird.join(
|
images.map(({ serviceImage, localImage, props, logs }, index) =>
|
||||||
|
Promise.all([
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
localImage.inspect().get('Size'),
|
localImage.inspect().get('Size'),
|
||||||
retry(
|
retry(
|
||||||
@ -746,8 +759,10 @@ 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(
|
||||||
|
/** @type {([number, string]) => void} */
|
||||||
|
function ([size, digest]) {
|
||||||
serviceImage.image_size = size;
|
serviceImage.image_size = size;
|
||||||
serviceImage.content_hash = digest;
|
serviceImage.content_hash = digest;
|
||||||
serviceImage.build_log = logs;
|
serviceImage.build_log = logs;
|
||||||
@ -763,12 +778,14 @@ export const pushAndUpdateServiceImages = function (
|
|||||||
serviceImage.status = 'success';
|
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)),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -843,7 +843,9 @@ export async function deployProject(
|
|||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
logger.logDebug('Untagging images...');
|
logger.logDebug('Untagging images...');
|
||||||
await Bluebird.map(taggedImages, ({ localImage }) => localImage.remove());
|
await Promise.all(
|
||||||
|
taggedImages.map(({ localImage }) => localImage.remove()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
runloop = runSpinner(tty, spinner, `${prefix}Saving release...`);
|
runloop = runSpinner(tty, spinner, `${prefix}Saving release...`);
|
||||||
|
@ -36,13 +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'),
|
streamUtils.buffer(imageStream, bufferFile).then((bufferedStream) => {
|
||||||
(imageStream, imageSize) =>
|
|
||||||
streamUtils.buffer(imageStream, bufferFile).tap((bufferedStream) => {
|
|
||||||
// @ts-ignore adding an extra property
|
// @ts-ignore adding an extra property
|
||||||
bufferedStream.length = imageSize;
|
bufferedStream.length = imageSize;
|
||||||
|
return bufferedStream;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -55,7 +54,7 @@ const showPushProgress = function (message) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const uploadToPromise = (uploadRequest, logger) =>
|
const uploadToPromise = (uploadRequest, logger) =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const handleMessage = function (data) {
|
const handleMessage = function (data) {
|
||||||
let obj;
|
let obj;
|
||||||
data = data.toString();
|
data = data.toString();
|
||||||
@ -88,7 +87,7 @@ const uploadToPromise = (uploadRequest, logger) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Bluebird<{ buildId: number }>}
|
* @returns {Promise<{ buildId: number }>}
|
||||||
*/
|
*/
|
||||||
const uploadImage = function (
|
const uploadImage = function (
|
||||||
imageStream,
|
imageStream,
|
||||||
|
@ -194,11 +194,11 @@ export class DeviceAPI {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLogStream(): Bluebird<Stream.Readable> {
|
public getLogStream(): Promise<Stream.Readable> {
|
||||||
const url = this.getUrlForAction('logs');
|
const url = this.getUrlForAction('logs');
|
||||||
|
|
||||||
// Don't use the promisified version here as we want to stream the output
|
// Don't use the promisified version here as we want to stream the output
|
||||||
return new Bluebird((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = request.get(url);
|
const req = request.get(url);
|
||||||
|
|
||||||
req.on('error', reject).on('response', async (res) => {
|
req.on('error', reject).on('response', async (res) => {
|
||||||
|
@ -361,7 +361,8 @@ export async function performBuilds(
|
|||||||
|
|
||||||
// Now tag any external images with the correct name that they should be,
|
// Now tag any external images with the correct name that they should be,
|
||||||
// as this won't be done by resin-multibuild
|
// as this won't be done by resin-multibuild
|
||||||
await Bluebird.map(localImages, async (localImage) => {
|
await Promise.all(
|
||||||
|
localImages.map(async (localImage) => {
|
||||||
if (localImage.external) {
|
if (localImage.external) {
|
||||||
// We can be sure that localImage.name is set here, because of the failure code above
|
// We can be sure that localImage.name is set here, because of the failure code above
|
||||||
const image = docker.getImage(localImage.name!);
|
const image = docker.getImage(localImage.name!);
|
||||||
@ -371,10 +372,13 @@ export async function performBuilds(
|
|||||||
});
|
});
|
||||||
imagesToRemove.push(localImage.name!);
|
imagesToRemove.push(localImage.name!);
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
await Bluebird.map(_.uniq(imagesToRemove), (image) =>
|
await Promise.all(
|
||||||
|
_.uniq(imagesToRemove).map((image) =>
|
||||||
docker.getImage(image).remove({ force: true }),
|
docker.getImage(image).remove({ force: true }),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return buildTasks;
|
return buildTasks;
|
||||||
@ -512,7 +516,8 @@ async function assignDockerBuildOpts(
|
|||||||
|
|
||||||
globalLogger.logDebug(`Using ${images.length} on-device images for cache...`);
|
globalLogger.logDebug(`Using ${images.length} on-device images for cache...`);
|
||||||
|
|
||||||
await Bluebird.map(buildTasks, async (task: BuildTask) => {
|
await Promise.all(
|
||||||
|
buildTasks.map(async (task: BuildTask) => {
|
||||||
task.dockerOpts = {
|
task.dockerOpts = {
|
||||||
cachefrom: images,
|
cachefrom: images,
|
||||||
labels: {
|
labels: {
|
||||||
@ -531,7 +536,8 @@ async function assignDockerBuildOpts(
|
|||||||
} else {
|
} else {
|
||||||
task.dockerOpts.registryconfig = opts.registrySecrets;
|
task.dockerOpts.registryconfig = opts.registrySecrets;
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateImageName(serviceName: string): string {
|
function generateImageName(serviceName: string): string {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import ColorHash = require('color-hash');
|
import ColorHash = require('color-hash');
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import type { Readable } from 'stream';
|
import type { Readable } from 'stream';
|
||||||
@ -38,8 +37,8 @@ export function displayDeviceLogs(
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
system: boolean,
|
system: boolean,
|
||||||
filterServices?: string[],
|
filterServices?: string[],
|
||||||
): Bluebird<void> {
|
): Promise<void> {
|
||||||
return new Bluebird((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logs.on('data', (log) => {
|
logs.on('data', (log) => {
|
||||||
displayLogLine(log, logger, system, filterServices);
|
displayLogLine(log, logger, system, filterServices);
|
||||||
});
|
});
|
||||||
|
@ -146,11 +146,11 @@ 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,
|
||||||
});
|
});
|
||||||
@ -160,8 +160,7 @@ export function getAppWithArch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { ...app, arch: config.arch };
|
return { ...app, arch: config.arch };
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getApplication(applicationName: string) {
|
function getApplication(applicationName: string) {
|
||||||
|
@ -44,7 +44,7 @@ export function copyQemu(context: string, arch: string) {
|
|||||||
.then(() => getQemuPath(arch))
|
.then(() => getQemuPath(arch))
|
||||||
.then(
|
.then(
|
||||||
(qemu) =>
|
(qemu) =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const read = fs.createReadStream(qemu);
|
const read = fs.createReadStream(qemu);
|
||||||
const write = fs.createWriteStream(binPath);
|
const write = fs.createWriteStream(binPath);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export function installQemu(arch: string) {
|
|||||||
|
|
||||||
return getQemuPath(arch).then(
|
return getQemuPath(arch).then(
|
||||||
(qemuPath) =>
|
(qemuPath) =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const installStream = fs.createWriteStream(qemuPath);
|
const installStream = fs.createWriteStream(qemuPath);
|
||||||
|
|
||||||
const qemuArch = balenaArchToQemuArch(arch);
|
const qemuArch = balenaArchToQemuArch(arch);
|
||||||
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import type { BalenaSDK } from 'balena-sdk';
|
import type { BalenaSDK } from 'balena-sdk';
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import * as JSONStream from 'JSONStream';
|
import * as JSONStream from 'JSONStream';
|
||||||
import * as readline from 'readline';
|
import * as readline from 'readline';
|
||||||
import * as request from 'request';
|
import * as request from 'request';
|
||||||
@ -124,7 +123,7 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!build.opts.headless) {
|
if (!build.opts.headless) {
|
||||||
return new Bluebird((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Setup interrupt handlers so we can cancel the build if the user presses
|
// Setup interrupt handlers so we can cancel the build if the user presses
|
||||||
// ctrl+c
|
// ctrl+c
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import { spawn, StdioOptions } from 'child_process';
|
import { spawn, StdioOptions } from 'child_process';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { TypedError } from 'typed-error';
|
import { TypedError } from 'typed-error';
|
||||||
@ -71,7 +70,7 @@ export async function exec(
|
|||||||
'inherit',
|
'inherit',
|
||||||
];
|
];
|
||||||
|
|
||||||
const exitCode = await new Bluebird<number>((resolve, reject) => {
|
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||||
const ps = spawn(program, args, { stdio })
|
const ps = spawn(program, args, { stdio })
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('close', resolve);
|
.on('close', resolve);
|
||||||
|
@ -14,20 +14,19 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import Bluebird = require('bluebird');
|
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
|
|
||||||
export function buffer(
|
export function buffer(
|
||||||
stream: NodeJS.ReadableStream,
|
stream: NodeJS.ReadableStream,
|
||||||
bufferFile: string,
|
bufferFile: string,
|
||||||
): Bluebird<NodeJS.ReadableStream> {
|
): Promise<NodeJS.ReadableStream> {
|
||||||
const fileWriteStream = fs.createWriteStream(bufferFile);
|
const fileWriteStream = fs.createWriteStream(bufferFile);
|
||||||
|
|
||||||
return new Bluebird(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
stream.on('error', reject).on('end', resolve).pipe(fileWriteStream);
|
stream.on('error', reject).on('end', resolve).pipe(fileWriteStream);
|
||||||
}).then(
|
}).then(
|
||||||
() =>
|
() =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const fstream = fs.createReadStream(bufferFile);
|
const fstream = fs.createReadStream(bufferFile);
|
||||||
|
|
||||||
fstream.on('open', () => resolve(fstream)).on('error', reject);
|
fstream.on('open', () => resolve(fstream)).on('error', reject);
|
||||||
|
@ -52,7 +52,7 @@ export const tunnelConnectionToDevice = (
|
|||||||
password: token,
|
password: token,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (client: Socket): Bluebird<void> =>
|
return (client: Socket): Promise<void> =>
|
||||||
openPortThroughProxy(vpnUrl, 3128, auth, uuid, port)
|
openPortThroughProxy(vpnUrl, 3128, auth, uuid, port)
|
||||||
.then((remote) => {
|
.then((remote) => {
|
||||||
client.pipe(remote);
|
client.pipe(remote);
|
||||||
@ -72,8 +72,9 @@ export const tunnelConnectionToDevice = (
|
|||||||
remote.end();
|
remote.end();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.tapCatch(() => {
|
.catch((e) => {
|
||||||
client.end();
|
client.end();
|
||||||
|
throw e;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -95,7 +96,7 @@ const openPortThroughProxy = (
|
|||||||
httpHeaders.push(`Proxy-Authorization: Basic ${credentials}`);
|
httpHeaders.push(`Proxy-Authorization: Basic ${credentials}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Bluebird.Promise<Socket>((resolve, reject) => {
|
return new Promise<Socket>((resolve, reject) => {
|
||||||
const proxyTunnel = new Socket();
|
const proxyTunnel = new Socket();
|
||||||
proxyTunnel.on('error', reject);
|
proxyTunnel.on('error', reject);
|
||||||
proxyTunnel.connect(proxyPort, proxyServer, () => {
|
proxyTunnel.connect(proxyPort, proxyServer, () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user