From 87cde8bf1ed36b62aee39b6acb1e08c81403bd70 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:45:12 +0100 Subject: [PATCH] remove unused code --- .../Server/InstallCoolifyDependencies.php | 155 ++++++++---------- 1 file changed, 70 insertions(+), 85 deletions(-) diff --git a/app/Actions/Server/InstallCoolifyDependencies.php b/app/Actions/Server/InstallCoolifyDependencies.php index fd322b0da..3b2461ec2 100644 --- a/app/Actions/Server/InstallCoolifyDependencies.php +++ b/app/Actions/Server/InstallCoolifyDependencies.php @@ -12,11 +12,7 @@ class InstallCoolifyDependencies public function handle(Server $server) { - $dockerVersion = config('constants.docker.minimum_required_version'); - $supported_os_type = $server->validateOS(); - if (!$supported_os_type) { - throw new \Exception('Server OS type is not supported for automated installation. Please install Docker manually before continuing: documentation.'); - } + $dockerVersion = config('constants.docker.version'); $config = base64_encode('{ "log-driver": "json-file", @@ -39,93 +35,82 @@ class InstallCoolifyDependencies } $command = collect([]); - if (isDev() && $server->id === 0) { + + if ($supported_os_type->contains('debian')) { $command = $command->merge([ "echo 'Installing Prerequisites...'", - 'sleep 1', - "echo 'Installing Docker Engine...'", - "echo 'Configuring Docker Engine...'", - 'sleep 4', - "echo 'Restarting Docker Engine...'", - 'ls -l /tmp', + 'apt-get update -y', + 'command -v curl >/dev/null || apt install -y curl', + 'command -v wget >/dev/null || apt install -y wget', + 'command -v git >/dev/null || apt install -y git', + 'command -v jq >/dev/null || apt install -y jq', + 'command -v qemu-user-static >/dev/null || apt install -y qemu-user-static binfmt-support', + ]); + } elseif ($supported_os_type->contains('rhel')) { + $command = $command->merge([ + "echo 'Installing Prerequisites...'", + 'command -v curl >/dev/null || dnf install -y curl', + 'command -v wget >/dev/null || dnf install -y wget', + 'command -v git >/dev/null || dnf install -y git', + 'command -v jq >/dev/null || dnf install -y jq', + 'command -v qemu-user-static >/dev/null || dnf install -y qemu-user-static', + ]); + } elseif ($supported_os_type->contains('arch')) { + $command = $command->merge([ + "echo 'Installing Prerequisites...'", + 'pacman -Sy --noconfirm --needed curl wget git jq qemu-user-static', + ]); + } elseif ($supported_os_type->contains('alpine')) { + $command = $command->merge([ + "echo 'Installing Prerequisites...'", + 'sed -i \'/^#.*\/community/s/^#//\' /etc/apk/repositories', + 'apk update', + 'apk add curl wget git jq qemu-user', + ]); + } elseif ($supported_os_type->contains('sles')) { + $command = $command->merge([ + "echo 'Installing Prerequisites...'", + 'zypper refresh', + 'command -v curl >/dev/null || zypper install -y curl', + 'command -v wget >/dev/null || zypper install -y wget', + 'command -v git >/dev/null || zypper install -y git', + 'command -v jq >/dev/null || zypper install -y jq', + 'command -v qemu-linux-user >/dev/null || zypper install -y qemu-linux-user', ]); } else { - if ($supported_os_type->contains('debian')) { - $command = $command->merge([ - "echo 'Installing Prerequisites...'", - 'apt-get update -y', - 'command -v curl >/dev/null || apt install -y curl', - 'command -v wget >/dev/null || apt install -y wget', - 'command -v git >/dev/null || apt install -y git', - 'command -v jq >/dev/null || apt install -y jq', - 'command -v qemu-user-static >/dev/null || apt install -y qemu-user-static binfmt-support', - ]); - } elseif ($supported_os_type->contains('rhel')) { - $command = $command->merge([ - "echo 'Installing Prerequisites...'", - 'command -v curl >/dev/null || dnf install -y curl', - 'command -v wget >/dev/null || dnf install -y wget', - 'command -v git >/dev/null || dnf install -y git', - 'command -v jq >/dev/null || dnf install -y jq', - 'command -v qemu-user-static >/dev/null || dnf install -y qemu-user-static', - ]); - } elseif ($supported_os_type->contains('arch')) { - $command = $command->merge([ - "echo 'Installing Prerequisites...'", - 'pacman -Sy --noconfirm --needed curl wget git jq qemu-user-static', - ]); - } elseif ($supported_os_type->contains('alpine')) { - $command = $command->merge([ - "echo 'Installing Prerequisites...'", - 'sed -i \'/^#.*\/community/s/^#//\' /etc/apk/repositories', - 'apk update', - 'apk add curl wget git jq qemu-user', - ]); - } elseif ($supported_os_type->contains('sles')) { - $command = $command->merge([ - "echo 'Installing Prerequisites...'", - 'zypper refresh', - 'command -v curl >/dev/null || zypper install -y curl', - 'command -v wget >/dev/null || zypper install -y wget', - 'command -v git >/dev/null || zypper install -y git', - 'command -v jq >/dev/null || zypper install -y jq', - 'command -v qemu-linux-user >/dev/null || zypper install -y qemu-linux-user', - ]); - } else { - throw new \Exception('Unsupported OS'); - } + throw new \Exception('Unsupported OS'); + } + $command = $command->merge([ + "echo 'Installing Docker Engine...'", + "curl https://releases.rancher.com/install-docker/{$dockerVersion}.sh | sh || curl https://get.docker.com | sh -s -- --version {$dockerVersion}", + "echo 'Configuring Docker Engine (merging existing configuration with the required)...'", + 'mkdir -p /etc/docker', + 'test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json "/etc/docker/daemon.json.original-$(date +"%Y%m%d-%H%M%S")"', + "test ! -s /etc/docker/daemon.json && echo '{$config}' | base64 -d | tee /etc/docker/daemon.json > /dev/null", + "echo '{$config}' | base64 -d | tee /etc/docker/daemon.json.coolify > /dev/null", + 'jq . /etc/docker/daemon.json.coolify | tee /etc/docker/daemon.json.coolify.pretty > /dev/null', + 'mv /etc/docker/daemon.json.coolify.pretty /etc/docker/daemon.json.coolify', + "jq -s '.[0] * .[1]' /etc/docker/daemon.json.coolify /etc/docker/daemon.json | tee /etc/docker/daemon.json.appended > /dev/null", + 'mv /etc/docker/daemon.json.appended /etc/docker/daemon.json', + + "echo 'Restarting Docker Engine...'", + 'systemctl enable docker >/dev/null 2>&1 || true', + 'systemctl restart docker', + + "echo 'Installing multi-architecture support...'", + 'docker run --privileged --rm tonistiigi/binfmt --install all >/dev/null 2>&1 || echo "Warning: Failed to install multi-architecture support."', + ]); + + if ($server->isSwarm()) { $command = $command->merge([ - "echo 'Installing Docker Engine...'", - "curl https://releases.rancher.com/install-docker/{$dockerVersion}.sh | sh || curl https://get.docker.com | sh -s -- --version {$dockerVersion}", - "echo 'Configuring Docker Engine (merging existing configuration with the required)...'", - 'mkdir -p /etc/docker', - 'test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json "/etc/docker/daemon.json.original-$(date +"%Y%m%d-%H%M%S")"', - "test ! -s /etc/docker/daemon.json && echo '{$config}' | base64 -d | tee /etc/docker/daemon.json > /dev/null", - "echo '{$config}' | base64 -d | tee /etc/docker/daemon.json.coolify > /dev/null", - 'jq . /etc/docker/daemon.json.coolify | tee /etc/docker/daemon.json.coolify.pretty > /dev/null', - 'mv /etc/docker/daemon.json.coolify.pretty /etc/docker/daemon.json.coolify', - "jq -s '.[0] * .[1]' /etc/docker/daemon.json.coolify /etc/docker/daemon.json | tee /etc/docker/daemon.json.appended > /dev/null", - 'mv /etc/docker/daemon.json.appended /etc/docker/daemon.json', - - "echo 'Restarting Docker Engine...'", - 'systemctl enable docker >/dev/null 2>&1 || true', - 'systemctl restart docker', - - "echo 'Installing multi-architecture support...'", - 'docker run --privileged --rm tonistiigi/binfmt --install all >/dev/null 2>&1 || echo "Warning: Failed to install multi-architecture support."', + 'docker network create --attachable --driver overlay coolify-overlay >/dev/null 2>&1 || true', + ]); + } else { + $command = $command->merge([ + 'docker network create --attachable coolify >/dev/null 2>&1 || true', + "echo 'Done!'", ]); - - if ($server->isSwarm()) { - $command = $command->merge([ - 'docker network create --attachable --driver overlay coolify-overlay >/dev/null 2>&1 || true', - ]); - } else { - $command = $command->merge([ - 'docker network create --attachable coolify >/dev/null 2>&1 || true', - "echo 'Done!'", - ]); - } } return remote_process($command, $server);