feat: open Adminer directly into project database
This commit is contained in:
@@ -32,6 +32,7 @@ const configDir = (root: string): string => join(root, '.aurora')
|
||||
const configPath = (root: string): string => join(configDir(root), 'config.json')
|
||||
const composePath = (root: string): string => join(configDir(root), 'compose.yaml')
|
||||
const phpDockerfilePath = (root: string): string => join(configDir(root), 'Dockerfile.php')
|
||||
const adminerAutoLoginPath = (root: string): string => join(configDir(root), 'adminer-auto-login.php')
|
||||
const registryPath = (): string => join(app.getPath('userData'), 'projects.json')
|
||||
const routerDir = (): string => join(app.getPath('userData'), 'router')
|
||||
const routerConfigPath = (): string => join(routerDir(), 'dynamic.yaml')
|
||||
@@ -59,9 +60,33 @@ async function readConfig(root: string): Promise<AuroraConfig> {
|
||||
async function writeConfig(root: string, config: AuroraConfig): Promise<void> {
|
||||
await mkdir(configDir(root), { recursive: true })
|
||||
await writeFile(configPath(root), JSON.stringify(config, null, 2))
|
||||
await writeAdminerAutoLogin(root, config)
|
||||
await writeFile(composePath(root), await renderCompose(config))
|
||||
}
|
||||
|
||||
async function writeAdminerAutoLogin(root: string, config: AuroraConfig): Promise<void> {
|
||||
const driver = config.database === 'postgres' ? 'pgsql' : 'server'
|
||||
await writeFile(adminerAutoLoginPath(root), `<?php
|
||||
// Generated by Aurora Core. Adminer is exposed only through the project's
|
||||
// localhost route; credentials stay in this server-side container bootstrap.
|
||||
if (empty($_GET['username']) && empty($_POST['auth'])) {
|
||||
$_POST['auth'] = [
|
||||
'driver' => '${driver}',
|
||||
'server' => 'db',
|
||||
'username' => 'db',
|
||||
'password' => 'db',
|
||||
'db' => 'db',
|
||||
'permanent' => '1',
|
||||
];
|
||||
}
|
||||
return new class {
|
||||
public function credentials() { return ['db', 'db', 'db']; }
|
||||
public function database() { return 'db'; }
|
||||
public function login($login, $password) { return true; }
|
||||
};
|
||||
`)
|
||||
}
|
||||
|
||||
function indent(lines: string, spaces = 4): string {
|
||||
const pad = ' '.repeat(spaces)
|
||||
return lines.split('\n').map((line) => line ? pad + line : line).join('\n')
|
||||
@@ -96,7 +121,7 @@ async function renderCompose(c: AuroraConfig): Promise<string> {
|
||||
const extras = (await Promise.all(manifests.map((m) => renderModuleService(m, c)))).filter(Boolean)
|
||||
const volumes = [' db_data:']
|
||||
if (c.modules.includes('redis') && c.moduleSettings?.redis?.persistence !== false) volumes.push(' redis_data:')
|
||||
const adminer = c.modules.includes('adminer') ? ` adminer:\n image: adminer:5\n environment:\n ADMINER_DEFAULT_SERVER: db\n networks:\n default:\n aurora-router:\n aliases:\n - aurora-${safeName(c.name)}-adminer\n depends_on:\n db:\n condition: service_healthy` : ''
|
||||
const adminer = c.modules.includes('adminer') ? ` adminer:\n image: adminer:5\n environment:\n ADMINER_DEFAULT_SERVER: db\n volumes:\n - ./adminer-auto-login.php:/var/www/html/plugins-enabled/aurora-auto-login.php:ro\n networks:\n default:\n aurora-router:\n aliases:\n - aurora-${safeName(c.name)}-adminer\n depends_on:\n db:\n condition: service_healthy` : ''
|
||||
return `name: aurora-${safeName(c.name)}\nservices:\n web:\n image: nginx:1.29-alpine\n working_dir: /var/www/html\n volumes:\n - ../:/var/www/html\n - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro\n ports:\n - "127.0.0.1::80"\n networks:\n default:\n aurora-router:\n aliases:\n - aurora-${safeName(c.name)}-web\n depends_on:\n php:\n condition: service_started\n db:\n condition: service_healthy\n php:\n build:\n context: .\n dockerfile: Dockerfile.php\n args:\n PHP_VERSION: ${c.php}\n working_dir: /var/www/html\n volumes:\n - ../:/var/www/html\n node:\n image: node:${c.node}-alpine\n working_dir: /var/www/html\n volumes:\n - ../:/var/www/html\n command: ["sh", "-c", "sleep infinity"]\n${db}${adminer ? `\n${adminer}` : ''}${extras.length ? `\n${extras.join('\n')}` : ''}\nvolumes:\n${volumes.join('\n')}\nnetworks:\n aurora-router:\n external: true\n name: aurora-router\n`
|
||||
}
|
||||
async function writePhpDockerfile(root: string, xdebug = false): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user