Merge pull request #175 from presenton/fix/script-file-endline-issue-win
fix/script file endline issue win
This commit is contained in:
commit
ee7ab1d0ba
8 changed files with 124 additions and 65 deletions
|
|
@ -1,12 +1,10 @@
|
|||
.venv
|
||||
.env
|
||||
.next
|
||||
node_modules
|
||||
out
|
||||
build
|
||||
.git
|
||||
.gitignore
|
||||
tmp
|
||||
debug
|
||||
.fastembed_cache
|
||||
generated_models
|
||||
servers/fastapi/tmp
|
||||
servers/fastapi/debug
|
||||
servers/nextjs/node_modules
|
||||
|
|
@ -49,11 +49,8 @@ COPY start.js LICENSE NOTICE ./
|
|||
# Copy nginx configuration
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Copy start script
|
||||
COPY docker-start.sh /app/docker-start.sh
|
||||
|
||||
# Expose the port
|
||||
EXPOSE 80
|
||||
|
||||
# Start the servers
|
||||
CMD ["/bin/bash", "/app/docker-start.sh"]
|
||||
CMD ["node", "/app/start.js"]
|
||||
|
|
@ -45,4 +45,4 @@ COPY nginx.conf /etc/nginx/nginx.conf
|
|||
EXPOSE 80
|
||||
|
||||
# Start the servers
|
||||
CMD ["/bin/bash", "/app/docker-dev-start.sh"]
|
||||
CMD ["node", "/app/start.js", "--dev"]
|
||||
|
|
@ -68,7 +68,6 @@ services:
|
|||
- .:/app
|
||||
- ./app_data:/app_data
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- CAN_CHANGE_KEYS=${CAN_CHANGE_KEYS}
|
||||
- LLM=${LLM}
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
|
|
@ -101,7 +100,6 @@ services:
|
|||
- .:/app
|
||||
- ./app_data:/app_data
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- CAN_CHANGE_KEYS=${CAN_CHANGE_KEYS}
|
||||
- LLM=${LLM}
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Starting development server..."
|
||||
|
||||
if [ -d "/node_dependencies/node_modules" ]; then
|
||||
rm -rf /app/servers/nextjs/node_modules
|
||||
mv /node_dependencies/node_modules /app/servers/nextjs
|
||||
fi
|
||||
|
||||
ollama serve &
|
||||
service nginx start
|
||||
service redis-server start
|
||||
node /app/start.js
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Starting production server..."
|
||||
|
||||
ollama serve &
|
||||
service nginx start
|
||||
service redis-server start
|
||||
node /app/start.js
|
||||
|
|
@ -50,16 +50,6 @@ export default function LLMProviderSelection({
|
|||
const [llmConfig, setLlmConfig] = useState<LLMConfig>(initialLLMConfig);
|
||||
const [openImageProviderSelect, setOpenImageProviderSelect] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!llmConfig.USE_CUSTOM_URL) {
|
||||
setLlmConfig({ ...llmConfig, OLLAMA_URL: "http://localhost:11434" });
|
||||
} else {
|
||||
if (!llmConfig.OLLAMA_URL) {
|
||||
setLlmConfig({ ...llmConfig, OLLAMA_URL: "http://localhost:11434" });
|
||||
}
|
||||
}
|
||||
}, [llmConfig.USE_CUSTOM_URL]);
|
||||
|
||||
useEffect(() => {
|
||||
onConfigChange(llmConfig);
|
||||
}, [llmConfig]);
|
||||
|
|
@ -79,10 +69,12 @@ export default function LLMProviderSelection({
|
|||
(llmConfig.IMAGE_PROVIDER === "pexels" && !llmConfig.PEXELS_API_KEY) ||
|
||||
(llmConfig.IMAGE_PROVIDER === "pixabay" && !llmConfig.PIXABAY_API_KEY);
|
||||
|
||||
const needsOllamaUrl = (llmConfig.LLM === "ollama" && !llmConfig.OLLAMA_URL);
|
||||
|
||||
setButtonState({
|
||||
isLoading: false,
|
||||
isDisabled: needsModelSelection || needsApiKey,
|
||||
text: needsModelSelection ? "Please Select a Model" : needsApiKey ? "Please Enter API Key" : "Save Configuration",
|
||||
isDisabled: needsModelSelection || needsApiKey || needsOllamaUrl,
|
||||
text: needsModelSelection ? "Please Select a Model" : needsApiKey ? "Please Enter API Key" : needsOllamaUrl ? "Please Enter Ollama URL" : "Save Configuration",
|
||||
showProgress: false
|
||||
});
|
||||
|
||||
|
|
@ -99,15 +91,30 @@ export default function LLMProviderSelection({
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!llmConfig.IMAGE_PROVIDER) {
|
||||
if (llmConfig.LLM === "openai") {
|
||||
setLlmConfig({ ...llmConfig, IMAGE_PROVIDER: "dall-e-3" });
|
||||
} else if (llmConfig.LLM === "google") {
|
||||
setLlmConfig({ ...llmConfig, IMAGE_PROVIDER: "gemini_flash" });
|
||||
} else {
|
||||
setLlmConfig({ ...llmConfig, IMAGE_PROVIDER: "pexels" });
|
||||
if (!llmConfig.USE_CUSTOM_URL) {
|
||||
setLlmConfig({ ...llmConfig, OLLAMA_URL: "http://localhost:11434" });
|
||||
} else {
|
||||
if (!llmConfig.OLLAMA_URL) {
|
||||
setLlmConfig({ ...llmConfig, OLLAMA_URL: "http://localhost:11434" });
|
||||
}
|
||||
}
|
||||
}, [llmConfig.USE_CUSTOM_URL]);
|
||||
|
||||
useEffect(() => {
|
||||
let updates: any = {};
|
||||
if (!llmConfig.IMAGE_PROVIDER) {
|
||||
if (llmConfig.LLM === "openai") {
|
||||
updates.IMAGE_PROVIDER = "dall-e-3";
|
||||
} else if (llmConfig.LLM === "google") {
|
||||
updates.IMAGE_PROVIDER = "gemini_flash";
|
||||
} else {
|
||||
updates.IMAGE_PROVIDER = "pexels";
|
||||
}
|
||||
}
|
||||
if (!llmConfig.OLLAMA_URL) {
|
||||
updates.OLLAMA_URL = "http://localhost:11434";
|
||||
}
|
||||
setLlmConfig({ ...llmConfig, ...updates });
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
|
|
|||
106
start.js
106
start.js
|
|
@ -1,34 +1,57 @@
|
|||
/* This script starts the FastAPI and Next.js servers, setting up user configuration if necessary. It reads environment variables to configure API keys and other settings, ensuring that the user configuration file is created if it doesn't exist. The script also handles the starting of both servers and keeps the Node.js process alive until one of the servers exits. */
|
||||
|
||||
const path = require('path');
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { spawn } from 'child_process';
|
||||
import { existsSync, mkdirSync, rmSync, cpSync, readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
const fastapiDir = path.join(__dirname, 'servers/fastapi');
|
||||
const nextjsDir = path.join(__dirname, 'servers/nextjs');
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const fastapiDir = join(__dirname, 'servers/fastapi');
|
||||
const nextjsDir = join(__dirname, 'servers/nextjs');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const hasDevArg = args.includes('--dev') || args.includes('-d');
|
||||
const isDev = hasDevArg;
|
||||
const canChangeKeys = process.env.CAN_CHANGE_KEYS !== 'false';
|
||||
|
||||
const fastapiPort = 8000;
|
||||
const nextjsPort = 3000;
|
||||
|
||||
const userConfigPath = path.join(process.env.APP_DATA_DIRECTORY, 'userConfig.json');
|
||||
const userDataDir = path.dirname(userConfigPath);
|
||||
const userConfigPath = join(process.env.APP_DATA_DIRECTORY, 'userConfig.json');
|
||||
const userDataDir = dirname(userConfigPath);
|
||||
|
||||
// Create user_data directory if it doesn't exist
|
||||
if (!fs.existsSync(userDataDir)) {
|
||||
fs.mkdirSync(userDataDir, { recursive: true });
|
||||
if (!existsSync(userDataDir)) {
|
||||
mkdirSync(userDataDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Setup node_modules for development
|
||||
const setupNodeModules = () => {
|
||||
console.log('Setting up node_modules for development...');
|
||||
const nodeDependenciesPath = '/node_dependencies/node_modules';
|
||||
const nextjsNodeModulesPath = join(nextjsDir, 'node_modules');
|
||||
|
||||
if (existsSync(nodeDependenciesPath)) {
|
||||
if (existsSync(nextjsNodeModulesPath)) {
|
||||
rmSync(nextjsNodeModulesPath, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
cpSync(nodeDependenciesPath, nextjsNodeModulesPath, { recursive: true });
|
||||
console.log('Copied node_modules from /node_dependencies to Next.js server directory');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
process.env.USER_CONFIG_PATH = userConfigPath;
|
||||
|
||||
//? UserConfig is only setup if API Keys can be changed
|
||||
const setupUserConfigFromEnv = () => {
|
||||
|
||||
let existingConfig = {};
|
||||
if (fs.existsSync(userConfigPath)) {
|
||||
existingConfig = JSON.parse(fs.readFileSync(userConfigPath, 'utf8'));
|
||||
if (existsSync(userConfigPath)) {
|
||||
existingConfig = JSON.parse(readFileSync(userConfigPath, 'utf8'));
|
||||
}
|
||||
|
||||
if (!['ollama', 'openai', 'google'].includes(existingConfig.LLM)) {
|
||||
|
|
@ -55,7 +78,7 @@ const setupUserConfigFromEnv = () => {
|
|||
USE_CUSTOM_URL: process.env.USE_CUSTOM_URL || existingConfig.USE_CUSTOM_URL,
|
||||
};
|
||||
|
||||
fs.writeFileSync(userConfigPath, JSON.stringify(userConfig));
|
||||
writeFileSync(userConfigPath, JSON.stringify(userConfig));
|
||||
}
|
||||
const startServers = async () => {
|
||||
|
||||
|
|
@ -87,17 +110,74 @@ const startServers = async () => {
|
|||
console.error("Next.js process failed to start:", err);
|
||||
});
|
||||
|
||||
const ollamaProcess = spawn(
|
||||
"ollama",
|
||||
["serve"],
|
||||
{
|
||||
cwd: "/",
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
}
|
||||
);
|
||||
|
||||
ollamaProcess.on("error", err => {
|
||||
console.error("Ollama process failed to start:", err);
|
||||
});
|
||||
|
||||
const redisProcess = spawn(
|
||||
"redis-server",
|
||||
[],
|
||||
{
|
||||
cwd: "/",
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
}
|
||||
);
|
||||
|
||||
redisProcess.on("error", err => {
|
||||
console.error("Redis process failed to start:", err);
|
||||
});
|
||||
|
||||
// Keep the Node process alive until both servers exit
|
||||
const exitCode = await Promise.race([
|
||||
new Promise(resolve => fastApiProcess.on("exit", resolve)),
|
||||
new Promise(resolve => nextjsProcess.on("exit", resolve)),
|
||||
new Promise(resolve => ollamaProcess.on("exit", resolve)),
|
||||
new Promise(resolve => redisProcess.on("exit", resolve)),
|
||||
]);
|
||||
|
||||
console.log(`One of the processes exited. Exit code: ${exitCode}`);
|
||||
process.exit(exitCode);
|
||||
};
|
||||
|
||||
// Start nginx service
|
||||
const startNginx = () => {
|
||||
const nginxProcess = spawn('service', ['nginx', 'start'], {
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
});
|
||||
|
||||
nginxProcess.on('error', err => {
|
||||
console.error('Nginx process failed to start:', err);
|
||||
});
|
||||
|
||||
nginxProcess.on('exit', (code) => {
|
||||
if (code === 0) {
|
||||
console.log('Nginx started successfully');
|
||||
} else {
|
||||
console.error(`Nginx failed to start with exit code: ${code}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (isDev) {
|
||||
setupNodeModules();
|
||||
}
|
||||
|
||||
if (canChangeKeys) {
|
||||
setupUserConfigFromEnv();
|
||||
}
|
||||
|
||||
startServers();
|
||||
|
||||
startNginx();
|
||||
Loading…
Add table
Reference in a new issue