-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR removes more uses of `shelljs` from the `appsmithctl` project, towards completely removing that dependency. Then we should be able to build `appsmithctl` with `esbuild`, and reduce false-positive CVEs being reported from `appsmithctl`'s `node_modules` folder. ## Automation /test sanity ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11833714062> > Commit: d63aa15 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11833714062&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Thu, 14 Nov 2024 09:21:47 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Enhanced backup and restore processes with improved error handling and logging. - Introduced a new utility function to check if the Supervisor process is running. - **Bug Fixes** - Improved error messages for password retrieval during backup operations. - Refined cleanup processes to ensure resources are released properly. - **Documentation** - Updated test cases for backup functionalities to cover more scenarios and ensure asynchronous handling. - **Chores** - Removed unnecessary dependencies and streamlined logging methods across various scripts. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
7 changed files
with
70 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,49 @@ | ||
// Init function export mongodb | ||
const shell = require('shelljs'); | ||
const fsPromises = require("fs/promises"); | ||
const Constants = require('./constants'); | ||
const utils = require('./utils'); | ||
|
||
function export_database() { | ||
async function exportDatabase() { | ||
console.log('export_database ....'); | ||
dbUrl = utils.getDburl(); | ||
shell.mkdir('-p', [Constants.BACKUP_PATH]); | ||
const cmd = `mongodump --uri='${dbUrl}' --archive='${Constants.BACKUP_PATH}/${Constants.DUMP_FILE_NAME}' --gzip`; | ||
shell.exec(cmd); | ||
const dbUrl = utils.getDburl(); | ||
await fsPromises.mkdir(Constants.BACKUP_PATH, { recursive: true }); | ||
await utils.execCommand([ | ||
"mongodump", | ||
"--uri=" + dbUrl, | ||
`--archive=${Constants.BACKUP_PATH}/${Constants.DUMP_FILE_NAME}`, | ||
"--gzip", | ||
]) | ||
console.log('export_database done'); | ||
} | ||
|
||
function stop_application() { | ||
console.log('stop_application ....'); | ||
shell.exec('/usr/bin/supervisorctl stop backend rts'); | ||
console.log('stop_application done'); | ||
} | ||
async function run() { | ||
let errorCode = 0; | ||
|
||
function start_application() { | ||
console.log('start_application ....'); | ||
shell.exec('/usr/bin/supervisorctl start backend rts'); | ||
console.log('start_application done'); | ||
} | ||
await utils.ensureSupervisorIsRunning(); | ||
|
||
// Main application workflow | ||
function run() { | ||
let errorCode = 0; | ||
try { | ||
check_supervisord_status_cmd = '/usr/bin/supervisorctl >/dev/null 2>&1 '; | ||
shell.exec(check_supervisord_status_cmd, function (code) { | ||
if (code > 0) { | ||
shell.echo('application is not running, starting supervisord'); | ||
shell.exec('/usr/bin/supervisord'); | ||
} | ||
}); | ||
|
||
shell.echo('stop backend & rts application before export database'); | ||
stop_application(); | ||
export_database(); | ||
shell.echo('start backend & rts application after export database'); | ||
shell.echo(); | ||
shell.echo('\033[0;33m++++++++++++++++++++ NOTE ++++++++++++++++++++'); | ||
shell.echo(); | ||
shell.echo( | ||
console.log('stop backend & rts application before export database'); | ||
await utils.stop(["backend", "rts"]); | ||
await exportDatabase(); | ||
console.log('start backend & rts application after export database'); | ||
console.log(); | ||
console.log('\033[0;33m++++++++++++++++++++ NOTE ++++++++++++++++++++'); | ||
console.log(); | ||
console.log( | ||
'Please remember to also copy APPSMITH_ENCRYPTION_SALT and APPSMITH_ENCRYPTION_PASSWORD variables from the docker.env file to the target instance where you intend to import this database dump.', | ||
); | ||
shell.echo(); | ||
shell.echo('++++++++++++++++++++++++++++++++++++++++++++++\033[0m'); | ||
shell.echo(); | ||
console.log(); | ||
console.log('++++++++++++++++++++++++++++++++++++++++++++++\033[0m'); | ||
console.log(); | ||
} catch (err) { | ||
shell.echo(err); | ||
console.log(err); | ||
errorCode = 1; | ||
} finally { | ||
start_application(); | ||
await utils.start(["backend", "rts"]); | ||
process.exit(errorCode); | ||
} | ||
} | ||
|
||
module.exports = { | ||
run, | ||
exportDatabase: export_database, | ||
stopApplication: stop_application, | ||
startApplication: start_application, | ||
}; | ||
exportDatabase, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters