Add full REST API for all deployment operations (projects, servers, docker)
Port all IPC handlers to HTTP endpoints so the UI and LLM use the same API. Adds routes/projects.js (scan, compare, init), routes/servers.js (CRUD, containers, logs), routes/docker.js (build, deploy, pull, vscode-diff). Enhanced ssh.js with full SSHService class (SFTP upload/download). Updated renderer api.js to use fetch instead of window.api IPC. Added concurrently for npm run dev (API + Vite + Electron). OpenAPI spec now covers all 24 endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,24 +1,81 @@
|
||||
import { readFileSync, existsSync } from 'fs';
|
||||
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PROJECT_ROOT = join(__dirname, '..', '..');
|
||||
|
||||
// Shared config from gitea.repo.management
|
||||
const CONFIG_PATH = join(__dirname, '..', '..', '..', 'gitea.repo.management', 'config.json');
|
||||
// Shared Coolify config from gitea.repo.management
|
||||
const COOLIFY_CONFIG_PATH = join(PROJECT_ROOT, '..', 'gitea.repo.management', 'config.json');
|
||||
|
||||
let _cached = null;
|
||||
// Local deployment config
|
||||
const DEPLOY_CONFIG_PATH = join(PROJECT_ROOT, 'deployment-config.json');
|
||||
|
||||
// SSH credentials from app/.env
|
||||
const ENV_PATH = join(PROJECT_ROOT, 'app', '.env');
|
||||
|
||||
let _coolifyCache = null;
|
||||
let _deployCache = null;
|
||||
|
||||
export function loadConfig() {
|
||||
if (_cached) return _cached;
|
||||
if (!existsSync(CONFIG_PATH)) {
|
||||
throw new Error(`Config not found at ${CONFIG_PATH}`);
|
||||
if (_coolifyCache) return _coolifyCache;
|
||||
if (!existsSync(COOLIFY_CONFIG_PATH)) {
|
||||
throw new Error(`Coolify config not found at ${COOLIFY_CONFIG_PATH}`);
|
||||
}
|
||||
_cached = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
|
||||
return _cached;
|
||||
_coolifyCache = JSON.parse(readFileSync(COOLIFY_CONFIG_PATH, 'utf8'));
|
||||
return _coolifyCache;
|
||||
}
|
||||
|
||||
export function reloadConfig() {
|
||||
_cached = null;
|
||||
_coolifyCache = null;
|
||||
return loadConfig();
|
||||
}
|
||||
|
||||
export function loadDeployConfig() {
|
||||
if (_deployCache) return _deployCache;
|
||||
if (!existsSync(DEPLOY_CONFIG_PATH)) {
|
||||
_deployCache = { servers: [], projectsRoot: 'C:\\.bucket\\repos.gitea', projects: {} };
|
||||
return _deployCache;
|
||||
}
|
||||
_deployCache = JSON.parse(readFileSync(DEPLOY_CONFIG_PATH, 'utf8'));
|
||||
return _deployCache;
|
||||
}
|
||||
|
||||
export function saveDeployConfig(config) {
|
||||
writeFileSync(DEPLOY_CONFIG_PATH, JSON.stringify(config, null, 2));
|
||||
_deployCache = config;
|
||||
}
|
||||
|
||||
export function reloadDeployConfig() {
|
||||
_deployCache = null;
|
||||
return loadDeployConfig();
|
||||
}
|
||||
|
||||
export function loadEnv() {
|
||||
if (!existsSync(ENV_PATH)) return {};
|
||||
const content = readFileSync(ENV_PATH, 'utf8');
|
||||
const env = {};
|
||||
for (const line of content.split('\n')) {
|
||||
if (line.startsWith('#') || !line.includes('=')) continue;
|
||||
const [key, ...valueParts] = line.split('=');
|
||||
if (key && valueParts.length > 0) {
|
||||
env[key.trim()] = valueParts.join('=').trim();
|
||||
}
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
export function getProjectsRoot() {
|
||||
return loadDeployConfig().projectsRoot || 'C:\\.bucket\\repos.gitea';
|
||||
}
|
||||
|
||||
export function getServerSshConfig(server) {
|
||||
const env = loadEnv();
|
||||
return {
|
||||
host: server.host,
|
||||
port: 22,
|
||||
username: env.SSH_USERNAME || server.username,
|
||||
password: env.SSH_PASSWORD || server.password,
|
||||
useSudo: server.useSudo || false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user