Commit ce375431 authored by Jürgen Haas's avatar Jürgen Haas

Improve determination of mount source inside docker container

parent 3bf9b012
......@@ -24,6 +24,7 @@
"source": "https://gitlab.lakedrops.com/composer/plugin/docker4drupal/tree/master"
},
"require": {
"ext-json": "*",
"php": ">=5.6",
"composer-plugin-api": "^1.0.0",
"lakedrops/composer-scripts": "^1.1.0",
......
......@@ -282,7 +282,7 @@ class Handler extends BaseHandler {
$projectRoot = getcwd();
}
else {
$projectRoot = $options['ci_home'] . $projectRoot;
$projectRoot = $this->getDockerMountSource($projectRoot);
}
$options['projectroot'] = $projectRoot;
......@@ -321,4 +321,29 @@ class Handler extends BaseHandler {
return isset($local_addrs[$interface]) ? $local_addrs[$interface] : '127.0.0.1';
}
/**
* @param $projectRoot
*
* @return string
*/
private function getDockerMountSource($projectRoot) {
try {
$output = [];
exec('basename "$(cat /proc/1/cpuset)"', $output);
$id = reset($output);
$output = [];
exec('docker container inspect ' . $id, $output);
$container = json_decode(implode('', $output), TRUE)[0];
foreach ($container['Mounts'] as $mount) {
if (strpos($projectRoot, $mount['Destination']) === 0) {
return $mount['Source'] . substr($projectRoot, strlen($mount['Destination']));
}
}
}
catch (\Exception $ex) {
// Ignore.
}
return getcwd();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment