feat: appsmithctl version and mongo-eval utils (#19075)
`appsmithctl version` - Util to display current Appsmith version `appsmithctl mongo-eval '<mongo query>' [--pretty]` - Util to run mongo queries Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
This commit is contained in:
parent
ebbd339947
commit
a1be1bf941
|
|
@ -83,7 +83,7 @@ async function createGitStorageArchive(destFolder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createManifestFile(path) {
|
async function createManifestFile(path) {
|
||||||
const version = await getCurrentVersion()
|
const version = await utils.getCurrentAppsmithVersion()
|
||||||
const manifest_data = { "appsmithVersion": version }
|
const manifest_data = { "appsmithVersion": version }
|
||||||
await fsPromises.writeFile(path + '/manifest.json', JSON.stringify(manifest_data));
|
await fsPromises.writeFile(path + '/manifest.json', JSON.stringify(manifest_data));
|
||||||
}
|
}
|
||||||
|
|
@ -183,10 +183,7 @@ function checkAvailableBackupSpace(availSpaceInBytes) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCurrentVersion() {
|
|
||||||
const content = await fsPromises.readFile('/opt/appsmith/rts/version.js', { encoding: 'utf8' });
|
|
||||||
return content.match(/\bexports\.VERSION\s*=\s*["']([^"]+)["']/)[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
run,
|
run,
|
||||||
|
|
@ -198,7 +195,6 @@ module.exports = {
|
||||||
executeMongoDumpCMD,
|
executeMongoDumpCMD,
|
||||||
getGitRoot,
|
getGitRoot,
|
||||||
executeCopyCMD,
|
executeCopyCMD,
|
||||||
getCurrentVersion,
|
|
||||||
removeEncryptionEnvData,
|
removeEncryptionEnvData,
|
||||||
getBackupArchiveLimit,
|
getBackupArchiveLimit,
|
||||||
removeOldBackups
|
removeOldBackups
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ it('Checks for the current Appsmith Version.', async () => {
|
||||||
`Object.defineProperty(exports, "__esModule", { value: true });
|
`Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.VERSION = void 0;
|
exports.VERSION = void 0;
|
||||||
exports.VERSION = "v0.0.0-SNAPSHOT";`);
|
exports.VERSION = "v0.0.0-SNAPSHOT";`);
|
||||||
const res = await backup.getCurrentVersion()
|
const res = await utils.getCurrentAppsmithVersion()
|
||||||
expect(res).toBe("v0.0.0-SNAPSHOT")
|
expect(res).toBe("v0.0.0-SNAPSHOT")
|
||||||
console.log(res)
|
console.log(res)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ const import_db = require("./import_db.js");
|
||||||
const migrate = require("./migrate.js");
|
const migrate = require("./migrate.js");
|
||||||
const check_replica_set = require("./check_replica_set.js");
|
const check_replica_set = require("./check_replica_set.js");
|
||||||
const estimate_billing = require("./estimate_billing.js");
|
const estimate_billing = require("./estimate_billing.js");
|
||||||
|
const version = require("./version.js");
|
||||||
|
const mongo_shell_utils = require("./mongo_shell_utils.js");
|
||||||
|
|
||||||
const APPLICATION_CONFIG_PATH = "/appsmith-stacks/configuration/docker.env";
|
const APPLICATION_CONFIG_PATH = "/appsmith-stacks/configuration/docker.env";
|
||||||
|
|
||||||
|
|
@ -52,5 +54,13 @@ if (["estimate-billing", "estimate_billing"].includes(command)) {
|
||||||
estimate_billing.run(process.argv.slice(3));
|
estimate_billing.run(process.argv.slice(3));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (["appsmith-version", "appsmith_version", "version"].includes(command)) {
|
||||||
|
version.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (["mongo-eval", "mongo_eval", "mongoEval"].includes(command)) {
|
||||||
|
mongo_shell_utils.exec(process.argv.slice(3));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
utils.showHelp();
|
utils.showHelp();
|
||||||
|
|
|
||||||
28
deploy/docker/utils/bin/mongo_shell_utils.js
Normal file
28
deploy/docker/utils/bin/mongo_shell_utils.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
const utils = require('./utils');
|
||||||
|
|
||||||
|
const command_args = process.argv.slice(3);
|
||||||
|
|
||||||
|
async function exec() {
|
||||||
|
let errorCode = 0;
|
||||||
|
try {
|
||||||
|
await execMongoEval(command_args[0], process.env.APPSMITH_MONGODB_URI);
|
||||||
|
} catch (err) {
|
||||||
|
errorCode = 1;
|
||||||
|
console.error('Error evaluating the mongo query', err);
|
||||||
|
} finally {
|
||||||
|
process.exit(errorCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function execMongoEval(queryExpression, appsmithMongoURI) {
|
||||||
|
queryExpression = queryExpression.trim();
|
||||||
|
if (command_args.includes('--pretty')) {
|
||||||
|
queryExpression += '.pretty()';
|
||||||
|
}
|
||||||
|
return await utils.execCommand(['mongo', appsmithMongoURI, `--eval=${queryExpression}`]);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
exec
|
||||||
|
};
|
||||||
|
|
@ -58,7 +58,7 @@ function execCommand(cmd, options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isPromiseDone = true;
|
isPromiseDone = true;
|
||||||
log.error("Error running command", err);
|
console.error("Error running command", err);
|
||||||
reject();
|
reject();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -97,6 +97,11 @@ async function getLastBackupErrorMailSentInMilliSec() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getCurrentAppsmithVersion() {
|
||||||
|
const content = await fsPromises.readFile('/opt/appsmith/rts/version.js', { encoding: 'utf8' });
|
||||||
|
return content.match(/\bexports\.VERSION\s*=\s*["']([^"]+)["']/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
showHelp,
|
showHelp,
|
||||||
start,
|
start,
|
||||||
|
|
@ -105,4 +110,5 @@ module.exports = {
|
||||||
listLocalBackupFiles,
|
listLocalBackupFiles,
|
||||||
updateLastBackupErrorMailSentInMilliSec,
|
updateLastBackupErrorMailSentInMilliSec,
|
||||||
getLastBackupErrorMailSentInMilliSec,
|
getLastBackupErrorMailSentInMilliSec,
|
||||||
|
getCurrentAppsmithVersion
|
||||||
};
|
};
|
||||||
|
|
|
||||||
22
deploy/docker/utils/bin/version.js
Normal file
22
deploy/docker/utils/bin/version.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
const utils = require('./utils');
|
||||||
|
|
||||||
|
async function exec() {
|
||||||
|
let version = null;
|
||||||
|
try {
|
||||||
|
version = await utils.getCurrentAppsmithVersion();
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error fetching current Appsmith version", err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if (version) {
|
||||||
|
console.log(version);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error("Error: could not find the current Appsmith version")
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
exec,
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user