mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Remove some bluebird usage
Change-type: patch
This commit is contained in:
parent
41e7ba12ff
commit
9aacb7ec56
@ -59,13 +59,13 @@ export default class LocalConfigureCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = this.parse<FlagsDef, ArgsDef>(LocalConfigureCmd);
|
||||
|
||||
const Bluebird = await import('bluebird');
|
||||
const { promisify } = await import('util');
|
||||
const path = await import('path');
|
||||
const umount = await import('umount');
|
||||
const umountAsync = Bluebird.promisify(umount.umount);
|
||||
const isMountedAsync = Bluebird.promisify(umount.isMounted);
|
||||
const umountAsync = promisify(umount.umount);
|
||||
const isMountedAsync = promisify(umount.isMounted);
|
||||
const reconfix = await import('reconfix');
|
||||
const denymount = Bluebird.promisify(await import('denymount'));
|
||||
const denymount = promisify(await import('denymount'));
|
||||
const Logger = await import('../../utils/logger');
|
||||
|
||||
const logger = Logger.getLogger();
|
||||
|
@ -42,10 +42,9 @@ const applicationExpandOptions = {
|
||||
};
|
||||
|
||||
let allDeviceTypes;
|
||||
const getDeviceTypes = function () {
|
||||
const Bluebird = require('bluebird');
|
||||
const getDeviceTypes = async function () {
|
||||
if (allDeviceTypes !== undefined) {
|
||||
return Bluebird.resolve(allDeviceTypes);
|
||||
return allDeviceTypes;
|
||||
}
|
||||
const balena = getBalenaSdk();
|
||||
return balena.models.config
|
||||
@ -154,12 +153,11 @@ const selectApplicationCommit = function (releases) {
|
||||
});
|
||||
};
|
||||
|
||||
const offerToDisableAutomaticUpdates = function (
|
||||
const offerToDisableAutomaticUpdates = async function (
|
||||
application,
|
||||
commit,
|
||||
pinDevice,
|
||||
) {
|
||||
const Bluebird = require('bluebird');
|
||||
const balena = getBalenaSdk();
|
||||
|
||||
if (
|
||||
@ -167,7 +165,7 @@ const offerToDisableAutomaticUpdates = function (
|
||||
!application.should_track_latest_release ||
|
||||
pinDevice
|
||||
) {
|
||||
return Bluebird.resolve();
|
||||
return;
|
||||
}
|
||||
const message = `\
|
||||
|
||||
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as _ from 'lodash';
|
||||
import * as url from 'url';
|
||||
import { getBalenaSdk } from '../utils/lazy';
|
||||
@ -26,7 +25,7 @@ import { getBalenaSdk } from '../utils/lazy';
|
||||
*
|
||||
* @param {String} callbackUrl - callback url
|
||||
* @fulfil {String} - dashboard login url
|
||||
* @returns {Bluebird}
|
||||
* @returns {Promise}
|
||||
*
|
||||
* @example
|
||||
* utils.getDashboardLoginURL('http://127.0.0.1:3000').then (url) ->
|
||||
@ -58,15 +57,15 @@ export const getDashboardLoginURL = (callbackUrl: string) => {
|
||||
*
|
||||
* @param {String} token - session token or api key
|
||||
* @fulfil {Boolean} - whether the login was successful or not
|
||||
* @returns {Bluebird}
|
||||
* @returns {Promise}
|
||||
*
|
||||
* utils.loginIfTokenValid('...').then (loggedIn) ->
|
||||
* if loggedIn
|
||||
* console.log('Token is valid!')
|
||||
*/
|
||||
export const loginIfTokenValid = (token: string) => {
|
||||
export const loginIfTokenValid = async (token: string) => {
|
||||
if (_.isEmpty(token?.trim())) {
|
||||
return Bluebird.resolve(false);
|
||||
return false;
|
||||
}
|
||||
const balena = getBalenaSdk();
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BalenaSDK } from 'balena-sdk';
|
||||
import * as Bluebird from 'bluebird';
|
||||
import type * as Dockerode from 'dockerode';
|
||||
import * as _ from 'lodash';
|
||||
import { promises as fs } from 'fs';
|
||||
@ -249,7 +248,7 @@ export async function tarDirectory(
|
||||
preFinalizeCallback,
|
||||
}: TarDirectoryOptions,
|
||||
): Promise<import('stream').Readable> {
|
||||
(await import('assert')).strict.strictEqual(nogitignore, true);
|
||||
(await import('assert')).strict.equal(nogitignore, true);
|
||||
const { filterFilesWithDockerignore } = await import('./ignore');
|
||||
const { toPosixPath } = (await import('resin-multibuild')).PathUtils;
|
||||
|
||||
@ -558,30 +557,34 @@ async function performResolution(
|
||||
},
|
||||
preprocessHook,
|
||||
);
|
||||
// Do one task at a time (Bluebird.each instead of Bluebird.all)
|
||||
// in order to reduce peak memory usage. Resolves to buildTasks.
|
||||
Bluebird.each(buildTasks, (buildTask) => {
|
||||
(async () => {
|
||||
try {
|
||||
// Do one task at a time in order to reduce peak memory usage. Resolves to buildTasks.
|
||||
for (const buildTask of buildTasks) {
|
||||
// buildStream is falsy for "external" tasks (image pull)
|
||||
if (!buildTask.buildStream) {
|
||||
return buildTask;
|
||||
continue;
|
||||
}
|
||||
// Consume each task.buildStream in order to trigger the
|
||||
// resolution events that define fields like:
|
||||
// task.dockerfile, task.dockerfilePath,
|
||||
// task.projectType, task.resolved
|
||||
// This mimics what is currently done in `resin-builder`.
|
||||
return cloneTarStream(buildTask.buildStream).then(
|
||||
(clonedStream: tar.Pack) => {
|
||||
const clonedStream: tar.Pack = await cloneTarStream(
|
||||
buildTask.buildStream,
|
||||
);
|
||||
buildTask.buildStream = clonedStream;
|
||||
if (!buildTask.external && !buildTask.resolved) {
|
||||
throw new ExpectedError(
|
||||
`Project type for service "${buildTask.serviceName}" could not be determined. Missing a Dockerfile?`,
|
||||
);
|
||||
}
|
||||
return buildTask;
|
||||
},
|
||||
);
|
||||
}).then(resolve, reject);
|
||||
}
|
||||
resolve(buildTasks);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ limitations under the License.
|
||||
*/
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
import * as semver from 'balena-semver';
|
||||
import Bluebird = require('bluebird');
|
||||
import { getBalenaSdk } from './lazy';
|
||||
|
||||
export interface ImgConfig {
|
||||
@ -52,7 +51,7 @@ export interface ImgConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export function generateBaseConfig(
|
||||
export async function generateBaseConfig(
|
||||
application: BalenaSdk.Application,
|
||||
options: {
|
||||
version: string;
|
||||
@ -62,17 +61,16 @@ export function generateBaseConfig(
|
||||
sshKeys?: string[];
|
||||
};
|
||||
},
|
||||
): Bluebird<ImgConfig> {
|
||||
): Promise<ImgConfig> {
|
||||
options = {
|
||||
...options,
|
||||
appUpdatePollInterval: options.appUpdatePollInterval || 10,
|
||||
};
|
||||
|
||||
const promise = getBalenaSdk().models.os.getConfig(
|
||||
const config = (await getBalenaSdk().models.os.getConfig(
|
||||
application.app_name,
|
||||
options,
|
||||
) as Bluebird<ImgConfig & { apiKey?: string }>;
|
||||
return promise.tap((config) => {
|
||||
)) as ImgConfig & { apiKey?: string };
|
||||
// os.getConfig always returns a config for an app
|
||||
delete config.apiKey;
|
||||
|
||||
@ -84,19 +82,23 @@ export function generateBaseConfig(
|
||||
? [...config.os.sshKeys, ...options.os.sshKeys]
|
||||
: options.os.sshKeys;
|
||||
}
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function generateApplicationConfig(
|
||||
export async function generateApplicationConfig(
|
||||
application: BalenaSdk.Application,
|
||||
options: { version: string; deviceType?: string },
|
||||
) {
|
||||
return generateBaseConfig(application, options).tap((config) => {
|
||||
const config = await generateBaseConfig(application, options);
|
||||
|
||||
if (semver.satisfies(options.version, '<2.7.8')) {
|
||||
return addApplicationKey(config, application.id);
|
||||
await addApplicationKey(config, application.id);
|
||||
} else {
|
||||
await addProvisioningKey(config, application.id);
|
||||
}
|
||||
return addProvisioningKey(config, application.id);
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function generateDeviceConfig(
|
||||
@ -108,20 +110,20 @@ export function generateDeviceConfig(
|
||||
) {
|
||||
return getBalenaSdk()
|
||||
.models.application.get(device.belongs_to__application.__id)
|
||||
.then((application) => {
|
||||
.then(async (application) => {
|
||||
const baseConfigOpts = {
|
||||
...options,
|
||||
deviceType: device.device_type,
|
||||
};
|
||||
return generateBaseConfig(application, baseConfigOpts).tap((config) => {
|
||||
if (
|
||||
deviceApiKey == null &&
|
||||
semver.satisfies(options.version, '<2.0.3')
|
||||
) {
|
||||
return addApplicationKey(config, application.id);
|
||||
const config = await generateBaseConfig(application, baseConfigOpts);
|
||||
|
||||
if (deviceApiKey == null && semver.satisfies(options.version, '<2.0.3')) {
|
||||
await addApplicationKey(config, application.id);
|
||||
} else {
|
||||
await addDeviceKey(config, device.uuid, deviceApiKey || true);
|
||||
}
|
||||
return addDeviceKey(config, device.uuid, deviceApiKey || true);
|
||||
});
|
||||
|
||||
return config;
|
||||
})
|
||||
.then((config) => {
|
||||
// Associate a device, to prevent the supervisor
|
||||
@ -150,18 +152,16 @@ function addProvisioningKey(config: any, applicationNameOrId: string | number) {
|
||||
});
|
||||
}
|
||||
|
||||
function addDeviceKey(
|
||||
async function addDeviceKey(
|
||||
config: any,
|
||||
uuid: string,
|
||||
customDeviceApiKey: string | true,
|
||||
) {
|
||||
return Bluebird.try(() => {
|
||||
if (customDeviceApiKey === true) {
|
||||
return getBalenaSdk().models.device.generateDeviceKey(uuid);
|
||||
config.deviceApiKey = await getBalenaSdk().models.device.generateDeviceKey(
|
||||
uuid,
|
||||
);
|
||||
} else {
|
||||
return customDeviceApiKey;
|
||||
config.deviceApiKey = customDeviceApiKey;
|
||||
}
|
||||
}).tap((deviceApiKey) => {
|
||||
config.deviceApiKey = deviceApiKey;
|
||||
});
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
import * as semver from 'balena-semver';
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as Docker from 'dockerode';
|
||||
import * as _ from 'lodash';
|
||||
import { Composition } from 'resin-compose-parse';
|
||||
@ -258,7 +257,7 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
|
||||
deployOpts: opts,
|
||||
});
|
||||
|
||||
const promises: Array<Bluebird<void> | Promise<void>> = [livepush.init()];
|
||||
const promises: Array<Promise<void>> = [livepush.init()];
|
||||
// Only show logs if we're not detaching
|
||||
if (!opts.detached) {
|
||||
const logStream = await api.getLogStream();
|
||||
@ -298,7 +297,7 @@ function connectToDocker(host: string, port: number): Docker {
|
||||
return new Docker({
|
||||
host,
|
||||
port,
|
||||
Promise: Bluebird as any,
|
||||
Promise: require('bluebird'),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -106,17 +106,15 @@ Implements the same feature as the "docker build --cache-from" option.`,
|
||||
]);
|
||||
}
|
||||
|
||||
const generateConnectOpts = function (opts) {
|
||||
const { promises: fs } = require('fs');
|
||||
const Bluebird = require('bluebird');
|
||||
const generateConnectOpts = async function (opts) {
|
||||
const { promises: fs } = await import('fs');
|
||||
|
||||
return Bluebird.try(function () {
|
||||
const connectOpts = {};
|
||||
|
||||
// Start with docker-modem defaults which take several env vars into account,
|
||||
// including DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH, SSH_AUTH_SOCK
|
||||
// https://github.com/apocas/docker-modem/blob/v2.1.3/lib/modem.js#L15-L65
|
||||
const Modem = require('docker-modem');
|
||||
const Modem = await import('docker-modem');
|
||||
const defaultOpts = new Modem();
|
||||
const optsOfInterest = [
|
||||
'ca',
|
||||
@ -164,18 +162,19 @@ const generateConnectOpts = function (opts) {
|
||||
);
|
||||
}
|
||||
|
||||
const certBodies = {
|
||||
ca: fs.readFile(opts.ca, 'utf-8'),
|
||||
cert: fs.readFile(opts.cert, 'utf-8'),
|
||||
key: fs.readFile(opts.key, 'utf-8'),
|
||||
};
|
||||
return Bluebird.props(certBodies).then((toMerge) =>
|
||||
_.merge(connectOpts, toMerge),
|
||||
);
|
||||
const [ca, cert, key] = await Promise.all([
|
||||
fs.readFile(opts.ca, 'utf-8'),
|
||||
fs.readFile(opts.cert, 'utf-8'),
|
||||
fs.readFile(opts.key, 'utf-8'),
|
||||
]);
|
||||
return _.merge(connectOpts, {
|
||||
ca,
|
||||
cert,
|
||||
key,
|
||||
});
|
||||
}
|
||||
|
||||
return connectOpts;
|
||||
});
|
||||
};
|
||||
|
||||
const parseBuildArgs = function (args) {
|
||||
@ -231,10 +230,11 @@ export function generateBuildOpts(options) {
|
||||
* }} options
|
||||
* @returns {Promise<import('docker-toolbelt')>}
|
||||
*/
|
||||
export function getDocker(options) {
|
||||
return generateConnectOpts(options)
|
||||
.then(createClient)
|
||||
.tap(ensureDockerSeemsAccessible);
|
||||
export async function getDocker(options) {
|
||||
const connectOpts = await generateConnectOpts(options);
|
||||
const client = createClient(connectOpts);
|
||||
await ensureDockerSeemsAccessible(client);
|
||||
return client;
|
||||
}
|
||||
|
||||
const getDockerToolbelt = _.once(function () {
|
||||
|
2
typings/denymount/index.d.ts
vendored
2
typings/denymount/index.d.ts
vendored
@ -20,7 +20,7 @@ declare module 'denymount' {
|
||||
target: string,
|
||||
handler: (cb: typeof callback) => void,
|
||||
opts?: { autoMountOnSuccess?: boolean; executablePath?: string },
|
||||
callback: (err?: any) => void,
|
||||
callback: (err?: Error) => void,
|
||||
) => void;
|
||||
export = denymount;
|
||||
}
|
||||
|
2
typings/umount/index.d.ts
vendored
2
typings/umount/index.d.ts
vendored
@ -22,6 +22,6 @@ declare module 'umount' {
|
||||
) => void;
|
||||
export const isMounted: (
|
||||
device: string,
|
||||
callback: (err?: Error, isMounted?: boolean) => void,
|
||||
callback: (err: Error | null, isMounted?: boolean) => void,
|
||||
) => void;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user