mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
feat(config/update.js): add support for updating with single-compose file (#680)
This commit is contained in:
parent
2a2e6d9991
commit
e38483a8b9
3 changed files with 74 additions and 33 deletions
102
config/update.js
102
config/update.js
|
|
@ -3,39 +3,67 @@ const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { askQuestion, isDockerRunning, silentExit } = require('./helpers');
|
const { askQuestion, isDockerRunning, silentExit } = require('./helpers');
|
||||||
|
|
||||||
(async () => {
|
const config = {
|
||||||
const localUpdate = process.argv.includes('-l');
|
localUpdate: process.argv.includes('-l'),
|
||||||
let dockerUpdate = process.argv.includes('-d');
|
dockerUpdate: process.argv.includes('-d'),
|
||||||
|
useSingleComposeFile: process.argv.includes('-s'),
|
||||||
|
};
|
||||||
|
|
||||||
if (!localUpdate) {
|
// Set the directories
|
||||||
dockerUpdate =
|
const rootDir = path.resolve(__dirname, '..');
|
||||||
dockerUpdate ||
|
const directories = [
|
||||||
(await askQuestion('Are you using Docker? (y/n): ')).toLowerCase().startsWith('y');
|
rootDir,
|
||||||
|
path.resolve(rootDir, 'packages', 'data-provider'),
|
||||||
|
path.resolve(rootDir, 'client'),
|
||||||
|
path.resolve(rootDir, 'api'),
|
||||||
|
];
|
||||||
|
|
||||||
|
async function updateConfigWithWizard() {
|
||||||
|
if (!config.dockerUpdate && !config.useSingleComposeFile) {
|
||||||
|
config.dockerUpdate = (await askQuestion('Are you using Docker? (y/n): '))
|
||||||
|
.toLowerCase()
|
||||||
|
.startsWith('y');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dockerUpdate && !isDockerRunning()) {
|
if (config.dockerUpdate && !config.useSingleComposeFile) {
|
||||||
|
config.useSingleComposeFile = !(
|
||||||
|
await askQuestion('Are you using the default docker-compose file? (y/n): ')
|
||||||
|
)
|
||||||
|
.toLowerCase()
|
||||||
|
.startsWith('y');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function validateDockerRunning() {
|
||||||
|
if (!config.dockerUpdate && config.useSingleComposeFile) {
|
||||||
|
config.dockerUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.dockerUpdate && !isDockerRunning()) {
|
||||||
console.red(
|
console.red(
|
||||||
'Error: Docker is not running. You will need to start Docker Desktop or if using linux/mac, run `sudo systemctl start docker`',
|
'Error: Docker is not running. You will need to start Docker Desktop or if using linux/mac, run `sudo systemctl start docker`',
|
||||||
);
|
);
|
||||||
silentExit(1);
|
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) {
|
||||||
function deleteNodeModules(dir) {
|
const nodeModulesPath = path.join(dir, 'node_modules');
|
||||||
const nodeModulesPath = path.join(dir, 'node_modules');
|
if (fs.existsSync(nodeModulesPath)) {
|
||||||
if (fs.existsSync(nodeModulesPath)) {
|
console.purple(`Deleting node_modules in ${dir}`);
|
||||||
console.purple(`Deleting node_modules in ${dir}`);
|
execSync(`rd /s /q "${nodeModulesPath}"`, { stdio: 'inherit', shell: 'cmd.exe' });
|
||||||
execSync(`rd /s /q "${nodeModulesPath}"`, { stdio: 'inherit', shell: 'cmd.exe' });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const showWizard = !config.localUpdate && !config.dockerUpdate && !config.useSingleComposeFile;
|
||||||
|
|
||||||
|
if (showWizard) {
|
||||||
|
await updateConfigWithWizard();
|
||||||
|
}
|
||||||
|
|
||||||
|
await validateDockerRunning();
|
||||||
|
const { dockerUpdate, useSingleComposeFile: singleCompose } = config;
|
||||||
|
|
||||||
// Fetch latest repo
|
// Fetch latest repo
|
||||||
console.purple('Fetching the latest repo...');
|
console.purple('Fetching the latest repo...');
|
||||||
|
|
@ -51,17 +79,27 @@ const { askQuestion, isDockerRunning, silentExit } = require('./helpers');
|
||||||
|
|
||||||
if (dockerUpdate) {
|
if (dockerUpdate) {
|
||||||
console.purple('Removing previously made Docker container...');
|
console.purple('Removing previously made Docker container...');
|
||||||
execSync('docker-compose down --volumes', { stdio: 'inherit' });
|
const downCommand = `docker-compose ${
|
||||||
|
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
||||||
|
}down --volumes`;
|
||||||
|
console.orange(downCommand);
|
||||||
|
execSync(downCommand, { stdio: 'inherit' });
|
||||||
console.purple('Pruning all LibreChat Docker images...');
|
console.purple('Pruning all LibreChat Docker images...');
|
||||||
|
|
||||||
|
const imageName = singleCompose ? 'librechat_single' : 'librechat';
|
||||||
try {
|
try {
|
||||||
execSync('docker rmi librechat:latest', { stdio: 'inherit' });
|
execSync(`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('docker image prune -f', { stdio: 'inherit' });
|
||||||
console.purple('Building new LibreChat image...');
|
console.purple('Building new LibreChat image...');
|
||||||
execSync('docker-compose build', { stdio: 'inherit' });
|
const buildCommand = `docker-compose ${
|
||||||
|
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
|
||||||
|
}build`;
|
||||||
|
console.orange(buildCommand);
|
||||||
|
execSync(buildCommand, { stdio: 'inherit' });
|
||||||
} else {
|
} else {
|
||||||
// Delete all node_modules
|
// Delete all node_modules
|
||||||
directories.forEach(deleteNodeModules);
|
directories.forEach(deleteNodeModules);
|
||||||
|
|
@ -79,12 +117,14 @@ const { askQuestion, isDockerRunning, silentExit } = require('./helpers');
|
||||||
execSync('npm run frontend', { stdio: 'inherit' });
|
execSync('npm run frontend', { stdio: 'inherit' });
|
||||||
}
|
}
|
||||||
|
|
||||||
console.green(
|
let startCommand = 'npm run backend';
|
||||||
`Your LibreChat app is now up to date! Start with ${
|
if (dockerUpdate) {
|
||||||
dockerUpdate ? '`docker-compose up`' : '`npm run backend`'
|
startCommand = `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.purple(startCommand);
|
||||||
console.orange(
|
console.orange(
|
||||||
'Note: it\'s also recommended to clear your browser cookies and localStorage for LibreChat to assure a fully clean installation.',
|
'Note: it\'s also recommended to clear your browser cookies and localStorage for LibreChat to assure a fully clean installation.',
|
||||||
);
|
);
|
||||||
|
console.orange('Also: Don\'t worry, your data is safe :)');
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ version: "3.4"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
api:
|
api:
|
||||||
container_name: LibreChat-App
|
container_name: LibreChat_Single
|
||||||
ports:
|
ports:
|
||||||
- 3080:3080 # Change it to 9000:3080 to use nginx
|
- 3080:3080 # Change it to 9000:3080 to use nginx
|
||||||
image: librechat # Comment this & uncomment below to build from docker hub image
|
image: librechat_single # Comment this & uncomment below to build from docker hub image
|
||||||
build: # ^------
|
build: # ^------
|
||||||
context: ../../ # ^------
|
context: ../../ # ^------
|
||||||
target: node # ^------v
|
target: node # ^------v
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
"update": "node config/update.js",
|
"update": "node config/update.js",
|
||||||
"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",
|
||||||
"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