mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-06-19 00:08:10 +00:00
Reduce bluebird usage
Change-type: patch
This commit is contained in:
@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as Bluebird from 'bluebird';
|
||||
import { getVisuals } from './lazy';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const getBuilderPushEndpoint = function (baseUrl, owner, app) {
|
||||
const querystring = require('querystring');
|
||||
@ -158,7 +158,7 @@ opts must be a hash with the following keys:
|
||||
- buildLogs: a string with build output
|
||||
- shouldUploadLogs
|
||||
*/
|
||||
export const deployLegacy = function (
|
||||
export const deployLegacy = async function (
|
||||
docker,
|
||||
logger,
|
||||
token,
|
||||
@ -167,7 +167,7 @@ export const deployLegacy = function (
|
||||
opts,
|
||||
) {
|
||||
const tmp = require('tmp');
|
||||
const tmpNameAsync = Bluebird.promisify(tmp.tmpName);
|
||||
const tmpNameAsync = promisify(tmp.tmpName);
|
||||
|
||||
// Ensure the tmp files gets deleted
|
||||
tmp.setGracefulCleanup();
|
||||
@ -175,37 +175,35 @@ export const deployLegacy = function (
|
||||
const { appName, imageName, buildLogs, shouldUploadLogs } = opts;
|
||||
const logs = buildLogs;
|
||||
|
||||
return tmpNameAsync()
|
||||
.then(function (bufferFile) {
|
||||
logger.logInfo('Initializing deploy...');
|
||||
return bufferImage(docker, imageName, bufferFile)
|
||||
.then((stream) =>
|
||||
uploadImage(stream, token, username, url, appName, logger),
|
||||
)
|
||||
.finally(() =>
|
||||
// If the file was never written to (for instance because an error
|
||||
// has occured before any data was written) this call will throw an
|
||||
// ugly error, just suppress it
|
||||
Bluebird.try(() =>
|
||||
require('fs').promises.unlink(bufferFile),
|
||||
).catchReturn(undefined),
|
||||
);
|
||||
})
|
||||
.tap(function ({ buildId }) {
|
||||
if (!shouldUploadLogs) {
|
||||
return;
|
||||
}
|
||||
const bufferFile = await tmpNameAsync();
|
||||
|
||||
logger.logInfo('Uploading logs...');
|
||||
return Bluebird.join(
|
||||
logs,
|
||||
token,
|
||||
url,
|
||||
buildId,
|
||||
username,
|
||||
appName,
|
||||
uploadLogs,
|
||||
);
|
||||
})
|
||||
.get('buildId');
|
||||
logger.logInfo('Initializing deploy...');
|
||||
const { buildId } = await bufferImage(docker, imageName, bufferFile)
|
||||
.then((stream) =>
|
||||
uploadImage(stream, token, username, url, appName, logger),
|
||||
)
|
||||
.finally(() =>
|
||||
// If the file was never written to (for instance because an error
|
||||
// has occured before any data was written) this call will throw an
|
||||
// ugly error, just suppress it
|
||||
|
||||
require('fs')
|
||||
.promises.unlink(bufferFile)
|
||||
.catch(() => undefined),
|
||||
);
|
||||
|
||||
if (shouldUploadLogs) {
|
||||
logger.logInfo('Uploading logs...');
|
||||
const args = await Promise.all([
|
||||
logs,
|
||||
token,
|
||||
url,
|
||||
buildId,
|
||||
username,
|
||||
appName,
|
||||
]);
|
||||
await uploadLogs(...args);
|
||||
}
|
||||
|
||||
return buildId;
|
||||
};
|
||||
|
Reference in New Issue
Block a user