public function testBuild() { $run = new DockerRunCommand(); // Container. $run->setBinary('docker'); $this->assertFalse($run->build()); $run->setImage('foo/bar'); $command = $run->build(); $this->assertTrue(!empty($command)); // Daemon. $command = $run->build(); $this->assertEquals('docker run foo/bar', $command); $run->setDaemon(true); $command = $run->build(); $this->assertEquals('docker run -d foo/bar', $command); // Remove after run. $run->setRemove(true); $command = $run->build(); $this->assertEquals('docker run -d --rm foo/bar', $command); // Volumes. $run->addVolume('foo:bar'); $command = $run->build(); $this->assertEquals('docker run -d --rm -v foo:bar foo/bar', $command); $run->addVolume('wah:weh'); $command = $run->build(); $this->assertEquals('docker run -d --rm -v foo:bar -v wah:weh foo/bar', $command); // Links. $run->addLink('waz:wez'); $command = $run->build(); $this->assertEquals('docker run -d --rm -v foo:bar -v wah:weh --link waz:wez foo/bar', $command); $run->addLink('raz:roz'); $command = $run->build(); $this->assertEquals('docker run -d --rm -v foo:bar -v wah:weh --link waz:wez --link raz:roz foo/bar', $command); // Entry point command. $run->setCommand('test 1 2 3'); $command = $run->build(); $this->assertEquals('docker run -d --rm -v foo:bar -v wah:weh --link waz:wez --link raz:roz foo/bar test 1 2 3', $command); }
/** * Adds a container service to the permutation. */ public function addService($service) { // Convert the service name to uppercase for bash variables. $uppercase_service = str_replace("-", "_", strtoupper($service)); $namespace = $this->getNamespace(); // Build the service command. $run = new DockerRunCommand(); $run->setDaemon(true); // $run->setRemove(true); $run->setImage($namespace . '/' . $service); // Privileged. $privileged = $this->getPrivileged(); if ($privileged) { $run->setPrivileged(true); } $command = $run->build(); $this->addStep($uppercase_service . '_ID=$(' . $command . ')'); // Build the inspect command. $run = new DockerInspectCommand(); $run->setFormat('{{ .Name }}'); $run->setContainer('$' . $uppercase_service . '_ID'); $run->setCommand('| cut -d "/" -f 2'); $command = $run->build(); $this->addStep($uppercase_service . '=$(' . $command . ')'); // Add a link so we can access these services from the main container. $this->addLink('$' . $uppercase_service . ':' . $service); }