Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bce2a0a58 | ||
|
|
14b153d73e | ||
|
|
b36011de1e | ||
|
|
9e35a8ab4d | ||
|
|
1a94e483fe | ||
|
|
abd26b2b0a | ||
|
|
18eea076d7 |
21
README.md
21
README.md
@@ -32,15 +32,18 @@ composer require --dev droath/robo-docker-compose
|
|||||||
|
|
||||||
The following commands have been implemented:
|
The following commands have been implemented:
|
||||||
|
|
||||||
- docker-compose up
|
- docker-compose up - [Command Options](https://docs.docker.com/compose/reference/up)
|
||||||
- docker-compose ps
|
- docker-compose ps - [Command Options](https://docs.docker.com/compose/reference/ps)
|
||||||
- docker-compose logs
|
- docker-compose run - [Command Options](https://docs.docker.com/compose/reference/run)
|
||||||
- docker-compose pull
|
- docker-compose logs - [Command Options](https://docs.docker.com/compose/reference/logs)
|
||||||
- docker-compose exec
|
- docker-compose pull - [Command Options](https://docs.docker.com/compose/reference/pull)
|
||||||
- docker-compose down
|
- docker-compose exec - [Command Options](https://docs.docker.com/compose/reference/exec)
|
||||||
- docker-compose start
|
- docker-compose down - [Command Options](https://docs.docker.com/compose/reference/down)
|
||||||
- docker-compose restart
|
- docker-compose build - [Command Options](https://docs.docker.com/compose/reference/build)
|
||||||
- docker-compose pause
|
- 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
|
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.
|
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;
|
namespace Droath\RoboDockerCompose\Task;
|
||||||
|
|
||||||
use Robo\Contract\CommandInterface;
|
use Droath\RoboDockerCompose\DockerCommandTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Docker compose execute command.
|
* Docker compose execute command.
|
||||||
*/
|
*/
|
||||||
class Execute extends Base
|
class Execute extends Base
|
||||||
{
|
{
|
||||||
/**
|
use DockerCommandTrait;
|
||||||
* Execute command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute container.
|
|
||||||
*
|
|
||||||
* @var string.
|
|
||||||
*/
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $action = 'exec';
|
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.
|
* Set execute command.
|
||||||
*
|
*
|
||||||
@@ -52,10 +26,7 @@ class Execute extends Base
|
|||||||
*/
|
*/
|
||||||
public function exec($command)
|
public function exec($command)
|
||||||
{
|
{
|
||||||
if ($command instanceof CommandInterface) {
|
$this->setCommand($command);
|
||||||
$command = $command->getCommand();
|
|
||||||
}
|
|
||||||
$this->command = $command;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -142,12 +113,4 @@ class Execute extends Base
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getCommand()
|
|
||||||
{
|
|
||||||
return parent::getCommand() . "{$this->container} {$this->command}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,4 +78,20 @@ trait loadTasks
|
|||||||
{
|
{
|
||||||
return $this->task(Execute::class, $pathToDockerCompose);
|
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