From 305d4d7fab29cf45504e871904e07e125601e731 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Wed, 27 Mar 2024 19:58:44 +0530 Subject: [PATCH] chore: Remove old undocumented migrate command (#32114) This removes the `appsmithctl migrate` command which can migrate an Appsmith instance from on EC2 instance to another, using SSH. Why are we removing it? 1. It's not documented on docs.appsmith.com at all. 2. The problem is better solved with a combination of `appsmithctl backup` and `appsmithctl restore`, with much _more_ flexibility. --- .../fs/opt/appsmith/utils/bin/backup.test.js | 11 +- .../docker/fs/opt/appsmith/utils/bin/index.js | 8 -- .../fs/opt/appsmith/utils/bin/migrate.js | 110 ------------------ .../docker/fs/opt/appsmith/utils/bin/utils.js | 5 +- .../docker/fs/opt/appsmith/utils/package.json | 1 - 5 files changed, 9 insertions(+), 126 deletions(-) delete mode 100644 deploy/docker/fs/opt/appsmith/utils/bin/migrate.js diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js b/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js index 6c03b50e3b..ca32e7acc1 100644 --- a/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js +++ b/deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js @@ -79,10 +79,13 @@ test('Test ln command generation', async () => { }) it('Checks for the current Appsmith Version.', async () => { - fsPromises.readFile = jest.fn().mockImplementation(async (a) => - `Object.defineProperty(exports, "__esModule", { value: true }); - exports.VERSION = void 0; - exports.VERSION = "v0.0.0-SNAPSHOT";`); + fsPromises.readFile = jest.fn().mockImplementation(async (path) => { + if (path === "/opt/appsmith/info.json") { + return `{"githubRef": "v0.0.0-SNAPSHOT"}` + } else { + throw new Error("Unexpected file to read: " + path) + } + }); const res = await utils.getCurrentAppsmithVersion() expect(res).toBe("v0.0.0-SNAPSHOT") console.log(res) diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/index.js b/deploy/docker/fs/opt/appsmith/utils/bin/index.js index 2abd361e4c..34d4c49492 100755 --- a/deploy/docker/fs/opt/appsmith/utils/bin/index.js +++ b/deploy/docker/fs/opt/appsmith/utils/bin/index.js @@ -4,7 +4,6 @@ const process = require("process"); const utils = require("./utils"); const export_db = require("./export_db.js"); const import_db = require("./import_db.js"); -const migrate = require("./migrate.js"); const check_replica_set = require("./check_replica_set.js"); const version = require("./version.js"); const mongo_shell_utils = require("./mongo_shell_utils.js"); @@ -32,13 +31,6 @@ if (["import-db", "import_db", "im"].includes(command)) { return; } -if (["migrate", "mi"].includes(command) && process.argv[3]) { - const arrString = process.argv[3].split("@"); - console.log("Start migrate instance"); - migrate.runMigrate(arrString[0], arrString[1]); - return; -} - if (["check-replica-set", "check_replica_set", "crs"].includes(command)) { check_replica_set.exec(); return; diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/migrate.js b/deploy/docker/fs/opt/appsmith/utils/bin/migrate.js deleted file mode 100644 index f5aed82cbe..0000000000 --- a/deploy/docker/fs/opt/appsmith/utils/bin/migrate.js +++ /dev/null @@ -1,110 +0,0 @@ -const shell = require('shelljs'); -const process = require('process'); -const export_db = require('./export_db.js'); -const readlineSync = require('readline-sync'); - -const main = async (userServer, ipServer) => { - shell.echo('Check connection to server'); - const resultNc = shell.exec(`nc -vzw 5 ${ipServer} 22`); - - if (!resultNc.stderr.includes('succeeded')) { - shell.echo("********* Can't connection to server destination ********"); - shell.echo('***** Please check connection to server destination *****'); - process.kill(process.pid); - } - - shell.echo('**************************** WARNING ****************************'); - shell.echo(' This process will stop application. Do you want to continue? '); - const answerConfirm = readlineSync.question('Type "y" if you agree, type "c" to cancel: '); - - if (answerConfirm.toLowerCase() === 'y') { - const folderSsh = `/opt/appsmith/.ssh`; - const isCreatedKey = await generationKey(folderSsh); - if (isCreatedKey) { - shell.echo('****** Run below command on the new server to add key for migration *******\n'); - shell.echo(`echo "${shell.cat(`${folderSsh}/id_rsa.pub`).stdout.replace(' \n', '')}" >> ~/.ssh/authorized_keys`); - shell.echo(); - } - - const answerKey = readlineSync.question('Type "y" if you have added public key to new server, type "c" to cancel: '); - - - if (answerKey.toLowerCase() === 'y') { - const status = shell.exec( - `ssh -i ${folderSsh}/id_rsa -q -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=5 ${userServer}@${ipServer} 'exit 0'`, - ); - - if (status.code === 0) { - shell.echo('Connect successfully via ssh'); - - const installDir = readlineSync.question('Choose Installation Directory [appsmith]: '); - - let installAbsoluteDir = `/home/${userServer}/appsmith`; - if (installDir.length !== 0 && /\/\w+/gi.test(installDir)) { - installAbsoluteDir = installDir; - } else if (installDir.length !== 0) { - installAbsoluteDir = `/home/${userServer}/${installDir}` - } - export_db.stopApplication(); - export_db.exportDatabase(); - export_db.startApplication(); - - const resDocker = shell.exec( - `ssh -i ${folderSsh}/id_rsa ${userServer}@${ipServer} 'bash -s ${installAbsoluteDir}' < /opt/appsmith/install_docker.sh`, - ); - if (resDocker.code === 1) { - process.kill(process.pid); - } - - const resPull = shell.exec( - `ssh -i ${folderSsh}/id_rsa ${userServer}@${ipServer} 'bash -s ${installAbsoluteDir}' < /opt/appsmith/pull_resource.sh`, - ); - if (resPull.code === 1) { - process.kill(process.pid); - } - - shell.exec( - `scp -i ${folderSsh}/id_rsa -r /appsmith-stacks/configuration ${userServer}@${ipServer}:${installAbsoluteDir}/stacks`, - ); - shell.exec( - `scp -i ${folderSsh}/id_rsa -r /appsmith-stacks/data/backup ${userServer}@${ipServer}:${installAbsoluteDir}/stacks/data`, - ); - shell.exec( - `scp -i ${folderSsh}/id_rsa -r /appsmith-stacks/letsencrypt ${userServer}@${ipServer}:${installAbsoluteDir}/stacks`, - ); - shell.exec(`ssh -i ${folderSsh}/id_rsa ${userServer}@${ipServer} 'bash -s ${installAbsoluteDir}' < /opt/appsmith/start_app.sh`); - shell.rm('-rf', folderSsh); - - shell.echo('***************** Migrated application successfully ***************'); - shell.echo(); - shell.echo('**************************** WARNING ****************************'); - shell.echo('You should remove authorized key on new server'); - - process.kill(process.pid); - } else { - shell.echo('Connect unsuccessfully via ssh'); - process.kill(process.pid); - } - } else if (answerKey.toLowerCase() === 'c') { - process.kill(process.pid); - } - } else if (answerConfirm.toLowerCase() === 'c') { - process.kill(process.pid); - } -}; - -const generationKey = (path) => { - return new Promise((resolve, reject) => { - shell.exec(`rm -rf ${path}`); - shell.exec(`mkdir -p ${path}`); - shell.echo(`***** Start gen key *****`); - shell.exec(`ssh-keygen -t rsa -b 2048 -C "" -f ${path}/id_rsa`, (err) => { - if (err) { - reject(false); - } - resolve(true); - }); - }); -}; - -module.exports = { runMigrate: main }; diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/utils.js b/deploy/docker/fs/opt/appsmith/utils/bin/utils.js index 6ee176d8f9..7bc05b4eb6 100644 --- a/deploy/docker/fs/opt/appsmith/utils/bin/utils.js +++ b/deploy/docker/fs/opt/appsmith/utils/bin/utils.js @@ -9,9 +9,8 @@ function showHelp() { "\nUsage: appsmith to interact with appsmith utils tool" ); console.log("\nOptions:\r"); - console.log("\tex, export_db\t\tExport interal database.\r"); - console.log("\tim, import_db\t\tImport interal database.\r"); - console.log("\tmi, migrate\t\tMigrate new server.\r"); + console.log("\tex, export_db\t\tExport internal database.\r"); + console.log("\tim, import_db\t\tImport internal database.\r"); console.log("\tcrs, check_replica_set\tCheck replica set mongoDB.\r"); console.log("\tbackup\t\t\tTake a backup of Appsmith instance.\r"); console.log("\trestore\t\t\tRestore Appsmith instance from a backup.\r"); diff --git a/deploy/docker/fs/opt/appsmith/utils/package.json b/deploy/docker/fs/opt/appsmith/utils/package.json index 2e1fe02c63..1758ad0fd7 100644 --- a/deploy/docker/fs/opt/appsmith/utils/package.json +++ b/deploy/docker/fs/opt/appsmith/utils/package.json @@ -12,7 +12,6 @@ "directory": "deploy/docker" }, "dependencies": { - "cli-progress": "^3.11.2", "dotenv": "10.0.0", "mongodb": "^5.8.0", "nodemailer": "6.9.9",