Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bce2a0a58 | ||
|
|
14b153d73e | ||
|
|
b36011de1e | ||
|
|
c3fee31737 | ||
|
|
8ff8ed66bf | ||
|
|
9e35a8ab4d | ||
|
|
1a94e483fe | ||
|
|
abd26b2b0a | ||
|
|
18eea076d7 |
19
README.md
19
README.md
@@ -32,13 +32,18 @@ composer require --dev droath/robo-docker-compose
|
||||
|
||||
The following commands have been implemented:
|
||||
|
||||
- docker-compose up
|
||||
- docker-compose pull
|
||||
- docker-compose exec
|
||||
- docker-compose down
|
||||
- docker-compose start
|
||||
- docker-compose restart
|
||||
- docker-compose pause
|
||||
- docker-compose up - [Command Options](https://docs.docker.com/compose/reference/up)
|
||||
- docker-compose ps - [Command Options](https://docs.docker.com/compose/reference/ps)
|
||||
- docker-compose run - [Command Options](https://docs.docker.com/compose/reference/run)
|
||||
- docker-compose logs - [Command Options](https://docs.docker.com/compose/reference/logs)
|
||||
- docker-compose pull - [Command Options](https://docs.docker.com/compose/reference/pull)
|
||||
- docker-compose exec - [Command Options](https://docs.docker.com/compose/reference/exec)
|
||||
- docker-compose down - [Command Options](https://docs.docker.com/compose/reference/down)
|
||||
- docker-compose build - [Command Options](https://docs.docker.com/compose/reference/build)
|
||||
- docker-compose start - [Command Options](https://docs.docker.com/compose/reference/start)
|
||||
- docker-compose restart - [Command Options](https://docs.docker.com/compose/reference/restart)
|
||||
- docker-compose pause - [Command Options](https://docs.docker.com/compose/reference/pause)
|
||||
|
||||
|
||||
I'll be adding the rests of the docker-compose commands shortly. Or if you want
|
||||
to create a PR with additional commands that would be much appreciated.
|
||||
|
||||
66
src/DockerCommandTrait.php
Normal file
66
src/DockerCommandTrait.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose;
|
||||
|
||||
use Robo\Contract\CommandInterface;
|
||||
|
||||
/**
|
||||
* Define the docker command trait.
|
||||
*/
|
||||
trait DockerCommandTrait
|
||||
{
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* Execute container.
|
||||
*
|
||||
* @var string.
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Set docker container.
|
||||
*
|
||||
* @param $container
|
||||
* The container name.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set docker command.
|
||||
*
|
||||
* @param string|CommandInterface $command
|
||||
* The command to execute.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCommand($command)
|
||||
{
|
||||
if ($command instanceof CommandInterface) {
|
||||
$command = $command->getCommand();
|
||||
}
|
||||
$this->command = $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return parent::getCommand() . " {$this->container} {$this->command}";
|
||||
}
|
||||
}
|
||||
95
src/Task/Build.php
Executable file
95
src/Task/Build.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* Define docker compose build command.
|
||||
*/
|
||||
class Build extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'build';
|
||||
|
||||
/**
|
||||
* Compress the build context using gzip.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function compress()
|
||||
{
|
||||
$this->option('compress');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always remove intermediate containers.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forceRm()
|
||||
{
|
||||
$this->option('force-rm');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use cache when building the image.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noCache()
|
||||
{
|
||||
$this->option('no-cache');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always attempt to pull a newer version of the image.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function pull()
|
||||
{
|
||||
$this->option('pull');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets memory limit for the build container.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function memory($value)
|
||||
{
|
||||
$this->option('memory', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set build-time variables for services.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function buildArg($key, $value)
|
||||
{
|
||||
$this->option('build-arg', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -2,46 +2,20 @@
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Robo\Contract\CommandInterface;
|
||||
use Droath\RoboDockerCompose\DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* Docker compose execute command.
|
||||
*/
|
||||
class Execute extends Base
|
||||
{
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* Execute container.
|
||||
*
|
||||
* @var string.
|
||||
*/
|
||||
protected $container;
|
||||
use DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'exec';
|
||||
|
||||
/**
|
||||
* Set docker container.
|
||||
*
|
||||
* @param $container
|
||||
* The container name.
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set execute command.
|
||||
*
|
||||
@@ -52,10 +26,7 @@ class Execute extends Base
|
||||
*/
|
||||
public function exec($command)
|
||||
{
|
||||
if ($command instanceof CommandInterface) {
|
||||
$command = $command->getCommand();
|
||||
}
|
||||
$this->command = $command;
|
||||
$this->setCommand($command);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -142,12 +113,4 @@ class Execute extends Base
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return parent::getCommand() . "{$this->container} {$this->command}";
|
||||
}
|
||||
}
|
||||
|
||||
77
src/Task/Logs.php
Normal file
77
src/Task/Logs.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
use Robo\Exception\TaskException;
|
||||
|
||||
/**
|
||||
* Define the docker compose logs task.
|
||||
*/
|
||||
class Logs extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'logs';
|
||||
|
||||
/**
|
||||
* Produce monochrome output.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noColor()
|
||||
{
|
||||
$this->option('no-color');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow log output.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function follow()
|
||||
{
|
||||
$this->option('follow');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show timestamps.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function timestamps()
|
||||
{
|
||||
$this->option('timestamps');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of lines to show from the end of the logs for
|
||||
* each container.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
* @throws TaskException
|
||||
*/
|
||||
public function tail($value = 'all')
|
||||
{
|
||||
if ($value !== 'all' && !is_numeric($value)) {
|
||||
throw new TaskException(
|
||||
__CLASS__,
|
||||
'Provided argument value is invalid.'
|
||||
);
|
||||
}
|
||||
$this->option('tail', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
59
src/Task/Ps.php
Normal file
59
src/Task/Ps.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* Define the docker composer ps command.
|
||||
*/
|
||||
class Ps extends Base
|
||||
{
|
||||
use DockerServicesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'ps';
|
||||
|
||||
/**
|
||||
* Only display IDs.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function quiet()
|
||||
{
|
||||
$this->option('quiet');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display services.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function services()
|
||||
{
|
||||
$this->option('services');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter services by a property.
|
||||
*
|
||||
* @param string $key
|
||||
* The filter property key.
|
||||
* @param string $value
|
||||
* The filter property value.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function filter($key, $value)
|
||||
{
|
||||
$this->option('filter', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
218
src/Task/Run.php
Normal file
218
src/Task/Run.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Droath\RoboDockerCompose\Task;
|
||||
|
||||
use Droath\RoboDockerCompose\DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* Docker compose run command.
|
||||
*/
|
||||
class Run extends Base
|
||||
{
|
||||
use DockerCommandTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $action = 'run';
|
||||
|
||||
/**
|
||||
* Run container in the background.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
$this->option('detach');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a name to the container.
|
||||
*
|
||||
* @param $value
|
||||
* The container name.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function name($value)
|
||||
{
|
||||
$this->option('name', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the entrypoint of the image.
|
||||
*
|
||||
* @param $cmd
|
||||
* The entrypoint command.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function entrypoint($cmd)
|
||||
{
|
||||
$this->option('entrypoint', $cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param $key
|
||||
* The environment key.
|
||||
* @param $value
|
||||
* The environment value.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function envVar($key, $value)
|
||||
{
|
||||
$this->option('-e', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or override a label.
|
||||
*
|
||||
* @param $key
|
||||
* The label key.
|
||||
* @param $value
|
||||
* The label value.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function label($key, $value)
|
||||
{
|
||||
$this->option('label', "{$key}={$value}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run as specified username or uid.
|
||||
*
|
||||
* @param $user
|
||||
* The username or uid.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function user($user)
|
||||
{
|
||||
$this->option('user', $user);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't start linked services.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noDeps()
|
||||
{
|
||||
$this->option('no-deps');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove container after run.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->option('rm');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a container's port(s) to the host.
|
||||
*
|
||||
* @param $host
|
||||
* The host post.
|
||||
* @param $container
|
||||
* The container port.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function publish($host, $container)
|
||||
{
|
||||
$this->option('publish', "{$host}:{$container}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run command with the service's ports enabled and mapped
|
||||
* to the host.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function servicePorts()
|
||||
{
|
||||
$this->option('service-ports');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the service's network aliases in the network(s) the
|
||||
* container connects to.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function useAliases()
|
||||
{
|
||||
$this->option('use-aliases');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind mount a volume.
|
||||
*
|
||||
* @param $volume
|
||||
* The volume to mount.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function volume($volume)
|
||||
{
|
||||
$this->option('volume', $volume);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable pseudo-tty allocation.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disablePseudoTty()
|
||||
{
|
||||
$this->option('-T');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Working directory inside the container.
|
||||
*
|
||||
* @param $workdir
|
||||
* The directory which to run the command under.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setWorkDir($workdir)
|
||||
{
|
||||
$this->option('workdir', $workdir, '=');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,22 @@ trait loadTasks
|
||||
return $this->task(Up::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose ps task.
|
||||
*/
|
||||
protected function taskDockerComposePs($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Ps::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose logs task.
|
||||
*/
|
||||
protected function taskDockerComposeLogs($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Logs::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose down task.
|
||||
*/
|
||||
@@ -62,4 +78,20 @@ trait loadTasks
|
||||
{
|
||||
return $this->task(Execute::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose run task.
|
||||
*/
|
||||
protected function taskDockerComposeRun($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Run::class, $pathToDockerCompose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Docker compose build task.
|
||||
*/
|
||||
protected function taskDockerComposeBuild($pathToDockerCompose = null)
|
||||
{
|
||||
return $this->task(Build::class, $pathToDockerCompose);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user