Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions bootstrap/helpers/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
'--shm-size' => 'shm_size',
'--gpus' => 'gpus',
'--hostname' => 'hostname',
'--entrypoint' => 'entrypoint',
]);
foreach ($matches as $match) {
$option = $match[1];
Expand All @@ -962,6 +963,24 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
$options[$option] = array_unique($options[$option]);
}
}
if ($option === '--entrypoint') {
// Match --entrypoint=value or --entrypoint value
// Handle quoted strings: --entrypoint "sh -c 'command'" or --entrypoint='command'
// Try double quotes first, then single quotes, then unquoted
if (preg_match('/--entrypoint(?:=|\s+)"([^"]+)"/', $custom_docker_run_options, $entrypoint_matches)) {
$value = $entrypoint_matches[1];
} elseif (preg_match("/--entrypoint(?:=|\s+)'([^']+)'/", $custom_docker_run_options, $entrypoint_matches)) {
$value = $entrypoint_matches[1];
} elseif (preg_match('/--entrypoint(?:=|\s+)([^\s]+)/', $custom_docker_run_options, $entrypoint_matches)) {
$value = $entrypoint_matches[1];
} else {
$value = null;
}
if ($value && ! empty(trim($value))) {
$options[$option][] = $value;
$options[$option] = array_unique($options[$option]);
}
}
if (isset($match[2]) && $match[2] !== '') {
$value = $match[2];
$options[$option][] = $value;
Expand Down Expand Up @@ -1002,6 +1021,12 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
if (! is_null($value) && is_array($value) && count($value) > 0 && ! empty(trim($value[0]))) {
$compose_options->put($mapping[$option], $value[0]);
}
} elseif ($option === '--entrypoint') {
if (! is_null($value) && is_array($value) && count($value) > 0 && ! empty(trim($value[0]))) {
// Docker compose accepts entrypoint as either a string or an array
// Keep it as a string for simplicity - docker compose will handle it
$compose_options->put($mapping[$option], $value[0]);
}
} elseif ($option === '--gpus') {
$payload = [
'driver' => 'nvidia',
Expand Down
49 changes: 49 additions & 0 deletions tests/Feature/DockerCustomCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,52 @@
],
]);
});

test('ConvertEntrypointSimple', function () {
$input = '--entrypoint /bin/sh';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => '/bin/sh',
]);
});

test('ConvertEntrypointWithEquals', function () {
$input = '--entrypoint=/bin/bash';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => '/bin/bash',
]);
});

test('ConvertEntrypointWithArguments', function () {
$input = '--entrypoint "sh -c npm install"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'sh -c npm install',
]);
});

test('ConvertEntrypointWithSingleQuotes', function () {
$input = "--entrypoint 'memcached -m 256'";
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'memcached -m 256',
]);
});

test('ConvertEntrypointWithOtherOptions', function () {
$input = '--entrypoint /bin/bash --cap-add SYS_ADMIN --privileged';
$output = convertDockerRunToCompose($input);
expect($output)->toHaveKeys(['entrypoint', 'cap_add', 'privileged'])
->and($output['entrypoint'])->toBe('/bin/bash')
->and($output['cap_add'])->toBe(['SYS_ADMIN'])
->and($output['privileged'])->toBe(true);
});

test('ConvertEntrypointComplex', function () {
$input = '--entrypoint "sh -c \'npm install && npm start\'"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "sh -c 'npm install && npm start'",
]);
Comment on lines +145 to +175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add coverage for escaped double quotes

Please add a case where the entrypoint contains escaped quotes (e.g. --entrypoint "python -c \"print('hi')\"") so the parser can’t regress on real-world commands that embed quoted scripts.

 test('ConvertEntrypointComplex', function () {
     $input = '--entrypoint "sh -c \'npm install && npm start\'"';
     $output = convertDockerRunToCompose($input);
     expect($output)->toBe([
         'entrypoint' => "sh -c 'npm install && npm start'",
     ]);
 });
+
+test('ConvertEntrypointWithEscapedQuotes', function () {
+    $input = "--entrypoint \"python -c \\\"print('hello')\\\"\"";
+    $output = convertDockerRunToCompose($input);
+    expect($output)->toBe([
+        'entrypoint' => "python -c \"print('hello')\"",
+    ]);
+});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('ConvertEntrypointWithArguments', function () {
$input = '--entrypoint "sh -c npm install"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'sh -c npm install',
]);
});
test('ConvertEntrypointWithSingleQuotes', function () {
$input = "--entrypoint 'memcached -m 256'";
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'memcached -m 256',
]);
});
test('ConvertEntrypointWithOtherOptions', function () {
$input = '--entrypoint /bin/bash --cap-add SYS_ADMIN --privileged';
$output = convertDockerRunToCompose($input);
expect($output)->toHaveKeys(['entrypoint', 'cap_add', 'privileged'])
->and($output['entrypoint'])->toBe('/bin/bash')
->and($output['cap_add'])->toBe(['SYS_ADMIN'])
->and($output['privileged'])->toBe(true);
});
test('ConvertEntrypointComplex', function () {
$input = '--entrypoint "sh -c \'npm install && npm start\'"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "sh -c 'npm install && npm start'",
]);
test('ConvertEntrypointWithArguments', function () {
$input = '--entrypoint "sh -c npm install"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'sh -c npm install',
]);
});
test('ConvertEntrypointWithSingleQuotes', function () {
$input = "--entrypoint 'memcached -m 256'";
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => 'memcached -m 256',
]);
});
test('ConvertEntrypointWithOtherOptions', function () {
$input = '--entrypoint /bin/bash --cap-add SYS_ADMIN --privileged';
$output = convertDockerRunToCompose($input);
expect($output)->toHaveKeys(['entrypoint', 'cap_add', 'privileged'])
->and($output['entrypoint'])->toBe('/bin/bash')
->and($output['cap_add'])->toBe(['SYS_ADMIN'])
->and($output['privileged'])->toBe(true);
});
test('ConvertEntrypointComplex', function () {
$input = '--entrypoint "sh -c \'npm install && npm start\'"';
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "sh -c 'npm install && npm start'",
]);
});
test('ConvertEntrypointWithEscapedQuotes', function () {
$input = "--entrypoint \"python -c \\\"print('hello')\\\"\"";
$output = convertDockerRunToCompose($input);
expect($output)->toBe([
'entrypoint' => "python -c \"print('hello')\"",
]);
});
🤖 Prompt for AI Agents
In tests/Feature/DockerCustomCommandsTest.php around lines 145 to 175, add a new
test that covers entrypoints containing escaped double quotes so the parser
handles embedded quoted scripts; add a test input like --entrypoint "python -c
\"print('hi')\"" (and similar with single-quote wrapping), call
convertDockerRunToCompose($input) and assert the returned array contains
'entrypoint' => 'python -c "print(\'hi\')"' (i.e. the inner quotes preserved and
properly unescaped), ensuring the parser returns the correct single string
rather than truncated or mis-parsed tokens.

});