diff --git a/src/docker.js b/src/docker.js index a3dae158f..3418ea6c4 100644 --- a/src/docker.js +++ b/src/docker.js @@ -493,13 +493,12 @@ async function stopContainers(appId) { } } -function deleteImage(manifest, callback) { +async function deleteImage(manifest) { assert(!manifest || typeof manifest === 'object'); - assert.strictEqual(typeof callback, 'function'); const dockerImage = manifest ? manifest.dockerImage : null; - if (!dockerImage) return callback(null); - if (dockerImage.includes('//')) return callback(null); // a common mistake is to paste a https:// as docker image. this results in a crash at runtime in dockerode module + if (!dockerImage) return; + if (dockerImage.includes('//')) return; // a common mistake is to paste a https:// as docker image. this results in a crash at runtime in dockerode module const removeOptions = { force: false, // might be shared with another instance of this app @@ -509,18 +508,15 @@ function deleteImage(manifest, callback) { // registry v1 used to pull down all *tags*. this meant that deleting image by tag was not enough (since that // just removes the tag). we used to remove the image by id. this is not required anymore because aliases are // not created anymore after https://github.com/docker/docker/pull/10571 - gConnection.getImage(dockerImage).remove(removeOptions, function (error) { - if (error && error.statusCode === 400) return callback(null); // invalid image format. this can happen if user installed with a bad --docker-image - if (error && error.statusCode === 404) return callback(null); // not found - if (error && error.statusCode === 409) return callback(null); // another container using the image + const [error] = await safe(gConnection.getImage(dockerImage).remove(removeOptions)); + if (error && error.statusCode === 400) return; // invalid image format. this can happen if user installed with a bad --docker-image + if (error && error.statusCode === 404) return; // not found + if (error && error.statusCode === 409) return; // another container using the image - if (error) { - debug('Error removing image %s : %j', dockerImage, error); - return callback(new BoxError(BoxError.DOCKER_ERROR, error)); - } - - callback(null); - }); + if (error) { + debug('Error removing image %s : %j', dockerImage, error); + throw new BoxError(BoxError.DOCKER_ERROR, error); + } } async function inspect(containerId) { diff --git a/src/services.js b/src/services.js index d1007eb32..7112937d4 100644 --- a/src/services.js +++ b/src/services.js @@ -1214,7 +1214,7 @@ async function pipeRequestToFile(url, filename) { assert.strictEqual(typeof url, 'string'); assert.strictEqual(typeof filename, 'string'); - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { const writeStream = fs.createWriteStream(filename); const done = once(function (error) { // the writeStream and the request can both error @@ -1262,7 +1262,7 @@ async function restoreMySql(app, options) { const result = await getContainerDetails('mysql', 'CLOUDRON_MYSQL_TOKEN'); - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { reject = once(reject); // protect from multiple returns with streams const input = fs.createReadStream(dumpPath('mysql', app.id)); @@ -1424,7 +1424,7 @@ async function restorePostgreSql(app, options) { const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN'); - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { resolve = once(resolve); // protect from multiple returns with streams const input = fs.createReadStream(dumpPath('postgresql', app.id)); @@ -1589,7 +1589,7 @@ async function restoreMongoDb(app, options) { const database = await addonConfigs.getByName(app.id, 'mongodb', '%MONGODB_DATABASE'); if (!database) throw new BoxError(BoxError.NOT_FOUND, 'Error restoring mongodb. No database'); - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { reject = once(reject); // protect from multiple returns with streams const readStream = fs.createReadStream(dumpPath('mongodb', app.id)); @@ -1800,7 +1800,7 @@ async function restoreRedis(app, options) { const result = await getContainerDetails('redis-' + app.id, 'CLOUDRON_REDIS_TOKEN'); - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { reject = once(reject); // protect from multiple returns with streams let input;