fix: boolean docker options
This commit is contained in:
parent
82b0667277
commit
364a6aa3a2
@ -340,17 +340,22 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null
|
|||||||
'--cap-drop' => 'cap_drop',
|
'--cap-drop' => 'cap_drop',
|
||||||
'--security-opt' => 'security_opt',
|
'--security-opt' => 'security_opt',
|
||||||
'--sysctl' => 'sysctls',
|
'--sysctl' => 'sysctls',
|
||||||
'--device' => 'devices',
|
|
||||||
'--ulimit' => 'ulimits',
|
'--ulimit' => 'ulimits',
|
||||||
|
'--device' => 'devices',
|
||||||
'--init' => 'init',
|
'--init' => 'init',
|
||||||
'--ulimit' => 'ulimits',
|
'--ulimit' => 'ulimits',
|
||||||
'--privileged' => 'privileged',
|
'--privileged' => 'privileged',
|
||||||
]);
|
]);
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
$option = $match[1];
|
$option = $match[1];
|
||||||
$value = isset($match[2]) && $match[2] !== '' ? $match[2] : true;
|
if (isset($match[2]) && $match[2] !== '') {
|
||||||
$options[$option][] = $value;
|
$value = $match[2];
|
||||||
$options[$option] = array_unique($options[$option]);
|
$options[$option][] = $value;
|
||||||
|
$options[$option] = array_unique($options[$option]);
|
||||||
|
} else {
|
||||||
|
$value = true;
|
||||||
|
$options[$option] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$options = collect($options);
|
$options = collect($options);
|
||||||
// Easily get mappings from https://github.com/composerize/composerize/blob/master/packages/composerize/src/mappings.js
|
// Easily get mappings from https://github.com/composerize/composerize/blob/master/packages/composerize/src/mappings.js
|
||||||
|
@ -1,9 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
it('ConvertDockerTunCommand', function () {
|
it('ConvertCapAdd', function () {
|
||||||
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN';
|
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN';
|
||||||
$output = convert_docker_run_to_compose($input);
|
$output = convert_docker_run_to_compose($input);
|
||||||
expect($output)->toBe([
|
expect($output)->toBe([
|
||||||
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
|
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
|
||||||
])->ray();
|
])->ray();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ConvertPrivilegedAndInit', function () {
|
||||||
|
$input = '---privileged --init';
|
||||||
|
$output = convert_docker_run_to_compose($input);
|
||||||
|
expect($output)->toBe([
|
||||||
|
'privileged' => true,
|
||||||
|
'init' => true,
|
||||||
|
])->ray();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ConvertUlimit', function () {
|
||||||
|
$input = '--ulimit nofile=262144:262144';
|
||||||
|
$output = convert_docker_run_to_compose($input);
|
||||||
|
expect($output)->toBe([
|
||||||
|
'ulimits' => [
|
||||||
|
'nofile' => [
|
||||||
|
'soft' => '262144',
|
||||||
|
'hard' => '262144',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])->ray();
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user