feat: add docker engine support install script to rhel based systems

This commit is contained in:
Andras Bacsai 2023-11-21 11:39:19 +01:00
parent 16eb7f4fb4
commit e78b6758d8
5 changed files with 83 additions and 43 deletions
app
Actions/Server
Http/Livewire/Server
Models
bootstrap/helpers

@ -9,8 +9,9 @@ use App\Models\StandaloneDocker;
class InstallDocker class InstallDocker
{ {
use AsAction; 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'; $dockerVersion = '24.0';
$config = base64_encode('{ $config = base64_encode('{
"log-driver": "json-file", "log-driver": "json-file",
@ -27,36 +28,48 @@ class InstallDocker
'server_id' => $server->id, 'server_id' => $server->id,
]); ]);
} }
$command = collect([]);
if (isDev() && $server->id === 0) { if (isDev() && $server->id === 0) {
$command = [ $command = $command->merge([
"echo '####### Installing Prerequisites...'", "echo 'Installing Prerequisites...'",
"sleep 1", "sleep 1",
"echo '####### Installing/updating Docker Engine...'", "echo 'Installing Docker Engine...'",
"echo '####### Configuring Docker Engine (merging existing configuration with the required)...'", "echo 'Configuring Docker Engine (merging existing configuration with the required)...'",
"sleep 4", "sleep 4",
"echo '####### Restarting Docker Engine...'", "echo 'Restarting Docker Engine...'",
"ls -l /tmp" "ls -l /tmp"
]; ]);
} else { } else {
$command = [ if ($supported_os_type === 'debian') {
"echo '####### Installing Prerequisites...'", $command = $command->merge([
"command -v jq >/dev/null || apt-get update", "echo 'Installing Prerequisites...'",
"command -v jq >/dev/null || apt install -y jq", "command -v jq >/dev/null || apt-get update",
"echo '####### Installing/updating Docker Engine...'", "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", "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", "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", "echo '{$config}' | base64 -d > /etc/docker/daemon.json.coolify",
"cat <<< $(jq . /etc/docker/daemon.json.coolify) > /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", "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", "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", "docker network create --attachable coolify >/dev/null 2>&1 || true",
"echo '####### Done!'" "echo 'Done!'"
]; ]);
return remote_process($command, $server);
} }
return remote_process($command, $server);
} }
} }

@ -43,9 +43,9 @@ class Form extends Component
$this->wildcard_domain = $this->server->settings->wildcard_domain; $this->wildcard_domain = $this->server->settings->wildcard_domain;
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage; $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() public function instantSave()
{ {
@ -53,11 +53,11 @@ class Form extends Component
$this->validateServer(); $this->validateServer();
$this->server->settings->save(); $this->server->settings->save();
} }
public function installDocker() public function installDocker($supported_os_type)
{ {
$this->emit('installDocker'); $this->emit('installDocker');
$this->dockerInstallationStarted = true; $this->dockerInstallationStarted = true;
$activity = InstallDocker::run($this->server); $activity = InstallDocker::run($this->server, $supported_os_type);
$this->emit('newMonitorActivity', $activity->id); $this->emit('newMonitorActivity', $activity->id);
} }
public function checkLocalhostConnection() public function checkLocalhostConnection()
@ -77,24 +77,27 @@ class Form extends Component
{ {
try { try {
$uptime = $this->server->validateConnection(); $uptime = $this->server->validateConnection();
if ($uptime) { if (!$uptime) {
$install && $this->emit('success', 'Server is reachable.');
} else {
$install && $this->emit('error', 'Server is not reachable. Please check your connection and configuration.'); $install && $this->emit('error', 'Server is not reachable. Please check your connection and configuration.');
return; 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(); $dockerInstalled = $this->server->validateDockerEngine();
if ($dockerInstalled) { if ($dockerInstalled) {
$install && $this->emit('success', 'Docker Engine is installed.<br> Checking version.'); $install && $this->emit('success', 'Docker Engine is installed.<br> Checking version.');
} else { } else {
$install && $this->installDocker(); $install && $this->installDocker($supported_os_type);
return; return;
} }
$dockerVersion = $this->server->validateDockerEngineVersion(); $dockerVersion = $this->server->validateDockerEngineVersion();
if ($dockerVersion) { if ($dockerVersion) {
$install && $this->emit('success', 'Docker Engine version is 23+.'); $install && $this->emit('success', 'Docker Engine version is 23+.');
} else { } else {
$install && $this->installDocker(); $install && $this->installDocker($supported_os_type);
return; return;
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {

@ -25,7 +25,7 @@ class Show extends Component
} }
public function submit() public function submit()
{ {
$this->emit('serverRefresh'); $this->emit('serverRefresh',false);
} }
public function render() public function render()
{ {

@ -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; 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() public function validateConnection()
{ {
if ($this->skipServer()) { if ($this->skipServer()) {
@ -311,30 +332,27 @@ class Server extends BaseModel
} }
$uptime = instant_remote_process(['uptime'], $this, false); $uptime = instant_remote_process(['uptime'], $this, false);
ray($uptime);
if (!$uptime) { if (!$uptime) {
$this->settings()->update([ $this->settings()->update([
'is_reachable' => false, 'is_reachable' => false,
'is_usable' => false
]); ]);
return 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) { if (data_get($this, 'unreachable_notification_sent') === true) {
$this->team->notify(new Revived($this)); $this->team->notify(new Revived($this));
$this->update(['unreachable_notification_sent' => false]); $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; return true;
} }
public function validateDockerEngine($throwError = false) public function validateDockerEngine($throwError = false)
@ -344,7 +362,7 @@ class Server extends BaseModel
$this->settings->is_usable = false; $this->settings->is_usable = false;
$this->settings->save(); $this->settings->save();
if ($throwError) { if ($throwError) {
throw new \Exception('Server is not usable.'); throw new \Exception('Server is not usable. Docker Engine is not installed.');
} }
return false; return false;
} }
@ -362,6 +380,7 @@ class Server extends BaseModel
$this->settings->save(); $this->settings->save();
return false; return false;
} }
$this->settings->is_reachable = true;
$this->settings->is_usable = true; $this->settings->is_usable = true;
$this->settings->save(); $this->settings->save();
return true; return true;

@ -27,3 +27,8 @@ const DATABASE_DOCKER_IMAGES = [
const SPECIFIC_SERVICES = [ const SPECIFIC_SERVICES = [
'quay.io/minio/minio', 'quay.io/minio/minio',
]; ];
const SUPPORTED_OS = [
'debian',
'rhel centos fedora'
];