mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
chore: add update script for assuring clean installations (#673)
This commit is contained in:
parent
8aa58ea240
commit
deb1472aa5
4 changed files with 111 additions and 6 deletions
|
@ -1,14 +1,9 @@
|
||||||
const connectDb = require('@librechat/backend/lib/db/connectDb');
|
const connectDb = require('@librechat/backend/lib/db/connectDb');
|
||||||
const migrateDb = require('@librechat/backend/lib/db/migrateDb');
|
const migrateDb = require('@librechat/backend/lib/db/migrateDb');
|
||||||
const { registerUser } = require('@librechat/backend/server/services/auth.service');
|
const { registerUser } = require('@librechat/backend/server/services/auth.service');
|
||||||
const { askQuestion } = require('./helpers');
|
const { askQuestion, silentExit } = require('./helpers');
|
||||||
const User = require('@librechat/backend/models/User');
|
const User = require('@librechat/backend/models/User');
|
||||||
|
|
||||||
const silentExit = (code = 0) => {
|
|
||||||
console.log = () => {};
|
|
||||||
process.exit(code);
|
|
||||||
};
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
/**
|
/**
|
||||||
* Connect to the database
|
* Connect to the database
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* 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 readline = require('readline');
|
const readline = require('readline');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
const askQuestion = (query) => {
|
const askQuestion = (query) => {
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
|
@ -18,6 +19,20 @@ const askQuestion = (query) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isDockerRunning() {
|
||||||
|
try {
|
||||||
|
execSync('docker info');
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const silentExit = (code = 0) => {
|
||||||
|
console.log = () => {};
|
||||||
|
process.exit(code);
|
||||||
|
};
|
||||||
|
|
||||||
// Set the console colours
|
// Set the console colours
|
||||||
console.orange = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
|
console.orange = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
|
||||||
console.green = (msg) => console.log('\x1b[32m%s\x1b[0m', msg);
|
console.green = (msg) => console.log('\x1b[32m%s\x1b[0m', msg);
|
||||||
|
@ -31,4 +46,6 @@ console.gray = (msg) => console.log('\x1b[90m%s\x1b[0m', msg);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
askQuestion,
|
askQuestion,
|
||||||
|
silentExit,
|
||||||
|
isDockerRunning,
|
||||||
};
|
};
|
||||||
|
|
90
config/update.js
Normal file
90
config/update.js
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const { askQuestion, isDockerRunning, silentExit } = require('./helpers');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const localUpdate = process.argv.includes('-l');
|
||||||
|
let dockerUpdate = process.argv.includes('-d');
|
||||||
|
|
||||||
|
if (!localUpdate) {
|
||||||
|
dockerUpdate =
|
||||||
|
dockerUpdate ||
|
||||||
|
(await askQuestion('Are you using Docker? (y/n): ')).toLowerCase().startsWith('y');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dockerUpdate && !isDockerRunning()) {
|
||||||
|
console.red(
|
||||||
|
'Error: Docker is not running. You will need to start Docker Desktop or if using linux/mac, run `sudo systemctl start docker`',
|
||||||
|
);
|
||||||
|
silentExit(1);
|
||||||
|
}
|
||||||
|
// 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'),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Function to delete node_modules
|
||||||
|
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' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch latest repo
|
||||||
|
console.purple('Fetching the latest repo...');
|
||||||
|
execSync('git fetch origin', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
// Switch to main branch
|
||||||
|
console.purple('Switching to main branch...');
|
||||||
|
execSync('git checkout main', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
// Git pull origin main
|
||||||
|
console.purple('Pulling the latest code from main...');
|
||||||
|
execSync('git pull origin main', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
if (dockerUpdate) {
|
||||||
|
console.purple('Removing previously made Docker container...');
|
||||||
|
execSync('docker-compose down --volumes', { stdio: 'inherit' });
|
||||||
|
console.purple('Pruning all LibreChat Docker images...');
|
||||||
|
try {
|
||||||
|
execSync('docker rmi librechat:latest', { stdio: 'inherit' });
|
||||||
|
} catch (e) {
|
||||||
|
console.purple('Failed to remove Docker image librechat:latest. It might not exist.');
|
||||||
|
}
|
||||||
|
console.purple('Removing all unused dangling Docker images...');
|
||||||
|
execSync('docker image prune -f', { stdio: 'inherit' });
|
||||||
|
console.purple('Building new LibreChat image...');
|
||||||
|
execSync('docker-compose build', { stdio: 'inherit' });
|
||||||
|
} else {
|
||||||
|
// 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 ci', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
// Build client-side code
|
||||||
|
console.purple('Building frontend...');
|
||||||
|
execSync('npm run frontend', { stdio: 'inherit' });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.green(
|
||||||
|
`Your LibreChat app is now up to date! Start with ${
|
||||||
|
dockerUpdate ? '`docker-compose up`' : '`npm run backend`'
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
console.orange(
|
||||||
|
'Note: it\'s also recommended to clear your browser cookies and localStorage for LibreChat to assure a fully clean installation.',
|
||||||
|
);
|
||||||
|
})();
|
|
@ -9,6 +9,9 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node config/install.js",
|
"install": "node config/install.js",
|
||||||
|
"update": "node config/update.js",
|
||||||
|
"update:local": "node config/update.js -l",
|
||||||
|
"update:docker": "node config/update.js -d",
|
||||||
"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",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue