Skip to content

Commit f9b88e2

Browse files
committed
Moving dev command to devstack
1 parent 4ed9879 commit f9b88e2

5 files changed

Lines changed: 91 additions & 5 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"illuminate/support": "^10.3",
2121
"league/flysystem": "^3.0",
2222
"symfony/console": "^6.2",
23-
"symfony/finder": "^6.2"
23+
"symfony/finder": "^6.2",
24+
"symfony/process": "^6.2"
2425
},
2526
"require-dev": {
2627
"mockery/mockery": "^1.5.1",

devstack

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
99

1010
use Symfony\Component\Console\Application;
1111
use Webteractive\Devstack\Commands\Config;
12-
use Webteractive\Devstack\Commands\DownloadRuntimes;
1312
use Webteractive\Devstack\Commands\InitStack;
13+
use Webteractive\Devstack\RegisterDockerCommands;
14+
use Webteractive\Devstack\Commands\DownloadRuntimes;
1415

1516
$app = new Application;
17+
1618
$app->add(new InitStack);
1719
$app->add(new Config);
1820
$app->add(new DownloadRuntimes);
21+
22+
RegisterDockerCommands::register($app);
23+
1924
$app->run();

src/Commands/Base.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
abstract class Base extends Command
1212
{
13+
protected $fullCommandSignature;
14+
1315
protected $name;
1416

1517
protected $signature;
@@ -20,9 +22,9 @@ abstract class Base extends Command
2022

2123
protected $hidden = false;
2224

23-
protected $input;
25+
protected InputInterface $input;
2426

25-
protected $output;
27+
protected OutputInterface $output;
2628

2729
public function __construct()
2830
{
@@ -55,8 +57,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
5557
->handle();
5658
}
5759

58-
public function setIO($input, $output)
60+
public function setIO(InputInterface $input, OutputInterface $output)
5961
{
62+
global $argv;
63+
$this->fullCommandSignature = array_slice($argv, 2);
6064
$this->input = $input;
6165
$this->output = $output;
6266
return $this;

src/Commands/RunDockerCommands.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Webteractive\Devstack\Commands;
4+
5+
use Symfony\Component\Process\Process;
6+
7+
class RunDockerCommands extends Base
8+
{
9+
public function __construct($name, $description)
10+
{
11+
$this->signature = $name;
12+
$this->description = $description;
13+
14+
$this->ignoreValidationErrors();
15+
16+
parent::__construct();
17+
}
18+
19+
public function handle(): int
20+
{
21+
[, $name] = explode(':', $this->getName());
22+
$processSignature = ['docker', 'compose', $name];
23+
$process = new Process(array_merge($processSignature, $this->fullCommandSignature));
24+
$process->setTty(true);
25+
$process->run();
26+
$process->run(function ($type, $buffer) {
27+
$this->line($buffer);
28+
});
29+
30+
return static::SUCCESS;
31+
}
32+
}

src/RegisterDockerCommands.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Webteractive\Devstack;
4+
5+
use Symfony\Component\Console\Application;
6+
use Webteractive\Devstack\Commands\RunDockerCommands;
7+
8+
class RegisterDockerCommands
9+
{
10+
protected static $commands = [
11+
'build' => 'Build or rebuild services.',
12+
'config' => 'Parse, resolve and render compose file in canonical format.',
13+
'cp' => 'Copy files/folders between a service container and the local filesystem.',
14+
'create' => 'Creates containers for a service.',
15+
'down' => 'Stop and remove containers, networks.',
16+
'events' => 'Receive real time events from containers.',
17+
'exec' => 'Execute a command in a running container.',
18+
'images' => 'List images used by the created containers.',
19+
'kill' => 'Force stop service containers.',
20+
'logs' => 'View output from containers.',
21+
'ls' => 'List running compose projects.',
22+
'pause' => 'Pause services.',
23+
'port' => 'Print the public port for a port binding.',
24+
'ps' => 'List containers.',
25+
'pull' => 'Pull service images.',
26+
'push' => 'Push service images',
27+
'restart' => 'Restart service containers.',
28+
'rm' => 'Removes stopped service containers.',
29+
'run' => 'Run a one-off command on a service.',
30+
'start' => 'Start services.',
31+
'stop' => 'Stop services.',
32+
'top' => 'Display the running processes.',
33+
'unpause' => 'Unpause services.',
34+
'up' => 'Create and start containers.',
35+
'version' => 'Show the Docker Compose version information.',
36+
];
37+
38+
public static function register(Application $app, $prefix = 'runtime')
39+
{
40+
foreach (static::$commands as $name => $description) {
41+
$app->add(new RunDockerCommands($prefix . ':' . $name, $description));
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)