fix(docker): enhance hostname and GPU option validation in Docker run to compose conversion
This commit is contained in:
@@ -787,7 +787,7 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
|||||||
$regexForParsingHostname = '/--hostname(?:=|\s+)([^\s]+)/';
|
$regexForParsingHostname = '/--hostname(?:=|\s+)([^\s]+)/';
|
||||||
preg_match($regexForParsingHostname, $custom_docker_run_options, $hostname_matches);
|
preg_match($regexForParsingHostname, $custom_docker_run_options, $hostname_matches);
|
||||||
$value = $hostname_matches[1] ?? null;
|
$value = $hostname_matches[1] ?? null;
|
||||||
if ($value) {
|
if ($value && ! empty(trim($value))) {
|
||||||
$options[$option][] = $value;
|
$options[$option][] = $value;
|
||||||
$options[$option] = array_unique($options[$option]);
|
$options[$option] = array_unique($options[$option]);
|
||||||
}
|
}
|
||||||
@@ -829,7 +829,7 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
|||||||
});
|
});
|
||||||
$compose_options->put($mapping[$option], $ulimits);
|
$compose_options->put($mapping[$option], $ulimits);
|
||||||
} elseif ($option === '--shm-size' || $option === '--hostname') {
|
} elseif ($option === '--shm-size' || $option === '--hostname') {
|
||||||
if (! is_null($value) && is_array($value) && count($value) > 0) {
|
if (! is_null($value) && is_array($value) && count($value) > 0 && ! empty(trim($value[0]))) {
|
||||||
$compose_options->put($mapping[$option], $value[0]);
|
$compose_options->put($mapping[$option], $value[0]);
|
||||||
}
|
}
|
||||||
} elseif ($option === '--gpus') {
|
} elseif ($option === '--gpus') {
|
||||||
@@ -837,7 +837,7 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
|||||||
'driver' => 'nvidia',
|
'driver' => 'nvidia',
|
||||||
'capabilities' => ['gpu'],
|
'capabilities' => ['gpu'],
|
||||||
];
|
];
|
||||||
if (! is_null($value) && is_array($value) && count($value) > 0) {
|
if (! is_null($value) && is_array($value) && count($value) > 0 && ! empty(trim($value[0]))) {
|
||||||
if (str($value[0]) != 'all') {
|
if (str($value[0]) != 'all') {
|
||||||
if (str($value[0])->contains(',')) {
|
if (str($value[0])->contains(',')) {
|
||||||
$payload['device_ids'] = str($value[0])->explode(',')->toArray();
|
$payload['device_ids'] = str($value[0])->explode(',')->toArray();
|
||||||
|
Reference in New Issue
Block a user