Reduce bluebird usage

Change-type: patch
This commit is contained in:
Pagan Gazzard
2020-08-04 16:24:02 +01:00
parent 3f084366db
commit 6ca7c34e57
6 changed files with 126 additions and 175 deletions

View File

@ -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;
};