feat: add --gpu support for custom docker command
This commit is contained in:
@@ -99,8 +99,8 @@ class StartClickhouse
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -96,8 +96,8 @@ class StartDragonfly
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -107,8 +107,8 @@ class StartKeydb
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
$this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null";
|
$this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null";
|
||||||
|
@@ -101,8 +101,8 @@ class StartMariadb
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -117,8 +117,8 @@ class StartMongodb
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -101,8 +101,8 @@ class StartMysql
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -122,8 +122,8 @@ class StartPostgresql
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -110,8 +110,8 @@ class StartRedis
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom docker run options
|
// Add custom docker run options
|
||||||
$docker_run_options = convert_docker_run_to_compose($this->database->custom_docker_run_options);
|
$docker_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);
|
||||||
$docker_compose = generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
|
||||||
|
|
||||||
$docker_compose = Yaml::dump($docker_compose, 10);
|
$docker_compose = Yaml::dump($docker_compose, 10);
|
||||||
$docker_compose_base64 = base64_encode($docker_compose);
|
$docker_compose_base64 = base64_encode($docker_compose);
|
||||||
|
@@ -1836,7 +1836,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->pull_request_id === 0) {
|
if ($this->pull_request_id === 0) {
|
||||||
$custom_compose = convert_docker_run_to_compose($this->application->custom_docker_run_options);
|
$custom_compose = convertDockerRunToCompose($this->application->custom_docker_run_options);
|
||||||
if ((bool) $this->application->settings->is_consistent_container_name_enabled) {
|
if ((bool) $this->application->settings->is_consistent_container_name_enabled) {
|
||||||
if (! $this->application->settings->custom_internal_name) {
|
if (! $this->application->settings->custom_internal_name) {
|
||||||
$docker_compose['services'][$this->application->uuid] = $docker_compose['services'][$this->container_name];
|
$docker_compose['services'][$this->application->uuid] = $docker_compose['services'][$this->container_name];
|
||||||
|
@@ -654,7 +654,7 @@ function isDatabaseImage(?string $image = null)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert_docker_run_to_compose(?string $custom_docker_run_options = null)
|
function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
||||||
{
|
{
|
||||||
$options = [];
|
$options = [];
|
||||||
$compose_options = collect([]);
|
$compose_options = collect([]);
|
||||||
@@ -667,6 +667,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null
|
|||||||
'--ulimit',
|
'--ulimit',
|
||||||
'--device',
|
'--device',
|
||||||
'--shm-size',
|
'--shm-size',
|
||||||
|
'--gpus',
|
||||||
]);
|
]);
|
||||||
$mapping = collect([
|
$mapping = collect([
|
||||||
'--cap-add' => 'cap_add',
|
'--cap-add' => 'cap_add',
|
||||||
@@ -679,6 +680,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null
|
|||||||
'--privileged' => 'privileged',
|
'--privileged' => 'privileged',
|
||||||
'--ip' => 'ip',
|
'--ip' => 'ip',
|
||||||
'--shm-size' => 'shm_size',
|
'--shm-size' => 'shm_size',
|
||||||
|
'--gpus' => 'gpus',
|
||||||
]);
|
]);
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
$option = $match[1];
|
$option = $match[1];
|
||||||
@@ -744,7 +746,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null
|
|||||||
return $compose_options->toArray();
|
return $compose_options->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_custom_docker_run_options_for_databases($docker_run_options, $docker_compose, $container_name, $network)
|
function generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $network)
|
||||||
{
|
{
|
||||||
$ipv4 = data_get($docker_run_options, 'ip.0');
|
$ipv4 = data_get($docker_run_options, 'ip.0');
|
||||||
$ipv6 = data_get($docker_run_options, 'ip6.0');
|
$ipv6 = data_get($docker_run_options, 'ip6.0');
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
test('ConvertCapAdd', function () {
|
test('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 = convertDockerRunToCompose($input);
|
||||||
expect($output)->toBe([
|
expect($output)->toBe([
|
||||||
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
|
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
|
||||||
]);
|
]);
|
||||||
@@ -10,7 +10,7 @@ test('ConvertCapAdd', function () {
|
|||||||
|
|
||||||
test('ConvertIp', function () {
|
test('ConvertIp', function () {
|
||||||
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN --ip 127.0.0.1 --ip 127.0.0.2';
|
$input = '--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add SYS_ADMIN --ip 127.0.0.1 --ip 127.0.0.2';
|
||||||
$output = convert_docker_run_to_compose($input);
|
$output = convertDockerRunToCompose($input);
|
||||||
expect($output)->toBe([
|
expect($output)->toBe([
|
||||||
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
|
'cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],
|
||||||
'ip' => ['127.0.0.1', '127.0.0.2'],
|
'ip' => ['127.0.0.1', '127.0.0.2'],
|
||||||
@@ -19,7 +19,7 @@ test('ConvertIp', function () {
|
|||||||
|
|
||||||
test('ConvertPrivilegedAndInit', function () {
|
test('ConvertPrivilegedAndInit', function () {
|
||||||
$input = '---privileged --init';
|
$input = '---privileged --init';
|
||||||
$output = convert_docker_run_to_compose($input);
|
$output = convertDockerRunToCompose($input);
|
||||||
expect($output)->toBe([
|
expect($output)->toBe([
|
||||||
'privileged' => true,
|
'privileged' => true,
|
||||||
'init' => true,
|
'init' => true,
|
||||||
@@ -28,7 +28,7 @@ test('ConvertPrivilegedAndInit', function () {
|
|||||||
|
|
||||||
test('ConvertUlimit', function () {
|
test('ConvertUlimit', function () {
|
||||||
$input = '--ulimit nofile=262144:262144';
|
$input = '--ulimit nofile=262144:262144';
|
||||||
$output = convert_docker_run_to_compose($input);
|
$output = convertDockerRunToCompose($input);
|
||||||
expect($output)->toBe([
|
expect($output)->toBe([
|
||||||
'ulimits' => [
|
'ulimits' => [
|
||||||
'nofile' => [
|
'nofile' => [
|
||||||
@@ -38,3 +38,19 @@ test('ConvertUlimit', function () {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('ConvertGpus', function () {
|
||||||
|
$input = '--gpus all';
|
||||||
|
$output = convertDockerRunToCompose($input);
|
||||||
|
expect($output)->toBe([
|
||||||
|
'gpus' => 'all',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ConvertGpusWithQuotes', function () {
|
||||||
|
$input = '--gpus "device=0"';
|
||||||
|
$output = convertDockerRunToCompose($input);
|
||||||
|
expect($output)->toBe([
|
||||||
|
'gpus' => '"device=0"',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user