postgresql container update

* 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 9590a60c47
commit d37652d362
2 changed files with 7 additions and 26 deletions
+6 -25
View File
@@ -593,7 +593,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') || containerName === 'mongodb'
const url = containerName.includes('redis') || containerName === 'mongodb' || containerName === 'postgresql'
? `http://${result.ip}:3000/healthcheck?access_token=${result.token}`
: `https://${result.ip}:3000/healthcheck?access_token=${result.token}`;
@@ -1427,8 +1427,7 @@ async function setupPostgreSql(app, options) {
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_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));
if (networkError) throw new BoxError(BoxError.ADDONS_ERROR, `Network error setting up postgresql: ${networkError.message}`);
@@ -1458,8 +1457,7 @@ async function clearPostgreSql(app, options) {
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN');
const [networkError, response] = await safe(superagent.post(`https://${result.ip}:3000/databases/${database}/clear?access_token=${result.token}&username=${username}&locale=${locale}`)
.disableTLSCerts()
const [networkError, response] = await safe(superagent.post(`http://${result.ip}:3000/databases/${database}/clear?access_token=${result.token}&username=${username}&locale=${locale}`)
.ok(() => true));
if (networkError) throw new BoxError(BoxError.ADDONS_ERROR, `Network error clearing postgresql: ${networkError.message}`);
if (response.status !== 200) throw new BoxError(BoxError.ADDONS_ERROR, `Error clearing postgresql. Status code: ${response.status} message: ${response.body.message}`);
@@ -1473,8 +1471,7 @@ async function teardownPostgreSql(app, options) {
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN');
const [networkError, response] = await safe(superagent.del(`https://${result.ip}:3000/databases/${database}?access_token=${result.token}&username=${username}`)
.disableTLSCerts()
const [networkError, response] = await safe(superagent.del(`http://${result.ip}:3000/databases/${database}?access_token=${result.token}&username=${username}`)
.ok(() => true));
if (networkError) throw new BoxError(BoxError.ADDONS_ERROR, `Network error tearing down postgresql: ${networkError.message}`);
if (response.status !== 200) throw new BoxError(BoxError.ADDONS_ERROR, `Error tearing down postgresql. Status code: ${response.status} message: ${response.body.message}`);
@@ -1491,9 +1488,7 @@ async function backupPostgreSql(app, options) {
const { database } = postgreSqlNames(app.id);
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN');
const url = `https://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`;
await pipeRequestToFile(url, dumpPath('postgresql', app.id));
await pipeRequestToFile2(`http://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`, dumpPath('postgresql', app.id));
}
async function restorePostgreSql(app, options) {
@@ -1506,21 +1501,7 @@ async function restorePostgreSql(app, options) {
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN');
await new Promise((resolve, reject) => {
resolve = once(resolve); // protect from multiple returns with streams
const input = fs.createReadStream(dumpPath('postgresql', app.id));
input.on('error', (error) => reject(new BoxError(BoxError.FS_ERROR, `Error reading input stream when restoring postgresql: ${error.message}`)));
const restoreReq = request.post(`https://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}&username=${username}`, { json: true, rejectUnauthorized: false }, function (error, response) {
if (error) return reject(new BoxError(BoxError.ADDONS_ERROR, `Error restoring postgresql: ${error.message}`));
if (response.statusCode !== 200) return reject(new BoxError(BoxError.ADDONS_ERROR, `Error restoring postgresql. Status code: ${response.statusCode} message: ${response.body.message}`));
resolve();
});
input.pipe(restoreReq);
});
await pipeFileToRequest(dumpPath('postgresql', app.id), `http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}&username=${username}`);
}
async function startMongodb(existingInfra) {