Initial Drupal 11 with DDEV setup

This commit is contained in:
gluebox
2025-10-08 11:39:17 -04:00
commit 89ef74b305
25344 changed files with 2599172 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace Robo\Task\Docker;
use Robo\Common\ExecOneCommand;
use Robo\Contract\CommandInterface;
use Robo\Contract\PrintedInterface;
use Robo\Task\BaseTask;
abstract class Base extends BaseTask implements CommandInterface, PrintedInterface
{
use ExecOneCommand;
/**
* @var string
*/
protected $command = '';
/**
* {@inheritdoc}
*/
public function run()
{
$command = $this->getCommand();
return $this->executeCommand($command);
}
abstract public function getCommand();
}

View File

@ -0,0 +1,74 @@
<?php
namespace Robo\Task\Docker;
/**
* Builds Docker image
*
* ```php
* <?php
* $this->taskDockerBuild()->run();
*
* $this->taskDockerBuild('path/to/dir')
* ->tag('database')
* ->run();
*
* ?>
*
* ```
*
* Class Build
* @package Robo\Task\Docker
*/
class Build extends Base
{
/**
* @var string
*/
protected $path;
/**
* @var bool
*/
protected $buildKit = false;
/**
* @param string $path
*/
public function __construct($path = '.')
{
$this->command = "docker build";
$this->path = $path;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
$command = $this->command;
if ($this->buildKit) {
$command = 'DOCKER_BUILDKIT=1 ' . $command;
}
return $command . ' ' . $this->arguments . ' ' . $this->path;
}
/**
* @param string $tag
*
* @return $this
*/
public function tag($tag)
{
return $this->option('-t', $tag);
}
/**
* @return $this
*/
public function enableBuildKit()
{
$this->buildKit = true;
return $this;
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace Robo\Task\Docker;
/**
* Commits docker container to an image
*
* ```
* $this->taskDockerCommit($containerId)
* ->name('my/database')
* ->run();
*
* // alternatively you can take the result from DockerRun task:
*
* $result = $this->taskDockerRun('db')
* ->exec('./prepare_database.sh')
* ->run();
*
* $task->dockerCommit($result)
* ->name('my/database')
* ->run();
* ```
*/
class Commit extends Base
{
/**
* @var string
*/
protected $command = "docker commit";
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $cid;
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*/
public function __construct($cidOrResult)
{
$this->cid = $cidOrResult instanceof Result ? $cidOrResult->getCid() : $cidOrResult;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return $this->command . ' ' . $this->cid . ' ' . $this->name . ' ' . $this->arguments;
}
/**
* @param string $name
*
* @return $this
*/
public function name($name)
{
$this->name = $name;
return $this;
}
}

View File

@ -0,0 +1,96 @@
<?php
namespace Robo\Task\Docker;
use Robo\Common\CommandReceiver;
/**
* Executes command inside running Docker container
*
* ```php
* <?php
* $test = $this->taskDockerRun('test_env')
* ->detached()
* ->run();
*
* $this->taskDockerExec($test)
* ->interactive()
* ->exec('./runtests')
* ->run();
*
* // alternatively use commands from other tasks
*
* $this->taskDockerExec($test)
* ->interactive()
* ->exec($this->taskCodecept()->suite('acceptance'))
* ->run();
* ?>
* ```
*
*/
class Exec extends Base
{
use CommandReceiver;
/**
* @var string
*/
protected $command = "docker exec";
/**
* @var string
*/
protected $cid;
/**
* @var string
*/
protected $run = '';
/**
* @param string|\Robo\Result $cidOrResult
*/
public function __construct($cidOrResult)
{
$this->cid = $cidOrResult instanceof Result ? $cidOrResult->getCid() : $cidOrResult;
}
/**
* @return $this
*/
public function detached()
{
$this->option('-d');
return $this;
}
/**
* {@inheritdoc}
*/
public function interactive($interactive = true)
{
if ($interactive) {
$this->option('-i');
}
return parent::interactive($interactive);
}
/**
* @param string|\Robo\Contract\CommandInterface $command
*
* @return $this
*/
public function exec($command)
{
$this->run = $this->receiveCommand($command);
return $this;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return $this->command . ' ' . $this->arguments . ' ' . $this->cid . ' ' . $this->run;
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Robo\Task\Docker;
/**
* Pulls an image from DockerHub
*
* ```php
* <?php
* $this->taskDockerPull('wordpress')
* ->run();
*
* ?>
* ```
*
*/
class Pull extends Base
{
/**
* @param string $image
*/
public function __construct($image)
{
$this->command = "docker pull $image ";
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return $this->command . ' ' . $this->arguments;
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Robo\Task\Docker;
/**
* Remove docker container
*
* ```php
* <?php
* $this->taskDockerRemove($container)
* ->run();
* ?>
* ```
*
*/
class Remove extends Base
{
/**
* @param string $container
*/
public function __construct($container)
{
$this->command = "docker rm $container ";
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return $this->command . ' ' . $this->arguments;
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Robo\Task\Docker;
class Result extends \Robo\Result
{
/**
* Do not print result, as it was already printed
*/
protected function printResult()
{
}
/**
* @return null|string
*/
public function getCid()
{
if (isset($this['cid'])) {
return $this['cid'];
}
return null;
}
/**
* @return null|string
*/
public function getContainerName()
{
if (isset($this['name'])) {
return $this['name'];
}
return null;
}
}

View File

@ -0,0 +1,303 @@
<?php
namespace Robo\Task\Docker;
use Robo\Common\CommandReceiver;
/**
* Performs `docker run` on a container.
*
* ```php
* <?php
* $this->taskDockerRun('mysql')->run();
*
* $result = $this->taskDockerRun('my_db_image')
* ->env('DB', 'database_name')
* ->volume('/path/to/data', '/data')
* ->detached()
* ->publish(3306)
* ->name('my_mysql')
* ->run();
*
* // retrieve container's cid:
* $this->say("Running container ".$result->getCid());
*
* // execute script inside container
* $result = $this->taskDockerRun('db')
* ->exec('prepare_test_data.sh')
* ->run();
*
* $this->taskDockerCommit($result)
* ->name('test_db')
* ->run();
*
* // link containers
* $mysql = $this->taskDockerRun('mysql')
* ->name('wp_db') // important to set name for linked container
* ->env('MYSQL_ROOT_PASSWORD', '123456')
* ->run();
*
* $this->taskDockerRun('wordpress')
* ->link($mysql)
* ->publish(80, 8080)
* ->detached()
* ->run();
*
* ?>
* ```
*
*/
class Run extends Base
{
use CommandReceiver;
/**
* @var string
*/
protected $image = '';
/**
* @var string
*/
protected $run = '';
/**
* @var string
*/
protected $cidFile;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $dir;
/**
* @param string $image
*/
public function __construct($image)
{
$this->image = $image;
}
/**
* {@inheritdoc}
*/
public function getPrinted()
{
return $this->isPrinted;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
if ($this->isPrinted) {
$this->option('-i');
}
if ($this->cidFile) {
$this->option('cidfile', $this->cidFile);
}
return trim('docker run ' . $this->arguments . ' ' . $this->image . ' ' . $this->run);
}
/**
* @return $this
*/
public function detached()
{
$this->option('-d');
return $this;
}
/**
* {@inheritdoc}
*/
public function interactive($interactive = true)
{
if ($interactive) {
$this->option('-i');
}
return parent::interactive($interactive);
}
/**
* @param string|\Robo\Contract\CommandInterface $run
*
* @return $this
*/
public function exec($run)
{
$this->run = $this->receiveCommand($run);
return $this;
}
/**
* @param string $from
* @param null|string $to
*
* @return $this
*/
public function volume($from, $to = null)
{
$volume = $to ? "$from:$to" : $from;
$this->option('-v', $volume);
return $this;
}
/**
* Set environment variables.
* n.b. $this->env($variable, $value) also available here,
* inherited from ExecTrait.
*
* @param array $env
*
* @return $this
*/
public function envVars(array $env)
{
foreach ($env as $variable => $value) {
$this->setDockerEnv($variable, $value);
}
return $this;
}
/**
* @param string $variable
* @param null|string $value
*
* @return $this
*/
protected function setDockerEnv($variable, $value = null)
{
$env = $value ? "$variable=$value" : $variable;
return $this->option("-e", $env);
}
/**
* @param null|int $port
* @param null|int $portTo
*
* @return $this
*/
public function publish($port = null, $portTo = null)
{
if (!$port) {
return $this->option('-P');
}
if ($portTo) {
$port = "$port:$portTo";
}
return $this->option('-p', $port);
}
/**
* @param string $dir
*
* @return $this
*/
public function containerWorkdir($dir)
{
return $this->option('-w', $dir);
}
/**
* @param string $user
*
* @return $this
*/
public function user($user)
{
return $this->option('-u', $user);
}
/**
* @return $this
*/
public function privileged()
{
return $this->option('--privileged');
}
/**
* @param string $name
*
* @return $this
*/
public function name($name)
{
$this->name = $name;
return $this->option('name', $name);
}
/**
* @param string|\Robo\Task\Docker\Result $name
* @param string $alias
*
* @return $this
*/
public function link($name, $alias)
{
if ($name instanceof Result) {
$name = $name->getContainerName();
}
$this->option('link', "$name:$alias");
return $this;
}
/**
* @param string $dir
*
* @return $this
*/
public function tmpDir($dir)
{
$this->dir = $dir;
return $this;
}
/**
* @return string
*/
public function getTmpDir()
{
return $this->dir ? $this->dir : sys_get_temp_dir();
}
/**
* @return string
*/
public function getUniqId()
{
return uniqid();
}
/**
* {@inheritdoc}
*/
public function run()
{
$this->cidFile = $this->getTmpDir() . '/docker_' . $this->getUniqId() . '.cid';
$result = parent::run();
$result['cid'] = $this->getCid();
return $result;
}
/**
* @return null|string
*/
protected function getCid()
{
if (!$this->cidFile || !file_exists($this->cidFile)) {
return null;
}
$cid = trim(file_get_contents($this->cidFile));
@unlink($this->cidFile);
return $cid;
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Robo\Task\Docker;
/**
* Starts Docker container
*
* ```php
* <?php
* $this->taskDockerStart($cidOrResult)
* ->run();
* ?>
* ```
*/
class Start extends Base
{
/**
* @var string
*/
protected $command = "docker start";
/**
* @var null|string
*/
protected $cid;
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*/
public function __construct($cidOrResult)
{
$this->cid = $cidOrResult instanceof Result ? $cidOrResult->getCid() : $cidOrResult;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return $this->command . ' ' . $this->arguments . ' ' . $this->cid;
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Robo\Task\Docker;
/**
* Stops Docker container
*
* ```php
* <?php
* $this->taskDockerStop($cidOrResult)
* ->run();
* ?>
* ```
*/
class Stop extends Base
{
/**
* @var string
*/
protected $command = "docker stop";
/**
* @var null|string
*/
protected $cid;
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*/
public function __construct($cidOrResult)
{
$this->cid = $cidOrResult instanceof Result ? $cidOrResult->getCid() : $cidOrResult;
}
/**
* {@inheritdoc}
*/
public function getCommand()
{
return $this->command . ' ' . $this->arguments . ' ' . $this->cid;
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace Robo\Task\Docker;
trait Tasks
{
/**
* @param string $image
*
* @return \Robo\Task\Docker\Run|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerRun($image)
{
return $this->task(Run::class, $image);
}
/**
* @param string $image
*
* @return \Robo\Task\Docker\Pull|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerPull($image)
{
return $this->task(Pull::class, $image);
}
/**
* @param string $path
*
* @return \Robo\Task\Docker\Build|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerBuild($path = '.')
{
return $this->task(Build::class, $path);
}
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*
* @return \Robo\Task\Docker\Stop|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerStop($cidOrResult)
{
return $this->task(Stop::class, $cidOrResult);
}
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*
* @return \Robo\Task\Docker\Commit|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerCommit($cidOrResult)
{
return $this->task(Commit::class, $cidOrResult);
}
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*
* @return \Robo\Task\Docker\Start|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerStart($cidOrResult)
{
return $this->task(Start::class, $cidOrResult);
}
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*
* @return \Robo\Task\Docker\Remove|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerRemove($cidOrResult)
{
return $this->task(Remove::class, $cidOrResult);
}
/**
* @param string|\Robo\Task\Docker\Result $cidOrResult
*
* @return \Robo\Task\Docker\Exec|\Robo\Collection\CollectionBuilder
*/
protected function taskDockerExec($cidOrResult)
{
return $this->task(Exec::class, $cidOrResult);
}
}