Feature/nodejs (#397)

* Add node support using nvm

* Add icon

* Rename to NodeJS

* Rename to NodeJS

* update php and node logo

* only services which have units can be started,restarted,stopped,disabled and enabled

* add tests

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
This commit is contained in:
Mark Topper 2024-12-24 17:49:27 +01:00 committed by GitHub
parent da1043185a
commit 924920e6e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 706 additions and 2 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace App\Actions\NodeJS;
use App\Enums\ServiceStatus;
use App\Models\Server;
use App\SSH\Services\NodeJS\NodeJS;
use Illuminate\Validation\ValidationException;
class ChangeDefaultCli
{
public function change(Server $server, array $input): void
{
$this->validate($server, $input);
$service = $server->nodejs($input['version']);
/** @var NodeJS $handler */
$handler = $service->handler();
$handler->setDefaultCli();
$server->defaultService('nodejs')->update(['is_default' => 0]);
$service->update(['is_default' => 1]);
$service->update(['status' => ServiceStatus::READY]);
}
public function validate(Server $server, array $input): void
{
if (! isset($input['version']) || ! in_array($input['version'], $server->installedNodejsVersions())) {
throw ValidationException::withMessages(
['version' => __('This version is not installed')]
);
}
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Actions\NodeJS;
use App\Enums\NodeJS;
use App\Enums\ServiceStatus;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Validation\Rule;
class InstallNewNodeJsVersion
{
public function install(Server $server, array $input): void
{
$nodejs = new Service([
'server_id' => $server->id,
'type' => 'nodejs',
'type_data' => [],
'name' => 'nodejs',
'version' => $input['version'],
'status' => ServiceStatus::INSTALLING,
'is_default' => false,
]);
$nodejs->save();
dispatch(function () use ($nodejs) {
$nodejs->handler()->install();
$nodejs->status = ServiceStatus::READY;
$nodejs->save();
})->catch(function () use ($nodejs) {
$nodejs->delete();
})->onConnection('ssh');
}
public static function rules(Server $server): array
{
return [
'version' => [
'required',
Rule::in(config('core.nodejs_versions')),
Rule::notIn(array_merge($server->installedNodejsVersions(), [NodeJS::NONE])),
],
];
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace App\Actions\NodeJS;
use App\Enums\ServiceStatus;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
class UninstallNodeJS
{
public function uninstall(Server $server, array $input): void
{
$this->validate($server, $input);
/** @var Service $nodejs */
$nodejs = $server->nodejs($input['version']);
$nodejs->status = ServiceStatus::UNINSTALLING;
$nodejs->save();
dispatch(function () use ($nodejs) {
$nodejs->handler()->uninstall();
$nodejs->delete();
})->catch(function () use ($nodejs) {
$nodejs->status = ServiceStatus::FAILED;
$nodejs->save();
})->onConnection('ssh');
}
/**
* @throws ValidationException
*/
private function validate(Server $server, array $input): void
{
Validator::make($input, [
'version' => 'required|string',
])->validate();
if (! in_array($input['version'], $server->installedNodejsVersions())) {
throw ValidationException::withMessages(
['version' => __('This version is not installed')]
);
}
$hasSite = $server->sites()->where('nodejs_version', $input['version'])->first();
if ($hasSite) {
throw ValidationException::withMessages(
['version' => __('Cannot uninstall this version because some sites are using it!')]
);
}
}
}

32
app/Enums/NodeJS.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace App\Enums;
use App\Traits\Enum;
final class NodeJS
{
use Enum;
const NONE = 'none';
const V4 = '4';
const V6 = '6';
const V8 = '8';
const V10 = '10';
const V12 = '12';
const V14 = '14';
const V16 = '16';
const V18 = '18';
const V20 = '20';
const V22 = '22';
}

View File

@ -318,6 +318,17 @@ public function installedPHPVersions(): array
return $versions;
}
public function installedNodejsVersions(): array
{
$versions = [];
$nodes = $this->services()->where('type', 'nodejs')->get(['version']);
foreach ($nodes as $node) {
$versions[] = $node->version;
}
return $versions;
}
public function type(): ServerType
{
$typeClass = config('core.server_types_class')[$this->type];
@ -377,6 +388,15 @@ public function php(?string $version = null): ?Service
return $this->service('php', $version);
}
public function nodejs(?string $version = null): ?Service
{
if (! $version) {
return $this->defaultService('nodejs');
}
return $this->service('nodejs', $version);
}
public function memoryDatabase(?string $version = null): ?Service
{
if (! $version) {

View File

@ -43,6 +43,8 @@
* @property ?Ssl $activeSsl
* @property string $ssh_key_name
* @property ?SourceControl $sourceControl
*
* @TODO: Add nodejs_version column
*/
class Site extends AbstractModel
{

View File

@ -35,4 +35,29 @@ public function delete(User $user, Service $service): bool
{
return ($user->isAdmin() || $service->server->project->users->contains($user)) && $service->server->isReady();
}
public function start(User $user, Service $service): bool
{
return $this->update($user, $service) && $service->unit;
}
public function stop(User $user, Service $service): bool
{
return $this->update($user, $service) && $service->unit;
}
public function restart(User $user, Service $service): bool
{
return $this->update($user, $service) && $service->unit;
}
public function disable(User $user, Service $service): bool
{
return $this->update($user, $service) && $service->unit;
}
public function enable(User $user, Service $service): bool
{
return $this->update($user, $service) && $service->unit;
}
}

View File

@ -0,0 +1,77 @@
<?php
namespace App\SSH\Services\NodeJS;
use App\SSH\HasScripts;
use App\SSH\Services\AbstractService;
use Closure;
use Illuminate\Validation\Rule;
class NodeJS extends AbstractService
{
use HasScripts;
public function creationRules(array $input): array
{
return [
'version' => [
'required',
Rule::in(config('core.nodejs_versions')),
Rule::notIn([\App\Enums\NodeJS::NONE]),
Rule::unique('services', 'version')
->where('type', 'nodejs')
->where('server_id', $this->service->server_id),
],
];
}
public function deletionRules(): array
{
return [
'service' => [
function (string $attribute, mixed $value, Closure $fail) {
$hasSite = $this->service->server->sites()
->where('nodejs_version', $this->service->version)
->exists();
if ($hasSite) {
$fail('Some sites are using this NodeJS version.');
}
},
],
];
}
public function install(): void
{
$server = $this->service->server;
$server->ssh()->exec(
$this->getScript('install-nodejs.sh', [
'version' => $this->service->version,
'user' => $server->getSshUser(),
]),
'install-nodejs-'.$this->service->version
);
$this->service->server->os()->cleanup();
}
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall-nodejs.sh', [
'version' => $this->service->version,
]),
'uninstall-nodejs-'.$this->service->version
);
$this->service->server->os()->cleanup();
}
public function setDefaultCli(): void
{
$this->service->server->ssh()->exec(
$this->getScript('change-default-nodejs.sh', [
'version' => $this->service->version,
]),
'change-default-nodejs'
);
}
}

View File

@ -0,0 +1,13 @@
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
if ! nvm alias default __version__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! nvm use default; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Default Node.js is now:"
node -v

View File

@ -0,0 +1,68 @@
# Download NVM, if not already downloaded
if [ ! -d "$HOME/.nvm" ]; then
if ! git clone https://github.com/nvm-sh/nvm.git "$HOME/.nvm"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
fi
# Checkout the latest stable version of NVM
if ! git -C "$HOME/.nvm" checkout v0.40.1; then
echo 'VITO_SSH_ERROR' && exit 1
fi
# Load NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Define the NVM initialization script
NVM_INIT='
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
'
# List of potential configuration files
CONFIG_FILES=("$HOME/.bash_profile" "$HOME/.bash_login" "$HOME/.profile")
# Flag to track if at least one file exists
FILE_EXISTS=false
# Loop through each configuration file and check if it exists
for config_file in "${CONFIG_FILES[@]}"; do
if [ -f "$config_file" ]; then
FILE_EXISTS=true
# Check if the NVM initialization is already present
if ! grep -q 'export NVM_DIR="$HOME/.nvm"' "$config_file"; then
echo "Adding NVM initialization to $config_file"
echo "$NVM_INIT" >> "$config_file"
else
echo "NVM initialization already exists in $config_file"
fi
fi
done
# If no file exists, fallback to .profile
if [ "$FILE_EXISTS" = false ]; then
FALLBACK_FILE="$HOME/.profile"
echo "No configuration files found. Creating $FALLBACK_FILE and adding NVM initialization."
echo "$NVM_INIT" >> "$FALLBACK_FILE"
fi
echo "NVM initialization process completed."
# Install NVM if not already installed
if ! command -v nvm > /dev/null 2>&1; then
if ! bash "$HOME/.nvm/install.sh"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
fi
# Install the requested Node.js version
if ! nvm install __version__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Node.js version __version__ installed successfully!"
echo "Node version:" && node -v
echo "NPM version:" && npm -v
echo "NPX version:" && npx -v

View File

@ -0,0 +1,6 @@
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
if ! nvm uninstall __version__; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,66 @@
<?php
namespace App\Web\Pages\Servers\NodeJS;
use App\Actions\NodeJS\InstallNewNodeJsVersion;
use App\Enums\NodeJS;
use App\Models\Service;
use App\Web\Pages\Servers\NodeJS\Widgets\NodeJSList;
use App\Web\Pages\Servers\Page;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Notifications\Notification;
use Filament\Support\Enums\MaxWidth;
class Index extends Page
{
protected static ?string $slug = 'servers/{server}/nodejs';
protected static ?string $title = 'NodeJS';
public function mount(): void
{
$this->authorize('viewAny', [Service::class, $this->server]);
}
public function getWidgets(): array
{
return [
[NodeJSList::class, ['server' => $this->server]],
];
}
protected function getHeaderActions(): array
{
$installedNodeVersions = $this->server->installedNodejsVersions();
return [
Action::make('install')
->authorize(fn () => auth()->user()?->can('create', [Service::class, $this->server]))
->label('Install Node')
->icon('heroicon-o-archive-box-arrow-down')
->modalWidth(MaxWidth::Large)
->form([
Select::make('version')
->options(
collect(config('core.nodejs_versions'))
->filter(fn ($version) => ! in_array($version, array_merge($installedNodeVersions, [NodeJS::NONE])))
->mapWithKeys(fn ($version) => [$version => $version])
->toArray()
)
->rules(InstallNewNodeJsVersion::rules($this->server)['version']),
])
->modalSubmitActionLabel('Install')
->action(function (array $data) {
app(InstallNewNodeJsVersion::class)->install($this->server, $data);
Notification::make()
->success()
->title('Installing Node...')
->send();
$this->dispatch('$refresh');
}),
];
}
}

View File

@ -0,0 +1,117 @@
<?php
namespace App\Web\Pages\Servers\NodeJS\Widgets;
use App\Actions\NodeJS\ChangeDefaultCli;
use App\Actions\Service\Uninstall;
use App\Models\Server;
use App\Models\Service;
use Exception;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as Widget;
use Illuminate\Database\Eloquent\Builder;
class NodeJSList extends Widget
{
public Server $server;
protected $listeners = ['$refresh'];
protected function getTableQuery(): Builder
{
return Service::query()->where('type', 'nodejs')->where('server_id', $this->server->id);
}
protected function getTableColumns(): array
{
return [
TextColumn::make('version')
->sortable(),
TextColumn::make('status')
->label('Status')
->badge()
->color(fn (Service $service) => Service::$statusColors[$service->status])
->sortable(),
TextColumn::make('is_default')
->label('Default Cli')
->badge()
->color(fn (Service $service) => $service->is_default ? 'primary' : 'gray')
->state(fn (Service $service) => $service->is_default ? 'Yes' : 'No')
->sortable(),
TextColumn::make('created_at')
->label('Installed At')
->formatStateUsing(fn ($record) => $record->created_at_by_timezone),
];
}
/**
* @throws Exception
*/
public function table(Table $table): Table
{
return $table
->heading(null)
->query($this->getTableQuery())
->columns($this->getTableColumns())
->actions([
ActionGroup::make([
$this->defaultNodeJsCliAction(),
$this->uninstallAction(),
]),
]);
}
private function defaultNodeJsCliAction(): Action
{
return Action::make('default-nodejs-cli')
->authorize(fn (Service $nodejs) => auth()->user()?->can('update', $nodejs))
->label('Make Default CLI')
->hidden(fn (Service $service) => $service->is_default)
->action(function (Service $service) {
try {
app(ChangeDefaultCli::class)->change($this->server, ['version' => $service->version]);
Notification::make()
->success()
->title('Default NodeJS CLI changed!')
->send();
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
$this->dispatch('$refresh');
});
}
private function uninstallAction(): Action
{
return Action::make('uninstall')
->authorize(fn (Service $nodejs) => auth()->user()?->can('update', $nodejs))
->label('Uninstall')
->color('danger')
->requiresConfirmation()
->action(function (Service $service) {
try {
app(Uninstall::class)->uninstall($service);
} catch (Exception $e) {
Notification::make()
->danger()
->title($e->getMessage())
->send();
throw $e;
}
$this->dispatch('$refresh');
});
}
}

View File

@ -18,6 +18,7 @@
use App\Web\Pages\Servers\Firewall\Index as FirewallIndex;
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
use App\Web\Pages\Servers\Metrics\Index as MetricsIndex;
use App\Web\Pages\Servers\NodeJS\Index as NodeJsIndex;
use App\Web\Pages\Servers\PHP\Index as PHPIndex;
use App\Web\Pages\Servers\Services\Index as ServicesIndex;
use App\Web\Pages\Servers\Settings as ServerSettings;
@ -60,11 +61,18 @@ public function getSubNavigation(): array
if (auth()->user()->can('viewAny', [Service::class, $this->server])) {
$items[] = NavigationItem::make(PHPIndex::getNavigationLabel())
->icon('heroicon-o-code-bracket')
->icon('icon-php-alt')
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
->url(PHPIndex::getUrl(parameters: ['server' => $this->server]));
}
if (auth()->user()->can('viewAny', [Service::class, $this->server])) {
$items[] = NavigationItem::make(NodeJsIndex::getNavigationLabel())
->icon('icon-nodejs-alt')
->isActiveWhen(fn () => request()->routeIs(NodeJsIndex::getRouteName().'*'))
->url(NodeJsIndex::getUrl(parameters: ['server' => $this->server]));
}
if (auth()->user()->can('viewAny', [FirewallRule::class, $this->server])) {
$items[] = NavigationItem::make(FirewallIndex::getNavigationLabel())
->icon('heroicon-o-fire')

View File

@ -75,7 +75,7 @@ public function table(Table $table): Table
private function serviceAction(string $type, string $icon): Action
{
return Action::make($type)
->authorize(fn (Service $service) => auth()->user()?->can('update', $service))
->authorize(fn (Service $service) => auth()->user()?->can($type, $service))
->label(ucfirst($type).' Service')
->icon($icon)
->action(function (Service $service) use ($type) {

View File

@ -40,6 +40,19 @@
\App\Enums\PHP::V83,
\App\Enums\PHP::V84,
],
'nodejs_versions' => [
\App\Enums\NodeJS::NONE,
\App\Enums\NodeJS::V4,
\App\Enums\NodeJS::V6,
\App\Enums\NodeJS::V8,
\App\Enums\NodeJS::V10,
\App\Enums\NodeJS::V12,
\App\Enums\NodeJS::V14,
\App\Enums\NodeJS::V16,
\App\Enums\NodeJS::V18,
\App\Enums\NodeJS::V20,
\App\Enums\NodeJS::V22,
],
'databases' => [
\App\Enums\Database::NONE,
\App\Enums\Database::MYSQL57,
@ -162,6 +175,7 @@
'postgresql' => 'database',
'redis' => 'memory_database',
'php' => 'php',
'nodejs' => 'nodejs',
'ufw' => 'firewall',
'supervisor' => 'process_manager',
'vito-agent' => 'monitoring',
@ -174,6 +188,7 @@
'postgresql' => \App\SSH\Services\Database\Postgresql::class,
'redis' => \App\SSH\Services\Redis\Redis::class,
'php' => \App\SSH\Services\PHP\PHP::class,
'nodejs' => \App\SSH\Services\NodeJS\NodeJS::class,
'ufw' => \App\SSH\Services\Firewall\Ufw::class,
'supervisor' => \App\SSH\Services\ProcessManager\Supervisor::class,
'vito-agent' => \App\SSH\Services\Monitoring\VitoAgent\VitoAgent::class,
@ -204,6 +219,18 @@
'redis' => [
'latest',
],
'nodejs' => [
'4',
'6',
'8',
'10',
'12',
'14',
'16',
'18',
'20',
'22',
],
'php' => [
'5.6',
'7.0',

View File

@ -0,0 +1,7 @@
<!--blade-boxicons-->
<svg class="w-64 h-64" xmlns="http://www.w3.org/2000/svg" fill="currentColor" stroke="none" viewBox="0 0 24 24">
<path
d="M12 21.985c-.275 0-.532-.074-.772-.202l-2.439-1.448c-.365-.203-.182-.277-.072-.314.496-.165.588-.201 1.101-.493.056-.037.129-.02.185.017l1.87 1.12c.074.036.166.036.221 0l7.319-4.237c.074-.036.11-.11.11-.202V7.768c0-.091-.036-.165-.11-.201l-7.319-4.219c-.073-.037-.165-.037-.221 0L4.552 7.566c-.073.036-.11.129-.11.201v8.457c0 .073.037.166.11.202l2 1.157c1.082.548 1.762-.095 1.762-.735V8.502c0-.11.091-.221.22-.221h.936c.108 0 .22.092.22.221v8.347c0 1.449-.788 2.294-2.164 2.294-.422 0-.752 0-1.688-.46l-1.925-1.099a1.55 1.55 0 0 1-.771-1.34V7.786c0-.55.293-1.064.771-1.339l7.316-4.237a1.637 1.637 0 0 1 1.544 0l7.317 4.237c.479.274.771.789.771 1.339v8.458c0 .549-.293 1.063-.771 1.34l-7.317 4.236c-.241.11-.516.165-.773.165zm2.256-5.816c-3.21 0-3.87-1.468-3.87-2.714 0-.11.092-.221.22-.221h.954c.11 0 .201.073.201.184.147.971.568 1.449 2.514 1.449 1.54 0 2.202-.35 2.202-1.175 0-.477-.185-.825-2.587-1.063-1.999-.2-3.246-.643-3.246-2.238 0-1.485 1.247-2.366 3.339-2.366 2.347 0 3.503.809 3.649 2.568a.297.297 0 0 1-.056.165c-.037.036-.091.073-.146.073h-.953a.212.212 0 0 1-.202-.164c-.221-1.012-.789-1.34-2.292-1.34-1.689 0-1.891.587-1.891 1.027 0 .531.237.696 2.514.99 2.256.293 3.32.715 3.32 2.294-.02 1.615-1.339 2.531-3.67 2.531z"
>
</path>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

2
resources/svg/nodejs.svg Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48px" height="48px" baseProfile="basic"><path fill="#21a366" d="M24.007,45.419c-0.574,0-1.143-0.15-1.646-0.44l-5.24-3.103c-0.783-0.438-0.401-0.593-0.143-0.682 c1.044-0.365,1.255-0.448,2.369-1.081c0.117-0.067,0.27-0.043,0.39,0.028l4.026,2.389c0.145,0.079,0.352,0.079,0.486,0l15.697-9.061 c0.145-0.083,0.24-0.251,0.24-0.424V14.932c0-0.181-0.094-0.342-0.243-0.432L24.253,5.446c-0.145-0.086-0.338-0.086-0.483,0 L8.082,14.499c-0.152,0.086-0.249,0.255-0.249,0.428v18.114c0,0.173,0.094,0.338,0.244,0.42l4.299,2.483 c2.334,1.167,3.76-0.208,3.76-1.591V16.476c0-0.255,0.2-0.452,0.456-0.452h1.988c0.248,0,0.452,0.196,0.452,0.452v17.886 c0,3.112-1.697,4.9-4.648,4.9c-0.908,0-1.623,0-3.619-0.982l-4.118-2.373C5.629,35.317,5,34.216,5,33.042V14.928 c0-1.179,0.629-2.279,1.646-2.861L22.36,3.002c0.994-0.562,2.314-0.562,3.301,0l15.694,9.069C42.367,12.656,43,13.753,43,14.932 v18.114c0,1.175-0.633,2.271-1.646,2.861L25.66,44.971c-0.503,0.291-1.073,0.44-1.654,0.44"/><path fill="#21a366" d="M28.856,32.937c-6.868,0-8.308-3.153-8.308-5.797c0-0.251,0.203-0.452,0.455-0.452h2.028 c0.224,0,0.413,0.163,0.448,0.384c0.306,2.066,1.218,3.108,5.371,3.108c3.308,0,4.715-0.747,4.715-2.502 c0-1.01-0.401-1.76-5.54-2.263c-4.299-0.424-6.955-1.371-6.955-4.809c0-3.167,2.672-5.053,7.147-5.053 c5.026,0,7.517,1.745,7.831,5.493c0.012,0.13-0.035,0.255-0.122,0.35c-0.086,0.09-0.208,0.145-0.334,0.145h-2.039 c-0.212,0-0.397-0.149-0.44-0.354c-0.491-2.173-1.678-2.868-4.904-2.868c-3.611,0-4.031,1.257-4.031,2.2 c0,1.143,0.495,1.477,5.367,2.122c4.825,0.64,7.116,1.544,7.116,4.935c0,3.418-2.853,5.379-7.827,5.379"/></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,5 @@
<!--file-icons-->
<svg class="w-64 h-64" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 512 512" fill="currentColor">
<path
d="M170.322 349.808c-2.4-15.66-9-28.38-25.020-34.531-6.27-2.4-11.7-6.78-17.88-9.54-7.020-3.15-14.16-6.15-21.57-8.1-5.61-1.5-10.83 1.020-14.16 5.94-3.15 4.62-0.87 8.97 1.77 12.84 2.97 4.35 6.27 8.49 9.6 12.57 5.52 6.78 11.37 13.29 16.74 20.161 5.13 6.57 9.51 13.86 8.76 22.56-1.65 19.080-10.29 34.891-24.21 47.76-1.53 1.38-4.23 2.37-6.21 2.19-8.88-0.96-16.95-4.32-23.46-10.53-7.47-7.11-6.33-15.48 2.61-20.67 2.13-1.23 4.35-2.37 6.3-3.87 5.46-4.11 7.29-11.13 4.32-17.22-1.41-2.94-3-6.12-5.34-8.25-11.43-10.41-22.651-21.151-34.891-30.63-29.671-23.041-44.91-53.52-47.251-90.421-2.64-40.981 6.87-79.231 28.5-114.242 8.19-13.29 17.73-25.951 32.37-32.52 9.96-4.47 20.88-6.99 31.531-9.78 29.311-7.71 58.89-13.5 89.401-8.34 26.28 4.41 45.511 17.94 54.331 43.77 5.79 16.89 7.17 34.35 5.37 52.231-3.54 35.131-29.49 66.541-63.331 75.841-14.67 4.020-22.68 1.77-31.5-10.44-6.33-8.79-11.58-18.36-17.25-27.631-0.84-1.38-1.44-2.97-2.16-4.44-0.69-1.47-1.44-2.88-2.16-4.35 2.13 15.24 5.67 29.911 13.98 42.99 4.5 7.11 10.5 12.36 19.29 13.14 32.34 2.91 59.641-7.71 79.021-33.721 21.69-29.101 26.461-62.581 20.19-97.831-1.23-6.96-3.3-13.77-4.77-20.7-0.99-4.47 0.78-7.77 5.19-9.33 2.040-0.69 4.14-1.26 6.18-1.68 26.461-5.7 53.221-7.59 80.191-4.86 30.601 3.060 59.551 11.46 85.441 28.471 40.531 26.67 65.641 64.621 79.291 110.522 1.98 6.66 2.28 13.95 2.46 20.971 0.12 4.68-2.88 5.91-6.45 2.97-3.93-3.21-7.53-6.87-10.92-10.65-3.15-3.57-5.67-7.65-8.73-11.4-2.37-2.94-4.44-2.49-5.58 1.17-0.72 2.22-1.35 4.41-1.98 6.63-7.080 25.26-18.24 48.3-36.33 67.711-2.52 2.73-4.77 6.78-5.070 10.38-0.78 9.96-1.35 20.13-0.39 30.060 1.98 21.331 5.070 42.57 7.47 63.871 1.35 12.030-2.52 19.11-13.83 23.281-7.95 2.91-16.47 5.040-24.87 5.64-13.38 0.93-26.88 0.27-40.32 0.27-0.36-15 0.93-29.731-13.17-37.771 2.73-11.13 5.88-21.69 7.77-32.49 1.56-8.97 0.24-17.79-6.060-25.14-5.91-6.93-13.32-8.82-20.101-4.86-20.43 11.91-41.671 11.97-63.301 4.17-9.93-3.6-16.86-1.56-22.351 7.5-5.91 9.75-8.4 20.7-7.74 31.771 0.84 13.95 3.27 27.75 5.13 41.64 1.020 7.77 0.15 9.78-7.56 11.76-17.13 4.35-34.56 4.83-52.081 3.42-0.93-0.090-1.86-0.48-2.46-0.63-0.87-14.55 0.66-29.671-16.68-37.411 7.68-16.29 6.63-33.18 3.99-50.070l-0.060-0.15zM66.761 292.718c2.55-2.4 4.59-6.15 5.31-9.6 1.8-8.64-4.68-20.22-12.18-23.43-3.99-1.74-7.47-1.11-10.29 2.070-6.87 7.77-13.65 15.63-20.401 23.521-1.14 1.35-2.16 2.94-2.97 4.53-2.7 5.19-1.11 8.97 4.65 10.38 3.48 0.87 7.080 1.050 10.65 1.56 9.3-0.9 18.3-2.46 25.23-9v-0.030zM67.541 206.347c-0.030-6.18-5.19-11.34-11.28-11.37-6.27-0.030-11.67 5.58-11.46 11.76 0.27 6.21 5.43 11.19 11.61 11.070 6.24-0.090 11.22-5.19 11.16-11.43l-0.030-0.030z"></path>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,94 @@
<?php
namespace Tests\Feature;
use App\Enums\NodeJS;
use App\Enums\ServiceStatus;
use App\Facades\SSH;
use App\Models\Service;
use App\Web\Pages\Servers\NodeJS\Index;
use App\Web\Pages\Servers\NodeJS\Widgets\NodeJSList;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class NodeJSTest extends TestCase
{
use RefreshDatabase;
public function test_install_new_nodejs(): void
{
SSH::fake();
$this->actingAs($this->user);
Livewire::test(Index::class, ['server' => $this->server])
->callAction('install', [
'version' => NodeJS::V16,
])
->assertSuccessful();
$this->assertDatabaseHas('services', [
'server_id' => $this->server->id,
'type' => 'nodejs',
'version' => NodeJS::V16,
'status' => ServiceStatus::READY,
]);
}
public function test_uninstall_nodejs(): void
{
SSH::fake();
$this->actingAs($this->user);
$php = new Service([
'server_id' => $this->server->id,
'type' => 'nodejs',
'type_data' => [],
'name' => 'nodejs',
'version' => NodeJS::V16,
'status' => ServiceStatus::READY,
'is_default' => true,
]);
$php->save();
Livewire::test(NodeJSList::class, [
'server' => $this->server,
])
->callTableAction('uninstall', $php->id)
->assertSuccessful();
$this->assertDatabaseMissing('services', [
'id' => $php->id,
]);
}
public function test_change_default_nodejs_cli(): void
{
SSH::fake();
$this->actingAs($this->user);
/** @var Service $service */
$service = Service::factory()->create([
'server_id' => $this->server->id,
'type' => 'nodejs',
'type_data' => [],
'name' => 'nodejs',
'version' => NodeJS::V16,
'status' => ServiceStatus::READY,
'is_default' => false,
]);
Livewire::test(NodeJSList::class, [
'server' => $this->server,
])
->callTableAction('default-nodejs-cli', $service->id)
->assertSuccessful();
$service->refresh();
$this->assertTrue($service->is_default);
}
}

View File

@ -318,6 +318,11 @@ public static function installData(): array
'php',
'7.4',
],
[
'nodejs',
'nodejs',
'16',
],
[
'supervisor',
'process_manager',