-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial logs command and signal handler
- Loading branch information
1 parent
f1d7a4a
commit c55ace3
Showing
6 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ $exitCode = 0; | |
} catch (ExitException $e) { | ||
$exitCode = $e->getStatus(); | ||
} | ||
|
||
}); | ||
|
||
exit($exitCode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Component\Config\Config; | ||
use App\Helper\CommandHelper; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
#[AsCommand( | ||
name: 'logs', | ||
description: 'Show logs for given service', | ||
)] | ||
class LogsCommand extends Command | ||
{ | ||
public function __construct(private readonly Config $config) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->addArgument('namespace', InputArgument::REQUIRED); | ||
$this->addArgument('serviceName', InputArgument::REQUIRED); | ||
|
||
$this->addOption('follow', 'f', InputOption::VALUE_NONE, 'Stream logs until it cancelled'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$namespace = $input->getArgument('namespace'); | ||
$serviceName = $input->getArgument('serviceName'); | ||
$follow = $input->getOption('follow') ?? false; | ||
|
||
$cmd = ['docker', 'service', 'logs', "{$namespace}-{$serviceName}"]; | ||
$tty = false; | ||
if ($follow) { | ||
$cmd[] = '--follow'; | ||
$tty = true; | ||
} | ||
|
||
$cmd = implode(' ', $cmd); | ||
|
||
$isRunning = runOnManager(fn() => yield CommandHelper::isServiceRunning($namespace, $serviceName), $namespace); | ||
if (empty($isRunning)) { | ||
$io->error("Service {$namespace}-{$serviceName} is not running"); | ||
return Command::FAILURE; | ||
} | ||
|
||
$res = runOnManager(fn() => yield $cmd, $namespace, throwError: false, tty: $tty); | ||
|
||
if (false === $tty) { | ||
$io->writeln($res); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters