diff --git a/lib/Commands/Compile.php b/lib/Commands/Compile.php index a8676c352a4ac8dcb4ce6aca1aced7a65e5b800e..770adaf6e654acab21714a2b38855b0b7ff07d39 100644 --- a/lib/Commands/Compile.php +++ b/lib/Commands/Compile.php @@ -164,10 +164,12 @@ final class Compile extends Command ]); // DB + $dbExposingPort = (int) (Config::getInstance()->get('db')['port'] ?? 3306); + $creator->addService('db', 'mariadb', [ 'container_name' => 'db', 'command' => '--sql_mode="NO_ENGINE_SUBSTITUTION"', - 'ports' => ['3306:3306'], + 'ports' => [$dbExposingPort . ':3306'], 'restart' => 'unless-stopped', 'volumes' => ['db-data:/var/lib/mysql'], 'environment' => [ diff --git a/lib/Commands/DB/Port.php b/lib/Commands/DB/Port.php new file mode 100644 index 0000000000000000000000000000000000000000..e523a79ccb42a10628a5125fbcd2fb9d5c5411d1 --- /dev/null +++ b/lib/Commands/DB/Port.php @@ -0,0 +1,40 @@ +<?php +namespace Studip\Dockerized\Commands\DB; + +use Studip\Dockerized\Config; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; + +final class Port extends Command +{ + protected function configure() + { + $this->setName('db:port'); + $this->setDescription('Change exposing port for Database (needs recompile)'); + $this->addArgument( + 'port', + InputArgument::REQUIRED, + 'Port to use' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $port = (int) $input->getArgument('port'); + + $config = Config::getInstance(); + $io = new SymfonyStyle($input, $output); + + $dbPort = $config->get('db'); + $dbPort['port'] = $port; + $config->set('db', $dbPort); + $config->store(); + + $io->success("Exposing ports of DB were changed to {$port}"); + + return Command::SUCCESS; + } +} diff --git a/studip-docker b/studip-docker index 7f8162f8bfd5508b12af7f4e276485c393809046..4ad569ed28c594e14607f74658c2a8101e524dcf 100755 --- a/studip-docker +++ b/studip-docker @@ -30,6 +30,8 @@ if (file_exists(CONFIG_FILE)) { $application->add(new Commands\Docker\Stop()); $application->add(new Commands\Keys\Create()); + + $application->add(new Commands\DB\Port()); } $application->run();