diff --git a/bin/volume.php b/bin/volume.php index 31300a1b7b657ce37ac1eab5f3c83a0574769f54..414f2803a3e77b595f106238da1fd199ef350b77 100644 --- a/bin/volume.php +++ b/bin/volume.php @@ -3,15 +3,27 @@ function readContainerConfig() { try { + $testString = 'This is a test file for LakeDrops GitLab CI'; + $filename = '/tmp/' . random_int(100,999) . '.test'; + file_put_contents($filename, $testString); $output = []; - exec('basename "$(cat /proc/1/cpuset)"', $output); - $id = reset($output); - if ($id === '/') { - $id = getenv('COMPOSE_PROJECT_NAME') . '_l3d'; + exec('docker ps -q', $output); + $id = NULL; + foreach ($output as $id) { + $output = []; + exec('docker exec ' . $id . ' cat ' . $filename . ' 2>&1', $output); + if (reset($output) === $testString) { + // Found the container. + break; + } + } + unlink($filename); + if ($id === NULL) { + return []; } $output = []; exec('docker container inspect ' . $id, $output); - return json_decode(implode('', $output), TRUE)[0]; + return json_decode(implode('', $output), TRUE, 512, JSON_THROW_ON_ERROR)[0]; } catch (\Exception $ex) { // Ignore.