mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
feat: stop-backend.js and update.js linux support (#712)
* chore(dependabot.yml): update target-branch from "develop" to "dev" for npm package updates in /api, /client, and root directory * feat: stop-backend.js and update.js linux support (#701) * feat: stop-backend.js and update.js linux support * feat: update.js sudo support * chore(helpers.js): add deleteNodeModules function feat(packages.js): add script to delete node_modules and install dependencies refactor(update.js): remove unnecessary imports and use deleteNodeModules function feat(package.json): add update:linux script to update with sudo * chore(package.json): rename 'update:linux' script to 'update:sudo' * refactor(update.js): simplify downCommand and buildCommand by removing redundant use of sudo command, add sudo to single docker command --------- Co-authored-by: Fuegovic <32828263+fuegovic@users.noreply.github.com>
This commit is contained in:
parent
d59a3f20cb
commit
777d64088b
6 changed files with 80 additions and 20 deletions
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
|
@ -7,7 +7,7 @@ version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "npm" # See documentation for possible values
|
- package-ecosystem: "npm" # See documentation for possible values
|
||||||
directory: "/api" # Location of package manifests
|
directory: "/api" # Location of package manifests
|
||||||
target-branch: "develop"
|
target-branch: "dev"
|
||||||
versioning-strategy: increase-if-necessary
|
versioning-strategy: increase-if-necessary
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
@ -20,7 +20,7 @@ updates:
|
||||||
include: "scope"
|
include: "scope"
|
||||||
- package-ecosystem: "npm" # See documentation for possible values
|
- package-ecosystem: "npm" # See documentation for possible values
|
||||||
directory: "/client" # Location of package manifests
|
directory: "/client" # Location of package manifests
|
||||||
target-branch: "develop"
|
target-branch: "dev"
|
||||||
versioning-strategy: increase-if-necessary
|
versioning-strategy: increase-if-necessary
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
@ -33,7 +33,7 @@ updates:
|
||||||
include: "scope"
|
include: "scope"
|
||||||
- package-ecosystem: "npm" # See documentation for possible values
|
- package-ecosystem: "npm" # See documentation for possible values
|
||||||
directory: "/" # Location of package manifests
|
directory: "/" # Location of package manifests
|
||||||
target-branch: "develop"
|
target-branch: "dev"
|
||||||
versioning-strategy: increase-if-necessary
|
versioning-strategy: increase-if-necessary
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* Helper functions
|
* Helper functions
|
||||||
* This allows us to give the console some colour when running in a terminal
|
* This allows us to give the console some colour when running in a terminal
|
||||||
*/
|
*/
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
@ -28,6 +30,14 @@ function isDockerRunning() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteNodeModules(dir) {
|
||||||
|
const nodeModulesPath = path.join(dir, 'node_modules');
|
||||||
|
if (fs.existsSync(nodeModulesPath)) {
|
||||||
|
console.purple(`Deleting node_modules in ${dir}`);
|
||||||
|
fs.rmdirSync(nodeModulesPath, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const silentExit = (code = 0) => {
|
const silentExit = (code = 0) => {
|
||||||
console.log = () => {};
|
console.log = () => {};
|
||||||
process.exit(code);
|
process.exit(code);
|
||||||
|
@ -48,4 +58,5 @@ module.exports = {
|
||||||
askQuestion,
|
askQuestion,
|
||||||
silentExit,
|
silentExit,
|
||||||
isDockerRunning,
|
isDockerRunning,
|
||||||
|
deleteNodeModules,
|
||||||
};
|
};
|
||||||
|
|
26
config/packages.js
Normal file
26
config/packages.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const { deleteNodeModules } = require('./helpers');
|
||||||
|
|
||||||
|
// Set the directories
|
||||||
|
const rootDir = path.resolve(__dirname, '..');
|
||||||
|
const directories = [
|
||||||
|
rootDir,
|
||||||
|
path.resolve(rootDir, 'packages', 'data-provider'),
|
||||||
|
path.resolve(rootDir, 'client'),
|
||||||
|
path.resolve(rootDir, 'api'),
|
||||||
|
];
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// Delete all node_modules
|
||||||
|
directories.forEach(deleteNodeModules);
|
||||||
|
|
||||||
|
// Run npm cache clean --force
|
||||||
|
console.purple('Cleaning npm cache...');
|
||||||
|
execSync('npm cache clean --force', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
// Install dependencies
|
||||||
|
console.purple('Installing dependencies...');
|
||||||
|
execSync('npm install', { stdio: 'inherit' });
|
||||||
|
})();
|
23
config/stop-backend.js
Normal file
23
config/stop-backend.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// eslint-disable-next-line
|
||||||
|
const helpers = require('./helpers');
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
const { promisify } = require('util');
|
||||||
|
|
||||||
|
const isWindows = process.platform === 'win32';
|
||||||
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
if (isWindows) {
|
||||||
|
console.red('The backend process has been terminated');
|
||||||
|
await execAsync('taskkill /F /IM node.exe /T');
|
||||||
|
} else {
|
||||||
|
await execAsync('pkill -f api/server/index.js');
|
||||||
|
console.orange('The backend process has been terminated');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.red('The backend process has been terminated', err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
|
@ -1,12 +1,12 @@
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const { askQuestion, isDockerRunning, deleteNodeModules, silentExit } = require('./helpers');
|
||||||
const { askQuestion, isDockerRunning, silentExit } = require('./helpers');
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
localUpdate: process.argv.includes('-l'),
|
localUpdate: process.argv.includes('-l'),
|
||||||
dockerUpdate: process.argv.includes('-d'),
|
dockerUpdate: process.argv.includes('-d'),
|
||||||
useSingleComposeFile: process.argv.includes('-s'),
|
useSingleComposeFile: process.argv.includes('-s'),
|
||||||
|
useSudo: process.argv.includes('--sudo'),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the directories
|
// Set the directories
|
||||||
|
@ -47,14 +47,6 @@ async function validateDockerRunning() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteNodeModules(dir) {
|
|
||||||
const nodeModulesPath = path.join(dir, 'node_modules');
|
|
||||||
if (fs.existsSync(nodeModulesPath)) {
|
|
||||||
console.purple(`Deleting node_modules in ${dir}`);
|
|
||||||
execSync(`rd /s /q "${nodeModulesPath}"`, { stdio: 'inherit', shell: 'cmd.exe' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const showWizard = !config.localUpdate && !config.dockerUpdate && !config.useSingleComposeFile;
|
const showWizard = !config.localUpdate && !config.dockerUpdate && !config.useSingleComposeFile;
|
||||||
|
|
||||||
|
@ -62,9 +54,13 @@ function deleteNodeModules(dir) {
|
||||||
await updateConfigWithWizard();
|
await updateConfigWithWizard();
|
||||||
}
|
}
|
||||||
|
|
||||||
await validateDockerRunning();
|
console.green(
|
||||||
const { dockerUpdate, useSingleComposeFile: singleCompose } = config;
|
'Starting update script, this may take a minute or two depending on your system and network.',
|
||||||
|
);
|
||||||
|
|
||||||
|
await validateDockerRunning();
|
||||||
|
const { dockerUpdate, useSingleComposeFile: singleCompose, useSudo } = config;
|
||||||
|
const sudo = useSudo ? 'sudo ' : '';
|
||||||
// Fetch latest repo
|
// Fetch latest repo
|
||||||
console.purple('Fetching the latest repo...');
|
console.purple('Fetching the latest repo...');
|
||||||
execSync('git fetch origin', { stdio: 'inherit' });
|
execSync('git fetch origin', { stdio: 'inherit' });
|
||||||
|
@ -79,7 +75,7 @@ function deleteNodeModules(dir) {
|
||||||
|
|
||||||
if (dockerUpdate) {
|
if (dockerUpdate) {
|
||||||
console.purple('Removing previously made Docker container...');
|
console.purple('Removing previously made Docker container...');
|
||||||
const downCommand = `docker-compose ${
|
const downCommand = `${sudo}docker-compose ${
|
||||||
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
||||||
}down --volumes`;
|
}down --volumes`;
|
||||||
console.orange(downCommand);
|
console.orange(downCommand);
|
||||||
|
@ -88,14 +84,14 @@ function deleteNodeModules(dir) {
|
||||||
|
|
||||||
const imageName = singleCompose ? 'librechat_single' : 'librechat';
|
const imageName = singleCompose ? 'librechat_single' : 'librechat';
|
||||||
try {
|
try {
|
||||||
execSync(`docker rmi ${imageName}:latest`, { stdio: 'inherit' });
|
execSync(`${sudo}docker rmi ${imageName}:latest`, { stdio: 'inherit' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.purple('Failed to remove Docker image librechat:latest. It might not exist.');
|
console.purple('Failed to remove Docker image librechat:latest. It might not exist.');
|
||||||
}
|
}
|
||||||
console.purple('Removing all unused dangling Docker images...');
|
console.purple('Removing all unused dangling Docker images...');
|
||||||
execSync('docker image prune -f', { stdio: 'inherit' });
|
execSync(`${sudo}docker image prune -f`, { stdio: 'inherit' });
|
||||||
console.purple('Building new LibreChat image...');
|
console.purple('Building new LibreChat image...');
|
||||||
const buildCommand = `docker-compose ${
|
const buildCommand = `${sudo}docker-compose ${
|
||||||
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
||||||
}build`;
|
}build`;
|
||||||
console.orange(buildCommand);
|
console.orange(buildCommand);
|
||||||
|
@ -119,7 +115,9 @@ function deleteNodeModules(dir) {
|
||||||
|
|
||||||
let startCommand = 'npm run backend';
|
let startCommand = 'npm run backend';
|
||||||
if (dockerUpdate) {
|
if (dockerUpdate) {
|
||||||
startCommand = `docker-compose ${singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''}up`;
|
startCommand = `${sudo}docker-compose ${
|
||||||
|
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
||||||
|
}up`;
|
||||||
}
|
}
|
||||||
console.green('Your LibreChat app is now up to date! Start the app with the following command:');
|
console.green('Your LibreChat app is now up to date! Start the app with the following command:');
|
||||||
console.purple(startCommand);
|
console.purple(startCommand);
|
||||||
|
|
|
@ -13,10 +13,12 @@
|
||||||
"update:local": "node config/update.js -l",
|
"update:local": "node config/update.js -l",
|
||||||
"update:docker": "node config/update.js -d",
|
"update:docker": "node config/update.js -d",
|
||||||
"update:single": "node config/update.js -s",
|
"update:single": "node config/update.js -s",
|
||||||
|
"update:sudo": "node config/update.js --sudo",
|
||||||
"upgrade": "node config/upgrade.js",
|
"upgrade": "node config/upgrade.js",
|
||||||
"create-user": "node config/create-user.js",
|
"create-user": "node config/create-user.js",
|
||||||
"backend": "cross-env NODE_ENV=production node api/server/index.js",
|
"backend": "cross-env NODE_ENV=production node api/server/index.js",
|
||||||
"backend:dev": "cross-env NODE_ENV=development npx nodemon api/server/index.js",
|
"backend:dev": "cross-env NODE_ENV=development npx nodemon api/server/index.js",
|
||||||
|
"backend:stop": "node config/stop-backend.js",
|
||||||
"build:data-provider": "cd packages/data-provider && npm run build",
|
"build:data-provider": "cd packages/data-provider && npm run build",
|
||||||
"frontend": "npm run build:data-provider && cd client && npm run build",
|
"frontend": "npm run build:data-provider && cd client && npm run build",
|
||||||
"frontend:ci": "npm run build:data-provider && cd client && npm run build:ci",
|
"frontend:ci": "npm run build:data-provider && cd client && npm run build:ci",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue