public function testWritesRunCommands() { $contextBuilder = new ContextBuilder(); $contextBuilder->run('foo command'); $context = $contextBuilder->getContext(); $this->assertStringEqualsFile($context->getDirectory() . '/Dockerfile', <<<DOCKERFILE FROM base RUN foo command DOCKERFILE ); }
public function testBuild() { $contextBuilder = new ContextBuilder(); $contextBuilder->from('ubuntu:precise'); $contextBuilder->add('/test', 'test file content'); $docker = $this->getDocker(); $docker->build($contextBuilder->getContext(), 'foo', function ($output) use(&$content) { $content .= $output; }); $this->assertRegExp('/Successfully built/', $content); }
public function testPushObject() { $contextBuilder = new ContextBuilder(); $contextBuilder->from('ubuntu:precise'); $contextBuilder->add('/test', 'test file content'); $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'localhost:5000/test-image'], ImageManager::FETCH_OBJECT); $registryConfig = new AuthConfig(); $registryConfig->setServeraddress('localhost:5000'); $pushImageInfos = $this->getManager()->push('localhost:5000/test-image', ['X-Registry-Auth' => $registryConfig], ImageManager::FETCH_OBJECT); $this->assertInternalType('array', $pushImageInfos); $this->assertContains("The push refers to a repository [localhost:5000/test-image]", $pushImageInfos[0]->getStatus()); }
public function testExec() { $manager = $this->getManager(); $dockerFileBuilder = new ContextBuilder(); $dockerFileBuilder->from('ubuntu:precise'); $dockerFileBuilder->add('/daemon.sh', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'script' . DIRECTORY_SEPARATOR . 'daemon.sh')); $dockerFileBuilder->run('chmod +x /daemon.sh'); $this->getDocker()->build($dockerFileBuilder->getContext(), 'docker-php-restart-test', null, true, false, true); $container = new Container(['Image' => 'docker-php-restart-test', 'Cmd' => ['/daemon.sh']]); $manager->create($container); $manager->start($container); $type = 0; $output = ""; $execId = $manager->exec($container, ['/bin/bash', '-c', 'echo -n "output"']); $this->assertNotNull($execId); $response = $manager->execstart($execId, function ($log, $stdtype) use(&$type, &$output) { $type = $stdtype; $output = $log; }); $response->getBody()->getContents(); $manager->kill($container); $this->assertEquals(1, $type); $this->assertEquals('output', $output); }
public function testWritesExposeCommands() { $contextBuilder = new ContextBuilder(); $contextBuilder->expose('80'); $context = $contextBuilder->getContext(); $this->assertStringEqualsFile($context->getDirectory() . '/Dockerfile', <<<DOCKERFILE FROM base EXPOSE 80 DOCKERFILE ); }
public function testExecInspect() { $manager = $this->getManager(); $dockerFileBuilder = new ContextBuilder(); $dockerFileBuilder->from('ubuntu:precise'); $dockerFileBuilder->add('/daemon.sh', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'script' . DIRECTORY_SEPARATOR . 'daemon.sh')); $dockerFileBuilder->run('chmod +x /daemon.sh'); $this->getDocker()->build($dockerFileBuilder->getContext(), 'docker-php-restart-test', null, true, false, true); $container = new Container(['Image' => 'docker-php-restart-test', 'Cmd' => ['/daemon.sh']]); $manager->create($container); $manager->start($container); $execId = $manager->exec($container, ['/bin/bash', '-c', 'echo -n "output"']); $inspection = $manager->execinspect($execId); $this->assertEquals(0, $inspection->ExitCode); $this->assertEquals(false, $inspection->Running); }
public function getDockerContextBuilder($identityRoot = '/root/.ssh') { $env = 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"' . PHP_EOL; $env .= 'SYMFONY_ENV=prod' . PHP_EOL; $env .= $this->getEnv(); $builder = new ContextBuilder(); $builder->setFormat(Context::FORMAT_TAR); $builder->add('/etc/environment', $env); $builder->add('/root/.ssh/config', $this->getSshConfig('/root/.ssh')); $this->dumpSshKeys($identityRoot, 'root', [$builder, 'add'], [$builder, 'run']); if ($this->getSettings() && strlen($this->getSettings()->getBuildYml()) > 0) { $builder->add('/root/stage1_local.yml', $this->getSettings()->getBuildYml()); } return $builder; }
public function testKill() { $manager = $this->getManager(); $dockerFileBuilder = new ContextBuilder(); $dockerFileBuilder->from('ubuntu:precise'); $dockerFileBuilder->add('/kill.sh', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'script' . DIRECTORY_SEPARATOR . 'kill.sh')); $dockerFileBuilder->run('chmod +x /kill.sh'); $this->getDocker()->build($dockerFileBuilder->getContext(), 'docker-php-kill-test', null, true, false, true); $container = new Container(['Image' => 'docker-php-kill-test', 'Cmd' => ['/kill.sh']]); $manager->create($container); $manager->start($container); $manager->kill($container, "SIGHUP"); $logs = $manager->logs($container, false, true); $logs = array_map(function ($value) { return $value['output']; }, $logs); $manager->stop($container); $manager->remove($container); $this->getDocker()->getImageManager()->delete($container->getImage()); $this->assertContains('HUP', implode("", $logs)); }