Docker-PHP/doc/gen

131 lines
3.4 KiB
PHP
Executable file

#!/usr/bin/php
<?php
require_once(__DIR__ . "/vendor/autoload.php");
$versionedPhpImages = [
'gone/php:cli-php%php_version%',
'gone/php:apache-php%php_version%',
'gone/php:nginx-php%php_version%',
];
$phpVersions = ['5.6', '7.0', '7.1', '7.2', '7.3', ];
$nodeVariants = ['', '-gcc', '-onbuild', '-onbuild-gcc'];
$nodeVersionsMajor = ['8', '10', '11', '12'];
$images = [
'gone/marshall:latest',
'gone/php:cli',
'gone/php:apache',
'gone/php:nginx',
];
foreach($nodeVersionsMajor as $majorVersion){
foreach($nodeVariants as $variant){
$nodeVersions[] = $majorVersion . $variant;
}
}
foreach($versionedPhpImages as $versionedImage){
foreach($phpVersions as $phpVersion){
$images[] = str_replace("%php_version%", $phpVersion, $versionedImage);
}
}
foreach($nodeVersions as $nodeVersion){
$images[] = "gone/node:{$nodeVersion}";
}
sort($images);
use AdamBrett\ShellWrapper\Runners;
use AdamBrett\ShellWrapper\Command;
use React\EventLoop\Factory as LoopFactory;
use React\ChildProcess\Process;
shuffle($images);
$images = array_slice($images, 0,2);
\Kint::dump($images);
$loop = LoopFactory::create();
// Iterate and pull images
foreach($images as $image) {
$shell = new Runners\ShellExec();
$command = new Command("docker");
$command->addSubCommand(new Command\SubCommand("pull"));
$command->addParam(new Command\Param($image));
echo sprintf(
'Running: "%s"' . PHP_EOL,
(string) $command
);
$process = new Process((string) $command);
$process->start($loop);
$process->stdout->on('data', function($chunk){
#echo $chunk;
});
$process->stderr->on('data', function($chunk){
echo $chunk;
});
$process->on('exit', function($exitCode, $termSignal) use ($command) {
if($exitCode == 0){
echo sprintf(
'Process "%s", succeeded!' . PHP_EOL,
(string) $command
);
}else{
echo sprintf(
'Process "%s", exited with code %d' . PHP_EOL,
(string) $command,
$exitCode
);
echo "\n\n";
exit(255);
}
});
}
$loop->run();
// Iterate and weigh images.
$weights = [];
foreach($images as $image) {
$shell = new Runners\ShellExec();
$command = new Command("docker");
$command->addSubCommand(new Command\SubCommand("images"));
$command->addParam(new Command\Param($image));
$command->addFlag(new Command\Flag("format", "{{json .}}"));
echo sprintf(
'Running: "%s"' . PHP_EOL,
(string) $command
);
$process = new Process((string) $command);
$process->start($loop);
$process->stdout->on('data', function($chunk) use ($weights){
\Kint::dump(
json_decode($chunk)
);
});
$process->stderr->on('data', function($chunk){
echo $chunk;
});
$process->on('exit', function($exitCode, $termSignal) use ($command) {
if($exitCode == 0){
echo sprintf(
'Process "%s", succeeded!' . PHP_EOL,
(string) $command
);
}else{
echo sprintf(
'Process "%s", exited with code %d' . PHP_EOL,
(string) $command,
$exitCode
);
echo "\n\n";
exit(255);
}
});
}
$loop->run();