Skip to content

Commit

Permalink
Merge pull request #16 from iamluc/feature/docker-machine
Browse files Browse the repository at this point in the history
Add compatibility with Docker environment variables
  • Loading branch information
iamluc committed Jan 7, 2016
2 parents 832ed19 + 43995c9 commit a819c11
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/Command/SynchronizeHostsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ protected function configure()
$this
->setName('synchronize-hosts')
->setDescription('Run the application')
->addOption(
'entrypoint',
'p',
InputOption::VALUE_REQUIRED,
'The docker entrypoint',
getenv('DOCKER_ENTRYPOINT') ?: 'unix:///var/run/docker.sock'
)
->addOption(
'hosts_file',
'f',
Expand All @@ -43,14 +36,43 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$client = new DockerClient([], $input->getOption('entrypoint'));

$app = new Synchronizer(
new Docker($client),
new Docker($this->createDockerClient()),
$input->getOption('hosts_file'),
$input->getOption('tld')
);

$app->run();
}

/**
* Copy of https://github.com/hxpro/docker-php/blob/master/src/Docker/Http/DockerClient.php
* + disable peer_name check.
*
* @return DockerClient
*/
private function createDockerClient()
{
$entrypoint = getenv('DOCKER_HOST') ? getenv('DOCKER_HOST') : 'unix:///var/run/docker.sock';
$context = null;
$useTls = false;
if (getenv('DOCKER_TLS_VERIFY') && getenv('DOCKER_TLS_VERIFY') == 1) {
if (!getenv('DOCKER_CERT_PATH')) {
throw new \RuntimeException('Connection to docker has been set to use TLS, but no PATH is defined for certificate in DOCKER_CERT_PATH docker environment variable');
}
$useTls = true;
$cafile = getenv('DOCKER_CERT_PATH').DIRECTORY_SEPARATOR.'ca.pem';
$certfile = getenv('DOCKER_CERT_PATH').DIRECTORY_SEPARATOR.'cert.pem';
$keyfile = getenv('DOCKER_CERT_PATH').DIRECTORY_SEPARATOR.'key.pem';
$context = stream_context_create([
'ssl' => [
'cafile' => $cafile,
'local_cert' => $certfile,
'local_pk' => $keyfile,
],
]);
}

return new DockerClient([], $entrypoint, $context, $useTls);
}
}

0 comments on commit a819c11

Please sign in to comment.