Misc fixes, templates

This commit is contained in:
Chris 2024-03-02 17:10:30 +01:00
parent 61f4f767c6
commit df3e1211af
7 changed files with 27 additions and 9 deletions

View File

@ -2,6 +2,7 @@
"$type": "service",
"name": "mailhog",
"description": "SMTP server that holds e-mail for debugging",
"info": "Mailhog accepts e-mails from any configured app over SMTP for use during development. Received messages can be displayed in the web interface.",
"tags": [ "app", "mail", "smtp" ],
"author": null,
"image": "mailhog/mailhog",

View File

@ -2,6 +2,7 @@
"$type": "service",
"name": "mariadb",
"description": "MariaDB RDBMS (MySQL fork)",
"info": "MariaDB is a mostly MySQL compatible relational database server.",
"help": "Default credentials are root/toor",
"tags": [ "rdbms", "mysql" ],
"author": null,
@ -16,17 +17,17 @@
{ "path": "/data", "hint": "data" }
],
"scripts": {
"mongosh": {
"info": "Open the mongo shell",
"execute": "mongosh"
"shell": {
"info": "Open the MariaDB shell",
"execute": [ "mysql", "-uroot", "-p${MARIADB_ROOT_PASSWORD}" ]
},
"export": {
"info": "Export the database",
"execute": "mysqldump "
"execute": "mysqldump -uroot -p${MARIADB_ROOT_PASSWORD} --all-databases"
},
"import": {
"info": "Import the database",
"execute": "mongoimport"
"execute": "mysql -uroot -p${MARIADB_ROOT_PASSWORD}"
}
}
}

View File

@ -18,7 +18,8 @@
"scripts": {
"shell": {
"info": "Open the mongo shell",
"execute": "mongosh"
"execute": "mongosh",
"arguments": [ "-u", "root", "-p", "toor" ]
},
"export": {
"info": "Export the database",

View File

@ -17,7 +17,7 @@
],
"scripts": {
"shell": {
"info": "Open the mongo shell",
"info": "Open the MySQL shell",
"execute": "mysql -uroot -p%{MARIADB_ROOT_PASSWORD}"
},
"export": {

View File

@ -41,12 +41,16 @@ class ExecCommand extends Command
return self::SUCCESS;
} elseif ($input->getOption("script")) {
$script = $serviceInfo['scripts'][$command]['execute']??null;
$scriptArgs = $serviceInfo['scripts'][$command]['arguments']??null;
if (!$script) {
$output->writeln("<error>No such script</>");
return self::FAILURE;
}
$cmdl = [ is_array($script)?join("; ", $script):$script ];
if ($scriptArgs)
$cmdl = [ $script, ...$scriptArgs ]; // is_array($script)?join("; ", $script):$script ];
else
$cmdl = $script;
$containerManager->execute($serviceInfo, $instanceName, $cmdl);
} else {
@ -58,4 +62,4 @@ class ExecCommand extends Command
return self::SUCCESS;
}
}
}

View File

@ -17,6 +17,7 @@ class FindCommand extends Command
$this->addArgument("service", InputArgument::OPTIONAL, "Search query");
$this->addOption("environment", "E", InputOption::VALUE_NONE, "Show the environment for the services");
$this->addOption("ports", "P", InputOption::VALUE_NONE, "Show the ports for the services");
$this->addOption("info", "I", InputOption::VALUE_NONE, "Show service information text if available");
}
protected function execute(InputInterface $input, OutputInterface $output)
@ -25,10 +26,12 @@ class FindCommand extends Command
$printEnvs = $input->getOption("environment");
$printPorts = $input->getOption("ports");
$showInfo = $input->getOption("info");
$services = $serviceRegistry->findAllServices();
$query = $input->getArgument("service");
$output->writeln($query?"Services matching <options=bold>{$query}</>:":"Available services:");
foreach ($services as $service) {
$tags = $service['tags']??[];
@ -42,6 +45,10 @@ class FindCommand extends Command
$tags = "";
}
$output->writeln(sprintf(" <comment>%s</>: <info>%s</> <fg=cyan>%s</>", $service['name'], $service['description']??"?", $tags));
if ($showInfo && array_key_exists('info', $service)) {
$info = " ".strtr(wordwrap($service['info']), [ "\n" => "\n " ]);
$output->writeln("<fg=bright-green>".$info."</>");
}
if ($printEnvs) {
foreach ($service['environment']??[] as $env=>$value) {
$output->writeln(sprintf(" <fg=cyan>%s</>=<fg=magenta>%s</>", $env, $value));

View File

@ -251,6 +251,10 @@ class ContainerManager
$cmdl = 'docker '.join(' ',array_map('escapeshellarg', $args));
$cmdl = preg_replace_callback('<\$\{(.+?)\}>', function ($v) use ($service) {
return $service['environment'][$v[1]]??null;
}, $cmdl);
echo "$ {$cmdl}\n";
passthru($cmdl);