mongodb container update

* upgrades mongodb to 4.4
* makes the service http based
* no more request module usage
This commit is contained in:
Girish Ramakrishnan
2021-12-16 22:23:41 -08:00
parent 3a956857d2
commit 34d11f7f6e
3 changed files with 9 additions and 27 deletions
+6 -24
View File
@@ -594,7 +594,7 @@ async function waitForContainer(containerName, tokenEnvName) {
await promiseRetry({ times: 10, interval: 15000, debug }, async () => {
// temporary workaround till we move all containers to http
const url = containerName.includes('redis')
const url = containerName.includes('redis') || containerName === 'mongodb'
? `http://${result.ip}:3000/healthcheck?access_token=${result.token}`
: `https://${result.ip}:3000/healthcheck?access_token=${result.token}`;
@@ -1592,8 +1592,7 @@ async function setupMongoDb(app, options) {
const result = await getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN');
const [networkError, response] = await safe(superagent.post(`https://${result.ip}:3000/databases?access_token=${result.token}`)
.disableTLSCerts()
const [networkError, response] = await safe(superagent.post(`http://${result.ip}:3000/databases?access_token=${result.token}`)
.send(data)
.ok(() => true));
@@ -1626,8 +1625,7 @@ async function clearMongodb(app, options) {
const database = await addonConfigs.getByName(app.id, 'mongodb', '%MONGODB_DATABASE');
if (!database) throw new BoxError(BoxError.NOT_FOUND, 'Error clearing mongodb. No database');
const [networkError, response] = await safe(superagent.post(`https://${result.ip}:3000/databases/${database}/clear?access_token=${result.token}`)
.disableTLSCerts()
const [networkError, response] = await safe(superagent.post(`http://${result.ip}:3000/databases/${database}/clear?access_token=${result.token}`)
.ok(() => true));
if (networkError) throw new BoxError(BoxError.ADDONS_ERROR, `Network error clearing mongodb: ${networkError.message}`);
@@ -1643,8 +1641,7 @@ async function teardownMongoDb(app, options) {
const database = await addonConfigs.getByName(app.id, 'mongodb', '%MONGODB_DATABASE');
if (!database) return;
const [networkError, response] = await safe(superagent.del(`https://${result.ip}:3000/databases/${database}?access_token=${result.token}`)
.disableTLSCerts()
const [networkError, response] = await safe(superagent.del(`http://${result.ip}:3000/databases/${database}?access_token=${result.token}`)
.ok(() => true));
if (networkError) throw new BoxError(BoxError.ADDONS_ERROR, `Error tearing down mongodb: ${networkError.message}`);
@@ -1664,8 +1661,7 @@ async function backupMongoDb(app, options) {
const database = await addonConfigs.getByName(app.id, 'mongodb', '%MONGODB_DATABASE');
if (!database) throw new BoxError(BoxError.NOT_FOUND, 'Error backing up mongodb. No database');
const url = `https://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`;
await pipeRequestToFile(url, dumpPath('mongodb', app.id));
await pipeRequestToFile2(`http://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`, dumpPath('mongodb', app.id));
}
async function restoreMongoDb(app, options) {
@@ -1679,21 +1675,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');
await new Promise((resolve, reject) => {
reject = once(reject); // protect from multiple returns with streams
const readStream = fs.createReadStream(dumpPath('mongodb', app.id));
readStream.on('error', (error) => reject(new BoxError(BoxError.FS_ERROR, `Error reading input stream when restoring mongodb: ${error.message}`)));
const restoreReq = request.post(`https://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
if (error) return reject(new BoxError(BoxError.ADDONS_ERROR, `Error restoring mongodb: ${error.message}`));
if (response.statusCode !== 200) return reject(new BoxError(BoxError.ADDONS_ERROR, `Error restoring mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
resolve();
});
readStream.pipe(restoreReq);
});
await pipeFileToRequest(dumpPath('mongodb', app.id), `http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}`);
}
async function startGraphite(existingInfra) {