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 docker engine support install script to rhel based systems
Andras Bacsaie78b6758d833
diff --git a/app/Actions/Server/InstallDocker.php b/app/Actions/Server/InstallDocker.phpindex e99e8a11b3..a39799d888 100644--- a/app/Actions/Server/InstallDocker.php+++ b/app/Actions/Server/InstallDocker.php@@ -9,8 +9,9 @@ use App\Models\StandaloneDocker;class InstallDocker{use AsAction;- public function handle(Server $server)+ public function handle(Server $server, $supported_os_type){+ ray('Installing Docker on server: ' . $server->name . ' (' . $server->ip . ')' . ' with OS: ' . $supported_os_type);$dockerVersion = '24.0';$config = base64_encode('{"log-driver": "json-file",@@ -27,36 +28,48 @@ class InstallDocker'server_id' => $server->id,]);}-+ $command = collect([]);if (isDev() && $server->id === 0) {- $command = [- "echo '####### Installing Prerequisites...'",+ $command = $command->merge([+ "echo 'Installing Prerequisites...'","sleep 1",- "echo '####### Installing/updating Docker Engine...'",- "echo '####### Configuring Docker Engine (merging existing configuration with the required)...'",+ "echo 'Installing Docker Engine...'",+ "echo 'Configuring Docker Engine (merging existing configuration with the required)...'","sleep 4",- "echo '####### Restarting Docker Engine...'",+ "echo 'Restarting Docker Engine...'","ls -l /tmp"- ];+ ]);} else {- $command = [- "echo '####### Installing Prerequisites...'",- "command -v jq >/dev/null || apt-get update",- "command -v jq >/dev/null || apt install -y jq",- "echo '####### Installing/updating Docker Engine...'",+ if ($supported_os_type === 'debian') {+ $command = $command->merge([+ "echo 'Installing Prerequisites...'",+ "command -v jq >/dev/null || apt-get update",+ "command -v jq >/dev/null || apt install -y jq",++ ]);+ } else if ($supported_os_type === 'rhel') {+ $command = $command->merge([+ "echo 'Installing Prerequisites...'",+ "command -v jq >/dev/null || dnf install -y jq",+ ]);+ } else {+ throw new \Exception('Unsupported OS');+ }+ $command = $command->merge([+ "echo 'Installing Docker Engine...'","curl https://releases.rancher.com/install-docker/{$dockerVersion}.sh | sh",- "echo '####### Configuring Docker Engine (merging existing configuration with the required)...'",+ "echo 'Configuring Docker Engine (merging existing configuration with the required)...'","test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json \"/etc/docker/daemon.json.original-`date +\"%Y%m%d-%H%M%S\"`\" || echo '{$config}' | base64 -d > /etc/docker/daemon.json","echo '{$config}' | base64 -d > /etc/docker/daemon.json.coolify","cat <<< $(jq . /etc/docker/daemon.json.coolify) > /etc/docker/daemon.json.coolify","cat <<< $(jq -s '.[0] * .[1]' /etc/docker/daemon.json /etc/docker/daemon.json.coolify) > /etc/docker/daemon.json",- "echo '####### Restarting Docker Engine...'",+ "echo 'Restarting Docker Engine...'","systemctl restart docker",- "echo '####### Creating default Docker network (coolify)...'",+ "echo 'Creating default Docker network (coolify)...'","docker network create --attachable coolify >/dev/null 2>&1 || true",- "echo '####### Done!'"- ];+ "echo 'Done!'"+ ]);+ return remote_process($command, $server);}- return remote_process($command, $server);}}diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.phpindex 4caa15b3f6..ecf7c80cf9 100644--- a/app/Http/Livewire/Server/Form.php+++ b/app/Http/Livewire/Server/Form.php@@ -43,9 +43,9 @@ class Form extends Component$this->wildcard_domain = $this->server->settings->wildcard_domain;$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;}- public function serverRefresh()+ public function serverRefresh($install = true){- $this->validateServer();+ $this->validateServer($install);}public function instantSave(){@@ -53,11 +53,11 @@ class Form extends Component$this->validateServer();$this->server->settings->save();}- public function installDocker()+ public function installDocker($supported_os_type){$this->emit('installDocker');$this->dockerInstallationStarted = true;- $activity = InstallDocker::run($this->server);+ $activity = InstallDocker::run($this->server, $supported_os_type);$this->emit('newMonitorActivity', $activity->id);}public function checkLocalhostConnection()@@ -77,24 +77,27 @@ class Form extends Component{try {$uptime = $this->server->validateConnection();- if ($uptime) {- $install && $this->emit('success', 'Server is reachable.');- } else {+ if (!$uptime) {$install && $this->emit('error', 'Server is not reachable. Please check your connection and configuration.');return;}+ $supported_os_type = $this->server->validateOS();+ if (!$supported_os_type) {+ $install && $this->emit('error', 'Server OS is not supported.<br>Please use a supported OS.');+ return;+ }$dockerInstalled = $this->server->validateDockerEngine();if ($dockerInstalled) {$install && $this->emit('success', 'Docker Engine is installed.<br> Checking version.');} else {- $install && $this->installDocker();+ $install && $this->installDocker($supported_os_type);return;}$dockerVersion = $this->server->validateDockerEngineVersion();if ($dockerVersion) {$install && $this->emit('success', 'Docker Engine version is 23+.');} else {- $install && $this->installDocker();+ $install && $this->installDocker($supported_os_type);return;}} catch (\Throwable $e) {diff --git a/app/Http/Livewire/Server/Show.php b/app/Http/Livewire/Server/Show.phpindex 77ae447d7c..3863381b29 100644--- a/app/Http/Livewire/Server/Show.php+++ b/app/Http/Livewire/Server/Show.php@@ -25,7 +25,7 @@ class Show extends Component}public function submit(){- $this->emit('serverRefresh');+ $this->emit('serverRefresh',false);}public function render(){diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 02c3186c6f..7b34278e72 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -304,6 +304,27 @@ class Server extends BaseModel{return $this->settings->is_logdrain_newrelic_enabled || $this->settings->is_logdrain_highlight_enabled || $this->settings->is_logdrain_axiom_enabled;}+ public function validateOS()+ {+ $os_release = instant_remote_process(['cat /etc/os-release'], $this);+ $datas = collect(explode("\n", $os_release));+ $collectedData = collect([]);+ foreach ($datas as $data) {+ $item = Str::of($data)->trim();+ $collectedData->put($item->before('=')->value(), $item->after('=')->lower()->replace('"', '')->value());+ }+ $ID = data_get($collectedData, 'ID');+ $ID_LIKE = data_get($collectedData, 'ID_LIKE');+ $VERSION_ID = data_get($collectedData, 'VERSION_ID');+ // ray($ID, $ID_LIKE, $VERSION_ID);+ if (collect(SUPPORTED_OS)->contains($ID_LIKE)) {+ ray('supported');+ return str($ID_LIKE)->explode(' ')->first();+ } else {+ ray('not supported');+ return false;+ }+ }public function validateConnection(){if ($this->skipServer()) {@@ -311,30 +332,27 @@ class Server extends BaseModel}$uptime = instant_remote_process(['uptime'], $this, false);+ ray($uptime);if (!$uptime) {$this->settings()->update(['is_reachable' => false,- 'is_usable' => false]);return false;+ } else {+ $this->settings()->update([+ 'is_reachable' => true,+ ]);+ $this->update([+ 'unreachable_count' => 0,+ ]);+ ray($this);}if (data_get($this, 'unreachable_notification_sent') === true) {$this->team->notify(new Revived($this));$this->update(['unreachable_notification_sent' => false]);}- if (- data_get($this, 'settings.is_reachable') === false ||- data_get($this, 'settings.is_usable') === false- ) {- $this->settings()->update([- 'is_reachable' => true,- 'is_usable' => true- ]);- }- $this->update([- 'unreachable_count' => 0,- ]);+return true;}public function validateDockerEngine($throwError = false)@@ -344,7 +362,7 @@ class Server extends BaseModel$this->settings->is_usable = false;$this->settings->save();if ($throwError) {- throw new \Exception('Server is not usable.');+ throw new \Exception('Server is not usable. Docker Engine is not installed.');}return false;}@@ -362,6 +380,7 @@ class Server extends BaseModel$this->settings->save();return false;}+ $this->settings->is_reachable = true;$this->settings->is_usable = true;$this->settings->save();return true;diff --git a/bootstrap/helpers/constants.php b/bootstrap/helpers/constants.phpindex d26932165d..299d3acb91 100644--- a/bootstrap/helpers/constants.php+++ b/bootstrap/helpers/constants.php@@ -27,3 +27,8 @@ const DATABASE_DOCKER_IMAGES = [const SPECIFIC_SERVICES = ['quay.io/minio/minio',];++const SUPPORTED_OS = [+ 'debian',+ 'rhel centos fedora'+];