feat: add docker engine support install script to rhel based systems
This commit is contained in:
parent
16eb7f4fb4
commit
e78b6758d8
@ -9,8 +9,9 @@
|
||||
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 @@ public function handle(Server $server)
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ public function mount()
|
||||
$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 @@ public function instantSave()
|
||||
$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 @@ public function validateServer($install = true)
|
||||
{
|
||||
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) {
|
||||
|
@ -25,7 +25,7 @@ public function mount()
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
$this->emit('serverRefresh');
|
||||
$this->emit('serverRefresh',false);
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
|
@ -304,6 +304,27 @@ public function isLogDrainEnabled()
|
||||
{
|
||||
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 @@ public function validateConnection()
|
||||
}
|
||||
|
||||
$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 @@ public function validateDockerEngine($throwError = false)
|
||||
$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 @@ public function validateDockerEngineVersion()
|
||||
$this->settings->save();
|
||||
return false;
|
||||
}
|
||||
$this->settings->is_reachable = true;
|
||||
$this->settings->is_usable = true;
|
||||
$this->settings->save();
|
||||
return true;
|
||||
|
@ -27,3 +27,8 @@
|
||||
const SPECIFIC_SERVICES = [
|
||||
'quay.io/minio/minio',
|
||||
];
|
||||
|
||||
const SUPPORTED_OS = [
|
||||
'debian',
|
||||
'rhel centos fedora'
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user