An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: add --gpu support for custom docker command
Andras Bacsaiff6f08948338
diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.phpindex 1e8616416e..13667e8297 100644--- a/app/Actions/Database/StartClickhouse.php+++ b/app/Actions/Database/StartClickhouse.php@@ -99,8 +99,8 @@ class StartClickhouse}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.phpindex 6274737a1c..c72714e1cd 100644--- a/app/Actions/Database/StartDragonfly.php+++ b/app/Actions/Database/StartDragonfly.php@@ -96,8 +96,8 @@ class StartDragonfly}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.phpindex 734b28322f..bd98258ab6 100644--- a/app/Actions/Database/StartKeydb.php+++ b/app/Actions/Database/StartKeydb.php@@ -107,8 +107,8 @@ class StartKeydb}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);$this->commands[] = "echo '{$docker_compose_base64}' | base64 -d | tee $this->configuration_dir/docker-compose.yml > /dev/null";diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.phpindex aa6b79126d..696dd7ff4b 100644--- a/app/Actions/Database/StartMariadb.php+++ b/app/Actions/Database/StartMariadb.php@@ -101,8 +101,8 @@ class StartMariadb}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.phpindex 8d0a6b3caa..6d67bdde61 100644--- a/app/Actions/Database/StartMongodb.php+++ b/app/Actions/Database/StartMongodb.php@@ -117,8 +117,8 @@ class StartMongodb];// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.phpindex 0339501b01..a3694648f9 100644--- a/app/Actions/Database/StartMysql.php+++ b/app/Actions/Database/StartMysql.php@@ -101,8 +101,8 @@ class StartMysql}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.phpindex 5c956acbcd..f5e85087ff 100644--- a/app/Actions/Database/StartPostgresql.php+++ b/app/Actions/Database/StartPostgresql.php@@ -122,8 +122,8 @@ class StartPostgresql];}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.phpindex e445a246e9..7a2d2b34d5 100644--- a/app/Actions/Database/StartRedis.php+++ b/app/Actions/Database/StartRedis.php@@ -110,8 +110,8 @@ class StartRedis}// Add custom docker run options- $docker_run_options = convert_docker_run_to_compose($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_run_options = convertDockerRunToCompose($this->database->custom_docker_run_options);+ $docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);$docker_compose = Yaml::dump($docker_compose, 10);$docker_compose_base64 = base64_encode($docker_compose);diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex a0fdd0e971..5ceed332a9 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -1836,7 +1836,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue}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 (! $this->application->settings->custom_internal_name) {$docker_compose['services'][$this->application->uuid] = $docker_compose['services'][$this->container_name];diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.phpindex 52435703cf..4781525657 100644--- a/bootstrap/helpers/docker.php+++ b/bootstrap/helpers/docker.php@@ -654,7 +654,7 @@ function isDatabaseImage(?string $image = null)return false;}-function convert_docker_run_to_compose(?string $custom_docker_run_options = null)+function convertDockerRunToCompose(?string $custom_docker_run_options = null){$options = [];$compose_options = collect([]);@@ -667,6 +667,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null'--ulimit','--device','--shm-size',+ '--gpus',]);$mapping = collect(['--cap-add' => 'cap_add',@@ -679,6 +680,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null'--privileged' => 'privileged','--ip' => 'ip','--shm-size' => 'shm_size',+ '--gpus' => 'gpus',]);foreach ($matches as $match) {$option = $match[1];@@ -744,7 +746,7 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = nullreturn $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');$ipv6 = data_get($docker_run_options, 'ip6.0');diff --git a/tests/Feature/DockerCustomCommandsTest.php b/tests/Feature/DockerCustomCommandsTest.phpindex a0baeb2159..12f0f91a6c 100644--- a/tests/Feature/DockerCustomCommandsTest.php+++ b/tests/Feature/DockerCustomCommandsTest.php@@ -2,7 +2,7 @@test('ConvertCapAdd', function () {$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(['cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],]);@@ -10,7 +10,7 @@ test('ConvertCapAdd', 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';- $output = convert_docker_run_to_compose($input);+ $output = convertDockerRunToCompose($input);expect($output)->toBe(['cap_add' => ['NET_ADMIN', 'NET_RAW', 'SYS_ADMIN'],'ip' => ['127.0.0.1', '127.0.0.2'],@@ -19,7 +19,7 @@ test('ConvertIp', function () {test('ConvertPrivilegedAndInit', function () {$input = '---privileged --init';- $output = convert_docker_run_to_compose($input);+ $output = convertDockerRunToCompose($input);expect($output)->toBe(['privileged' => true,'init' => true,@@ -28,7 +28,7 @@ test('ConvertPrivilegedAndInit', function () {test('ConvertUlimit', function () {$input = '--ulimit nofile=262144:262144';- $output = convert_docker_run_to_compose($input);+ $output = convertDockerRunToCompose($input);expect($output)->toBe(['ulimits' => ['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"',+ ]);+});