Skip to content
Snippets Groups Projects
Commit ff509e4a authored by jurgenhaas's avatar jurgenhaas
Browse files

docker/gitlab-drupal-ci#17 Save solution to find the correct self container

parent 4310e404
No related branches found
No related tags found
1 merge request!58Merging develop into main
Pipeline #744439 passed
This commit is part of merge request !58. Comments created here will be created in the context of that merge request.
......@@ -793,15 +793,26 @@ class Handler extends BaseHandler {
*/
private function readContainerConfig(): array {
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) {
$output = [];
exec('docker container inspect ' . $id, $output);
return json_decode(implode('', $output), TRUE, 512, JSON_THROW_ON_ERROR)[0];
}
$output = [];
exec('docker container inspect ' . $id, $output);
return json_decode(implode('', $output), TRUE)[0];
}
catch (\Exception $ex) {
// Ignore.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment