mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
e976709522 | |||
5aa100519e | |||
ab43dfb2a6 | |||
a320e52dbf | |||
20c6b58866 | |||
f5c9d6701b | |||
ba069a2db0 | |||
8b86ff23c9 | |||
dfdd50beb7 | |||
924920e6e8 | |||
da1043185a | |||
ea3d64607a | |||
db81583884 |
@ -1,9 +1,9 @@
|
|||||||
name: Build and push Docker image
|
name: Docker Latest
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 1.x
|
|
||||||
- 2.x
|
- 2.x
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@ -25,12 +25,11 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push to the latest tag
|
||||||
run: |
|
run: |
|
||||||
docker buildx build . \
|
docker buildx build . \
|
||||||
-f docker/Dockerfile \
|
-f docker/Dockerfile \
|
||||||
-t vitodeploy/vito:${{ github.head_ref || github.ref_name }} \
|
-t vitodeploy/vito:latest \
|
||||||
--build-arg="RELEASE=0" \
|
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--no-cache \
|
--no-cache \
|
||||||
--push
|
--push
|
20
.github/workflows/docker-release.yml
vendored
20
.github/workflows/docker-release.yml
vendored
@ -1,6 +1,7 @@
|
|||||||
name: Build and push Docker image
|
name: Docker Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
release:
|
release:
|
||||||
types: [ created ]
|
types: [ created ]
|
||||||
|
|
||||||
@ -23,22 +24,29 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push to the release tag
|
||||||
run: |
|
run: |
|
||||||
docker buildx build . \
|
docker buildx build . \
|
||||||
-f docker/Dockerfile \
|
-f docker/Dockerfile \
|
||||||
-t vitodeploy/vito:${{ github.event.release.tag_name }} \
|
-t vitodeploy/vito:${{ github.event.release.tag_name }} \
|
||||||
--build-arg="RELEASE=0" \
|
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--no-cache \
|
--no-cache \
|
||||||
--push
|
--push
|
||||||
|
|
||||||
- name: Build and push latest tag
|
- name: Build and push to the 1.x tag
|
||||||
|
if: startsWith(github.event.release.target_commitish, '1.x')
|
||||||
|
run: |
|
||||||
|
docker buildx build . \
|
||||||
|
-f docker/Dockerfile \
|
||||||
|
-t vitodeploy/vito:1.x \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--push
|
||||||
|
|
||||||
|
- name: Build and push to the 2.x tag
|
||||||
if: startsWith(github.event.release.target_commitish, '2.x')
|
if: startsWith(github.event.release.target_commitish, '2.x')
|
||||||
run: |
|
run: |
|
||||||
docker buildx build . \
|
docker buildx build . \
|
||||||
-f docker/Dockerfile \
|
-f docker/Dockerfile \
|
||||||
-t vitodeploy/vito:latest \
|
-t vitodeploy/vito:2.x \
|
||||||
--build-arg="RELEASE=0" \
|
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--push
|
--push
|
||||||
|
32
app/Actions/NodeJS/ChangeDefaultCli.php
Normal file
32
app/Actions/NodeJS/ChangeDefaultCli.php
Normal 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')]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
app/Actions/NodeJS/InstallNewNodeJsVersion.php
Executable file
45
app/Actions/NodeJS/InstallNewNodeJsVersion.php
Executable 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])),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
53
app/Actions/NodeJS/UninstallNodeJS.php
Executable file
53
app/Actions/NodeJS/UninstallNodeJS.php
Executable 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!')]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,15 +3,11 @@
|
|||||||
namespace App\Actions\Queue;
|
namespace App\Actions\Queue;
|
||||||
|
|
||||||
use App\Models\Queue;
|
use App\Models\Queue;
|
||||||
use App\SSH\Services\ProcessManager\ProcessManager;
|
|
||||||
|
|
||||||
class DeleteQueue
|
class DeleteQueue
|
||||||
{
|
{
|
||||||
public function delete(Queue $queue): void
|
public function delete(Queue $queue): void
|
||||||
{
|
{
|
||||||
/** @var ProcessManager $processManager */
|
|
||||||
$processManager = $queue->server->processManager()->handler();
|
|
||||||
$processManager->delete($queue->id, $queue->site_id);
|
|
||||||
$queue->delete();
|
$queue->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@ class GetQueueLogs
|
|||||||
{
|
{
|
||||||
public function getLogs(Queue $queue): string
|
public function getLogs(Queue $queue): string
|
||||||
{
|
{
|
||||||
return $queue->server->processManager()->handler()->getLogs($queue->getLogFile());
|
return $queue->server->processManager()->handler()->getLogs($queue->user, $queue->getLogFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ final class Database
|
|||||||
|
|
||||||
const MYSQL80 = 'mysql80';
|
const MYSQL80 = 'mysql80';
|
||||||
|
|
||||||
|
const MYSQL84 = 'mysql84';
|
||||||
|
|
||||||
const MARIADB103 = 'mariadb103';
|
const MARIADB103 = 'mariadb103';
|
||||||
|
|
||||||
const MARIADB104 = 'mariadb104';
|
const MARIADB104 = 'mariadb104';
|
||||||
|
32
app/Enums/NodeJS.php
Normal file
32
app/Enums/NodeJS.php
Normal 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';
|
||||||
|
}
|
@ -11,6 +11,4 @@ final class StorageProvider
|
|||||||
const LOCAL = 'local';
|
const LOCAL = 'local';
|
||||||
|
|
||||||
const S3 = 's3';
|
const S3 = 's3';
|
||||||
|
|
||||||
const WASABI = 'wasabi';
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use phpseclib3\Crypt\Common\PrivateKey;
|
use phpseclib3\Crypt\Common\PrivateKey;
|
||||||
use phpseclib3\Crypt\PublicKeyLoader;
|
use phpseclib3\Crypt\PublicKeyLoader;
|
||||||
@ -93,7 +95,11 @@ public function connect(bool $sftp = false): void
|
|||||||
*/
|
*/
|
||||||
public function exec(string $command, string $log = '', ?int $siteId = null, ?bool $stream = false, ?callable $streamCallback = null): string
|
public function exec(string $command, string $log = '', ?int $siteId = null, ?bool $stream = false, ?callable $streamCallback = null): string
|
||||||
{
|
{
|
||||||
if (! $this->log && $log) {
|
if (! $log) {
|
||||||
|
$log = 'run-command';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->log) {
|
||||||
$this->log = ServerLog::make($this->server, $log);
|
$this->log = ServerLog::make($this->server, $log);
|
||||||
if ($siteId) {
|
if ($siteId) {
|
||||||
$this->log->forSite($siteId);
|
$this->log->forSite($siteId);
|
||||||
@ -102,7 +108,7 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! $this->connection) {
|
if (! $this->connection instanceof SSH2) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
}
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
@ -117,16 +123,18 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
|||||||
$this->connection->setTimeout(0);
|
$this->connection->setTimeout(0);
|
||||||
if ($stream) {
|
if ($stream) {
|
||||||
$this->connection->exec($command, function ($output) use ($streamCallback) {
|
$this->connection->exec($command, function ($output) use ($streamCallback) {
|
||||||
$this->log?->write($output);
|
$this->log->write($output);
|
||||||
|
|
||||||
return $streamCallback($output);
|
return $streamCallback($output);
|
||||||
});
|
});
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
} else {
|
} else {
|
||||||
$output = $this->connection->exec($command);
|
$output = '';
|
||||||
|
$this->connection->exec($command, function ($out) use (&$output) {
|
||||||
$this->log?->write($output);
|
$this->log->write($out);
|
||||||
|
$output .= $out;
|
||||||
|
});
|
||||||
|
|
||||||
if ($this->connection->getExitStatus() !== 0 || Str::contains($output, 'VITO_SSH_ERROR')) {
|
if ($this->connection->getExitStatus() !== 0 || Str::contains($output, 'VITO_SSH_ERROR')) {
|
||||||
throw new SSHCommandError(
|
throw new SSHCommandError(
|
||||||
@ -152,7 +160,7 @@ public function upload(string $local, string $remote): void
|
|||||||
{
|
{
|
||||||
$this->log = null;
|
$this->log = null;
|
||||||
|
|
||||||
if (! $this->connection) {
|
if (! $this->connection instanceof SFTP) {
|
||||||
$this->connect(true);
|
$this->connect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,13 +174,43 @@ public function download(string $local, string $remote): void
|
|||||||
{
|
{
|
||||||
$this->log = null;
|
$this->log = null;
|
||||||
|
|
||||||
if (! $this->connection) {
|
if (! $this->connection instanceof SFTP) {
|
||||||
$this->connect(true);
|
$this->connect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->connection->get($remote, $local, SFTP::SOURCE_LOCAL_FILE);
|
$this->connection->get($remote, $local, SFTP::SOURCE_LOCAL_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
|
public function write(string $remotePath, string $content, bool $sudo = false): void
|
||||||
|
{
|
||||||
|
$tmpName = Str::random(10).strtotime('now');
|
||||||
|
|
||||||
|
try {
|
||||||
|
/** @var FilesystemAdapter $storageDisk */
|
||||||
|
$storageDisk = Storage::disk('local');
|
||||||
|
|
||||||
|
$storageDisk->put($tmpName, $content);
|
||||||
|
|
||||||
|
if ($sudo) {
|
||||||
|
$this->upload($storageDisk->path($tmpName), sprintf('/home/%s/%s', $this->server->ssh_user, $tmpName));
|
||||||
|
$this->exec(sprintf('sudo mv /home/%s/%s %s', $this->server->ssh_user, $tmpName, $remotePath));
|
||||||
|
} else {
|
||||||
|
$this->upload($storageDisk->path($tmpName), $remotePath);
|
||||||
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
throw new SSHCommandError(
|
||||||
|
message: $e->getMessage()
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
if (Storage::disk('local')->exists($tmpName)) {
|
||||||
|
Storage::disk('local')->delete($tmpName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@ -4,14 +4,16 @@
|
|||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Spatie\RouteAttributes\Attributes\Get;
|
||||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||||
use Spatie\RouteAttributes\Attributes\Post;
|
use Spatie\RouteAttributes\Attributes\Post;
|
||||||
|
|
||||||
#[Middleware('auth')]
|
#[Middleware('auth')]
|
||||||
class ConsoleController extends Controller
|
class ConsoleController extends Controller
|
||||||
{
|
{
|
||||||
#[Post('/{server}/console', name: 'servers.console.run')]
|
#[Post('servers/{server}/console/run', name: 'servers.console.run')]
|
||||||
public function run(Server $server, Request $request)
|
public function run(Server $server, Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $server);
|
$this->authorize('update', $server);
|
||||||
@ -24,15 +26,29 @@ public function run(Server $server, Request $request)
|
|||||||
'command' => 'required|string',
|
'command' => 'required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$ssh = $server->ssh($request->user);
|
||||||
|
$log = 'console-'.time();
|
||||||
|
|
||||||
|
$user = $request->input('user');
|
||||||
|
$currentDir = $user == 'root' ? '/root' : '/home/'.$user;
|
||||||
|
if (Cache::has('console.'.$server->id.'.dir')) {
|
||||||
|
$currentDir = Cache::get('console.'.$server->id.'.dir');
|
||||||
|
}
|
||||||
|
|
||||||
return response()->stream(
|
return response()->stream(
|
||||||
function () use ($server, $request) {
|
function () use ($server, $request, $ssh, $log, $currentDir) {
|
||||||
$ssh = $server->ssh($request->user);
|
$command = 'cd '.$currentDir.' && '.$request->command.' && echo "VITO_WORKING_DIR: $(pwd)"';
|
||||||
$log = 'console-'.time();
|
$output = '';
|
||||||
$ssh->exec(command: $request->command, log: $log, stream: true, streamCallback: function ($output) {
|
$ssh->exec(command: $command, log: $log, stream: true, streamCallback: function ($out) use (&$output) {
|
||||||
echo $output;
|
echo preg_replace('/^VITO_WORKING_DIR:.*(\r?\n)?/m', '', $out);
|
||||||
|
$output .= $out;
|
||||||
ob_flush();
|
ob_flush();
|
||||||
flush();
|
flush();
|
||||||
});
|
});
|
||||||
|
// extract the working dir and put it in the session
|
||||||
|
if (preg_match('/VITO_WORKING_DIR: (.*)/', $output, $matches)) {
|
||||||
|
Cache::put('console.'.$server->id.'.dir', $matches[1]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
200,
|
200,
|
||||||
[
|
[
|
||||||
@ -42,4 +58,12 @@ function () use ($server, $request) {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Get('servers/{server}/console/working-dir', name: 'servers.console.working-dir')]
|
||||||
|
public function workingDir(Server $server)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'dir' => Cache::get('console.'.$server->id.'.dir'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,11 @@ public function handle(Request $request, Closure $next)
|
|||||||
|
|
||||||
if (! $user->currentProject) {
|
if (! $user->currentProject) {
|
||||||
if ($user->allProjects()->count() > 0) {
|
if ($user->allProjects()->count() > 0) {
|
||||||
$user->current_project_id = $user->projects->first()->id;
|
$user->current_project_id = $user->allProjects()->first()->id;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
$request->user()->refresh();
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
use App\Enums\QueueStatus;
|
use App\Enums\QueueStatus;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $server_id
|
* @property int $server_id
|
||||||
@ -62,7 +64,11 @@ public static function boot(): void
|
|||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
static::deleting(function (Queue $queue) {
|
static::deleting(function (Queue $queue) {
|
||||||
$queue->server->processManager()->handler()->delete($queue->id, $queue->site_id);
|
try {
|
||||||
|
$queue->server->processManager()->handler()->delete($queue->id, $queue->site_id);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
Log::error($e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +95,10 @@ public function site(): BelongsTo
|
|||||||
|
|
||||||
public function getLogDirectory(): string
|
public function getLogDirectory(): string
|
||||||
{
|
{
|
||||||
|
if ($this->user === 'root') {
|
||||||
|
return '/root/.logs/workers';
|
||||||
|
}
|
||||||
|
|
||||||
return '/home/'.$this->user.'/.logs/workers';
|
return '/home/'.$this->user.'/.logs/workers';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +121,12 @@ public static function boot(): void
|
|||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
try {
|
try {
|
||||||
$server->sites()->each(function (Site $site) {
|
$server->sites()->each(function (Site $site) {
|
||||||
$site->delete();
|
$site->queues()->delete();
|
||||||
|
$site->ssls()->delete();
|
||||||
|
$site->deployments()->delete();
|
||||||
|
$site->deploymentScript()->delete();
|
||||||
});
|
});
|
||||||
|
$server->sites()->delete();
|
||||||
$server->logs()->each(function (ServerLog $log) {
|
$server->logs()->each(function (ServerLog $log) {
|
||||||
$log->delete();
|
$log->delete();
|
||||||
});
|
});
|
||||||
@ -318,6 +322,17 @@ public function installedPHPVersions(): array
|
|||||||
return $versions;
|
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
|
public function type(): ServerType
|
||||||
{
|
{
|
||||||
$typeClass = config('core.server_types_class')[$this->type];
|
$typeClass = config('core.server_types_class')[$this->type];
|
||||||
@ -377,6 +392,15 @@ public function php(?string $version = null): ?Service
|
|||||||
return $this->service('php', $version);
|
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
|
public function memoryDatabase(?string $version = null): ?Service
|
||||||
{
|
{
|
||||||
if (! $version) {
|
if (! $version) {
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
* @property ?Ssl $activeSsl
|
* @property ?Ssl $activeSsl
|
||||||
* @property string $ssh_key_name
|
* @property string $ssh_key_name
|
||||||
* @property ?SourceControl $sourceControl
|
* @property ?SourceControl $sourceControl
|
||||||
|
*
|
||||||
|
* @TODO: Add nodejs_version column
|
||||||
*/
|
*/
|
||||||
class Site extends AbstractModel
|
class Site extends AbstractModel
|
||||||
{
|
{
|
||||||
|
@ -35,4 +35,29 @@ public function delete(User $user, Service $service): bool
|
|||||||
{
|
{
|
||||||
return ($user->isAdmin() || $service->server->project->users->contains($user)) && $service->server->isReady();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
27
app/SSH/Services/Database/scripts/mysql/install-8.4.sh
Executable file
27
app/SSH/Services/Database/scripts/mysql/install-8.4.sh
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
||||||
|
|
||||||
|
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y lsb-release
|
||||||
|
|
||||||
|
DEBIAN_FRONTEND=noninteractive wget https://dev.mysql.com/get/mysql-apt-config_0.8.32-1_all.deb
|
||||||
|
|
||||||
|
sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.32-1_all.deb
|
||||||
|
|
||||||
|
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
||||||
|
|
||||||
|
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server
|
||||||
|
|
||||||
|
sudo systemctl unmask mysql.service
|
||||||
|
|
||||||
|
sudo systemctl enable mysql
|
||||||
|
|
||||||
|
sudo systemctl start mysql
|
||||||
|
|
||||||
|
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
|
||||||
|
echo 'VITO_SSH_ERROR' && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
|
||||||
|
echo 'VITO_SSH_ERROR' && exit 1
|
||||||
|
fi
|
77
app/SSH/Services/NodeJS/NodeJS.php
Normal file
77
app/SSH/Services/NodeJS/NodeJS.php
Normal 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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
13
app/SSH/Services/NodeJS/scripts/change-default-nodejs.sh
Executable file
13
app/SSH/Services/NodeJS/scripts/change-default-nodejs.sh
Executable 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
|
68
app/SSH/Services/NodeJS/scripts/install-nodejs.sh
Executable file
68
app/SSH/Services/NodeJS/scripts/install-nodejs.sh
Executable 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
|
6
app/SSH/Services/NodeJS/scripts/uninstall-nodejs.sh
Executable file
6
app/SSH/Services/NodeJS/scripts/uninstall-nodejs.sh
Executable 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
|
@ -53,6 +53,7 @@ public function install(): void
|
|||||||
]),
|
]),
|
||||||
'install-php-'.$this->service->version
|
'install-php-'.$this->service->version
|
||||||
);
|
);
|
||||||
|
$this->installComposer();
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,4 +4,6 @@ curl -sS https://getcomposer.org/installer -o composer-setup.php
|
|||||||
|
|
||||||
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||||
|
|
||||||
|
rm composer-setup.php
|
||||||
|
|
||||||
composer
|
composer
|
||||||
|
@ -23,5 +23,5 @@ public function stop(int $id, ?int $siteId = null): void;
|
|||||||
|
|
||||||
public function start(int $id, ?int $siteId = null): void;
|
public function start(int $id, ?int $siteId = null): void;
|
||||||
|
|
||||||
public function getLogs(string $logPath): string;
|
public function getLogs(string $user, string $logPath): string;
|
||||||
}
|
}
|
||||||
|
@ -40,18 +40,22 @@ public function create(
|
|||||||
string $logFile,
|
string $logFile,
|
||||||
?int $siteId = null
|
?int $siteId = null
|
||||||
): void {
|
): void {
|
||||||
|
$this->service->server->ssh()->write(
|
||||||
|
"/etc/supervisor/conf.d/$id.conf",
|
||||||
|
$this->generateConfigFile(
|
||||||
|
$id,
|
||||||
|
$command,
|
||||||
|
$user,
|
||||||
|
$autoStart,
|
||||||
|
$autoRestart,
|
||||||
|
$numprocs,
|
||||||
|
$logFile
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
$this->service->server->ssh($user)->exec(
|
$this->service->server->ssh($user)->exec(
|
||||||
$this->getScript('supervisor/create-worker.sh', [
|
$this->getScript('supervisor/create-worker.sh', [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'config' => $this->generateConfigFile(
|
|
||||||
$id,
|
|
||||||
$command,
|
|
||||||
$user,
|
|
||||||
$autoStart,
|
|
||||||
$autoRestart,
|
|
||||||
$numprocs,
|
|
||||||
$logFile
|
|
||||||
),
|
|
||||||
]),
|
]),
|
||||||
'create-worker',
|
'create-worker',
|
||||||
$siteId
|
$siteId
|
||||||
@ -117,9 +121,9 @@ public function start(int $id, ?int $siteId = null): void
|
|||||||
/**
|
/**
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function getLogs(string $logPath): string
|
public function getLogs(string $user, string $logPath): string
|
||||||
{
|
{
|
||||||
return $this->service->server->ssh()->exec(
|
return $this->service->server->ssh($user)->exec(
|
||||||
"tail -100 $logPath"
|
"tail -100 $logPath"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,6 @@ mkdir -p ~/.logs/workers
|
|||||||
|
|
||||||
touch ~/.logs/workers/__id__.log
|
touch ~/.logs/workers/__id__.log
|
||||||
|
|
||||||
if ! echo '__config__' | sudo tee /etc/supervisor/conf.d/__id__.conf; then
|
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! sudo supervisorctl reread; then
|
if ! sudo supervisorctl reread; then
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
echo 'VITO_SSH_ERROR' && exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -19,7 +19,7 @@ http {
|
|||||||
tcp_nodelay on;
|
tcp_nodelay on;
|
||||||
keepalive_timeout 65;
|
keepalive_timeout 65;
|
||||||
types_hash_max_size 2048;
|
types_hash_max_size 2048;
|
||||||
# server_tokens off;
|
server_tokens off;
|
||||||
|
|
||||||
# server_names_hash_bucket_size 64;
|
# server_names_hash_bucket_size 64;
|
||||||
# server_name_in_redirect off;
|
# server_name_in_redirect off;
|
||||||
|
@ -3,36 +3,31 @@
|
|||||||
namespace App\SSH\Storage;
|
namespace App\SSH\Storage;
|
||||||
|
|
||||||
use App\Exceptions\SSHCommandError;
|
use App\Exceptions\SSHCommandError;
|
||||||
use App\Models\Server;
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\StorageProvider;
|
|
||||||
use App\SSH\HasS3Storage;
|
use App\SSH\HasS3Storage;
|
||||||
use App\SSH\HasScripts;
|
use App\SSH\HasScripts;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class S3 extends S3AbstractStorage
|
class S3 extends AbstractStorage
|
||||||
{
|
{
|
||||||
use HasS3Storage, HasScripts;
|
use HasS3Storage, HasScripts;
|
||||||
|
|
||||||
public function __construct(Server $server, StorageProvider $storageProvider)
|
|
||||||
{
|
|
||||||
parent::__construct($server, $storageProvider);
|
|
||||||
$this->setBucketRegion($this->storageProvider->credentials['region']);
|
|
||||||
$this->setApiUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws SSHCommandError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function upload(string $src, string $dest): array
|
public function upload(string $src, string $dest): array
|
||||||
{
|
{
|
||||||
|
/** @var \App\StorageProviders\S3 $provider */
|
||||||
|
$provider = $this->storageProvider->provider();
|
||||||
|
|
||||||
$uploadCommand = $this->getScript('s3/upload.sh', [
|
$uploadCommand = $this->getScript('s3/upload.sh', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||||
'dest' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$dest),
|
'dest' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$dest),
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
'key' => $this->storageProvider->credentials['key'],
|
||||||
'secret' => $this->storageProvider->credentials['secret'],
|
'secret' => $this->storageProvider->credentials['secret'],
|
||||||
'region' => $this->getBucketRegion(),
|
'region' => $this->storageProvider->credentials['region'],
|
||||||
'endpoint' => $this->getApiUrl(),
|
'endpoint' => $provider->getApiUrl(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$upload = $this->server->ssh()->exec($uploadCommand, 'upload-to-s3');
|
$upload = $this->server->ssh()->exec($uploadCommand, 'upload-to-s3');
|
||||||
@ -49,20 +44,25 @@ public function upload(string $src, string $dest): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws SSHCommandError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function download(string $src, string $dest): void
|
public function download(string $src, string $dest): void
|
||||||
{
|
{
|
||||||
|
/** @var \App\StorageProviders\S3 $provider */
|
||||||
|
$provider = $this->storageProvider->provider();
|
||||||
|
|
||||||
$downloadCommand = $this->getScript('s3/download.sh', [
|
$downloadCommand = $this->getScript('s3/download.sh', [
|
||||||
'src' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$src),
|
'src' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$src),
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
'key' => $this->storageProvider->credentials['key'],
|
||||||
'secret' => $this->storageProvider->credentials['secret'],
|
'secret' => $this->storageProvider->credentials['secret'],
|
||||||
'region' => $this->getBucketRegion(),
|
'region' => $this->storageProvider->credentials['region'],
|
||||||
'endpoint' => $this->getApiUrl(),
|
'endpoint' => $provider->getApiUrl(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Log::info('Downloading from S3', ['command' => $downloadCommand]);
|
||||||
|
|
||||||
$download = $this->server->ssh()->exec($downloadCommand, 'download-from-s3');
|
$download = $this->server->ssh()->exec($downloadCommand, 'download-from-s3');
|
||||||
|
|
||||||
if (! str_contains($download, 'Download successful')) {
|
if (! str_contains($download, 'Download successful')) {
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\SSH\Storage;
|
|
||||||
|
|
||||||
abstract class S3AbstractStorage extends AbstractStorage
|
|
||||||
{
|
|
||||||
protected ?string $apiUrl = null;
|
|
||||||
|
|
||||||
protected ?string $bucketRegion = null;
|
|
||||||
|
|
||||||
public function getApiUrl(): string
|
|
||||||
{
|
|
||||||
return $this->apiUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setApiUrl(?string $region = null): void
|
|
||||||
{
|
|
||||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
|
||||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.amazonaws.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getter and Setter for $bucketRegion
|
|
||||||
public function getBucketRegion(): string
|
|
||||||
{
|
|
||||||
return $this->bucketRegion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setBucketRegion(string $region): void
|
|
||||||
{
|
|
||||||
$this->bucketRegion = $region;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\SSH\Storage;
|
|
||||||
|
|
||||||
use App\Exceptions\SSHCommandError;
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\Models\StorageProvider;
|
|
||||||
use App\SSH\HasS3Storage;
|
|
||||||
use App\SSH\HasScripts;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class Wasabi extends S3AbstractStorage
|
|
||||||
{
|
|
||||||
use HasS3Storage, HasScripts;
|
|
||||||
|
|
||||||
public function __construct(Server $server, StorageProvider $storageProvider)
|
|
||||||
{
|
|
||||||
parent::__construct($server, $storageProvider);
|
|
||||||
$this->setBucketRegion($this->storageProvider->credentials['region']);
|
|
||||||
$this->setApiUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws SSHCommandError
|
|
||||||
*/
|
|
||||||
public function upload(string $src, string $dest): array
|
|
||||||
{
|
|
||||||
$uploadCommand = $this->getScript('wasabi/upload.sh', [
|
|
||||||
'src' => $src,
|
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
|
||||||
'dest' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$dest),
|
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
|
||||||
'secret' => $this->storageProvider->credentials['secret'],
|
|
||||||
'region' => $this->storageProvider->credentials['region'],
|
|
||||||
'endpoint' => $this->getApiUrl(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$upload = $this->server->ssh()->exec($uploadCommand, 'upload-to-wasabi');
|
|
||||||
|
|
||||||
if (str_contains($upload, 'Error') || ! str_contains($upload, 'upload:')) {
|
|
||||||
Log::error('Failed to upload to wasabi', ['output' => $upload]);
|
|
||||||
throw new SSHCommandError('Failed to upload to wasabi: '.$upload);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'size' => null, // You can parse the size from the output if needed
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws SSHCommandError
|
|
||||||
*/
|
|
||||||
public function download(string $src, string $dest): void
|
|
||||||
{
|
|
||||||
$downloadCommand = $this->getScript('wasabi/download.sh', [
|
|
||||||
'src' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$src),
|
|
||||||
'dest' => $dest,
|
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
|
||||||
'secret' => $this->storageProvider->credentials['secret'],
|
|
||||||
'region' => $this->storageProvider->credentials['region'],
|
|
||||||
'endpoint' => $this->getApiUrl(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$download = $this->server->ssh()->exec($downloadCommand, 'download-from-wasabi');
|
|
||||||
|
|
||||||
if (! str_contains($download, 'Download successful')) {
|
|
||||||
Log::error('Failed to download from wasabi', ['output' => $download]);
|
|
||||||
throw new SSHCommandError('Failed to download from wasabi: '.$download);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO Implement delete method
|
|
||||||
*/
|
|
||||||
public function delete(string $path): void {}
|
|
||||||
|
|
||||||
public function setApiUrl(?string $region = null): void
|
|
||||||
{
|
|
||||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
|
||||||
$this->apiUrl = "https://{$this->storageProvider->credentials['bucket']}.s3.{$this->getBucketRegion()}.wasabisys.com";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Configure AWS CLI with provided credentials
|
|
||||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
|
||||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
|
||||||
|
|
||||||
# Use the provided endpoint in the correct format
|
|
||||||
ENDPOINT="__endpoint__"
|
|
||||||
BUCKET="__bucket__"
|
|
||||||
REGION="__region__"
|
|
||||||
|
|
||||||
# Ensure that DEST does not have a trailing slash
|
|
||||||
SRC="__src__"
|
|
||||||
DEST="__dest__"
|
|
||||||
|
|
||||||
# Download the file from S3
|
|
||||||
echo "Downloading s3://__bucket____src__ to __dest__"
|
|
||||||
download_output=$(/usr/local/bin/aws s3 cp "s3://$BUCKET/$SRC" "$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
|
||||||
download_exit_code=$?
|
|
||||||
|
|
||||||
# Log output and exit code
|
|
||||||
echo "Download command output: $download_output"
|
|
||||||
echo "Download command exit code: $download_exit_code"
|
|
||||||
|
|
||||||
# Check if the download was successful
|
|
||||||
if [ $download_exit_code -eq 0 ]; then
|
|
||||||
echo "Download successful"
|
|
||||||
else
|
|
||||||
echo "Download failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
@ -1,59 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Check if AWS CLI is installed
|
|
||||||
if ! command -v aws &> /dev/null
|
|
||||||
then
|
|
||||||
echo "AWS CLI is not installed. Installing..."
|
|
||||||
|
|
||||||
# Detect system architecture
|
|
||||||
ARCH=$(uname -m)
|
|
||||||
if [ "$ARCH" == "x86_64" ]; then
|
|
||||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
|
|
||||||
elif [ "$ARCH" == "aarch64" ]; then
|
|
||||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"
|
|
||||||
else
|
|
||||||
echo "Unsupported architecture: $ARCH"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Download and install AWS CLI
|
|
||||||
sudo curl "$CLI_URL" -o "awscliv2.zip"
|
|
||||||
sudo unzip awscliv2.zip
|
|
||||||
sudo ./aws/install --update
|
|
||||||
sudo rm -rf awscliv2.zip aws
|
|
||||||
|
|
||||||
echo "AWS CLI installation completed."
|
|
||||||
else
|
|
||||||
echo "AWS CLI is already installed."
|
|
||||||
aws --version
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configure AWS CLI with provided credentials
|
|
||||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
|
||||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
|
||||||
|
|
||||||
# Use the provided endpoint in the correct format
|
|
||||||
ENDPOINT="__endpoint__"
|
|
||||||
BUCKET="__bucket__"
|
|
||||||
REGION="__region__"
|
|
||||||
|
|
||||||
# Ensure that DEST does not have a trailing slash
|
|
||||||
SRC="__src__"
|
|
||||||
DEST="__dest__"
|
|
||||||
|
|
||||||
# Upload the file
|
|
||||||
echo "Uploading __src__ to s3://$BUCKET/$DEST"
|
|
||||||
upload_output=$(/usr/local/bin/aws s3 cp "$SRC" "s3://$BUCKET/$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
|
||||||
upload_exit_code=$?
|
|
||||||
|
|
||||||
# Log output and exit code
|
|
||||||
echo "Upload command output: $upload_output"
|
|
||||||
echo "Upload command exit code: $upload_exit_code"
|
|
||||||
|
|
||||||
# Check if the upload was successful
|
|
||||||
if [ $upload_exit_code -eq 0 ]; then
|
|
||||||
echo "Upload successful"
|
|
||||||
else
|
|
||||||
echo "Upload failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
@ -3,46 +3,89 @@
|
|||||||
namespace App\StorageProviders;
|
namespace App\StorageProviders;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\StorageProvider;
|
||||||
use App\SSH\Storage\S3 as S3Storage;
|
use App\SSH\Storage\S3 as S3Storage;
|
||||||
use App\SSH\Storage\Storage;
|
use App\SSH\Storage\Storage;
|
||||||
use Aws\S3\Exception\S3Exception;
|
use Aws\S3\Exception\S3Exception;
|
||||||
|
use Aws\S3\S3Client;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class S3 extends S3AbstractStorageProvider
|
class S3 extends AbstractStorageProvider
|
||||||
{
|
{
|
||||||
|
protected StorageProvider $storageProvider;
|
||||||
|
|
||||||
|
protected ?S3Client $client = null;
|
||||||
|
|
||||||
|
protected array $clientConfig = [];
|
||||||
|
|
||||||
|
public function getApiUrl(): string
|
||||||
|
{
|
||||||
|
if (isset($this->storageProvider->credentials['api_url']) && $this->storageProvider->credentials['api_url']) {
|
||||||
|
return $this->storageProvider->credentials['api_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$region = $this->storageProvider->credentials['region'];
|
||||||
|
|
||||||
|
return "https://s3.{$region}.amazonaws.com";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClient(): S3Client
|
||||||
|
{
|
||||||
|
return new S3Client($this->clientConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the configuration array for the S3 client.
|
||||||
|
* This method can be overridden by child classes to modify the configuration.
|
||||||
|
*/
|
||||||
|
public function buildClientConfig(): array
|
||||||
|
{
|
||||||
|
$this->clientConfig = [
|
||||||
|
'credentials' => [
|
||||||
|
'key' => $this->storageProvider->credentials['key'],
|
||||||
|
'secret' => $this->storageProvider->credentials['secret'],
|
||||||
|
],
|
||||||
|
'region' => $this->storageProvider->credentials['region'],
|
||||||
|
'version' => 'latest',
|
||||||
|
'endpoint' => $this->getApiUrl(),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->clientConfig;
|
||||||
|
}
|
||||||
|
|
||||||
public function validationRules(): array
|
public function validationRules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'api_url' => 'nullable',
|
||||||
'key' => 'required',
|
'key' => 'required',
|
||||||
'secret' => 'required',
|
'secret' => 'required',
|
||||||
'region' => 'required',
|
'region' => 'required',
|
||||||
'bucket' => 'required',
|
'bucket' => 'required',
|
||||||
'path' => 'required',
|
'path' => 'nullable',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function credentialData(array $input): array
|
public function credentialData(array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'api_url' => $input['api_url'] ?? '',
|
||||||
'key' => $input['key'],
|
'key' => $input['key'],
|
||||||
'secret' => $input['secret'],
|
'secret' => $input['secret'],
|
||||||
'region' => $input['region'],
|
'region' => $input['region'],
|
||||||
'bucket' => $input['bucket'],
|
'bucket' => $input['bucket'],
|
||||||
'path' => $input['path'],
|
'path' => $input['path'] ?? '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect(): bool
|
public function connect(): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->setBucketRegion($this->storageProvider->credentials['region']);
|
|
||||||
$this->setApiUrl();
|
|
||||||
$this->buildClientConfig();
|
$this->buildClientConfig();
|
||||||
$this->getClient()->listBuckets();
|
$this->getClient()->listBuckets();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (S3Exception $e) {
|
} catch (S3Exception $e) {
|
||||||
Log::error('Failed to connect to S3', ['exception' => $e]);
|
Log::error('Failed to connect to the provider', ['exception' => $e]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\StorageProviders;
|
|
||||||
|
|
||||||
use App\Models\StorageProvider;
|
|
||||||
use Aws\S3\S3Client;
|
|
||||||
|
|
||||||
abstract class S3AbstractStorageProvider extends AbstractStorageProvider implements S3ClientInterface, S3StorageInterface
|
|
||||||
{
|
|
||||||
protected ?string $apiUrl = null;
|
|
||||||
|
|
||||||
protected ?string $bucketRegion = null;
|
|
||||||
|
|
||||||
protected ?S3Client $client = null;
|
|
||||||
|
|
||||||
protected StorageProvider $storageProvider;
|
|
||||||
|
|
||||||
protected array $clientConfig = [];
|
|
||||||
|
|
||||||
public function getApiUrl(): string
|
|
||||||
{
|
|
||||||
return $this->apiUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setApiUrl(?string $region = null): void
|
|
||||||
{
|
|
||||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
|
||||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.amazonaws.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBucketRegion(): string
|
|
||||||
{
|
|
||||||
return $this->bucketRegion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setBucketRegion(string $region): void
|
|
||||||
{
|
|
||||||
$this->bucketRegion = $region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClient(): S3Client
|
|
||||||
{
|
|
||||||
return new S3Client($this->clientConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the configuration array for the S3 client.
|
|
||||||
* This method can be overridden by child classes to modify the configuration.
|
|
||||||
*/
|
|
||||||
public function buildClientConfig(): array
|
|
||||||
{
|
|
||||||
$this->clientConfig = [
|
|
||||||
'credentials' => [
|
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
|
||||||
'secret' => $this->storageProvider->credentials['secret'],
|
|
||||||
],
|
|
||||||
'region' => $this->getBucketRegion(),
|
|
||||||
'version' => 'latest',
|
|
||||||
'endpoint' => $this->getApiUrl(),
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->clientConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set or update a configuration parameter for the S3 client.
|
|
||||||
*/
|
|
||||||
public function setConfigParam(array $param): void
|
|
||||||
{
|
|
||||||
foreach ($param as $key => $value) {
|
|
||||||
$this->clientConfig[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\StorageProviders;
|
|
||||||
|
|
||||||
use Aws\S3\S3Client;
|
|
||||||
|
|
||||||
interface S3ClientInterface
|
|
||||||
{
|
|
||||||
public function getClient(): S3Client;
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\StorageProviders;
|
|
||||||
|
|
||||||
interface S3StorageInterface
|
|
||||||
{
|
|
||||||
public function getApiUrl(): string;
|
|
||||||
|
|
||||||
public function setApiUrl(?string $region = null): void;
|
|
||||||
|
|
||||||
public function getBucketRegion(): string;
|
|
||||||
|
|
||||||
public function setBucketRegion(string $region): void;
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\StorageProviders;
|
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use App\SSH\Storage\Storage;
|
|
||||||
use App\SSH\Storage\Wasabi as WasabiStorage;
|
|
||||||
use Aws\S3\Exception\S3Exception;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class Wasabi extends S3AbstractStorageProvider
|
|
||||||
{
|
|
||||||
private const DEFAULT_REGION = 'us-east-1';
|
|
||||||
|
|
||||||
public function validationRules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'key' => 'required',
|
|
||||||
'secret' => 'required',
|
|
||||||
'region' => 'required',
|
|
||||||
'bucket' => 'required',
|
|
||||||
'path' => 'required',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function credentialData(array $input): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'key' => $input['key'],
|
|
||||||
'secret' => $input['secret'],
|
|
||||||
'region' => $input['region'],
|
|
||||||
'bucket' => $input['bucket'],
|
|
||||||
'path' => $input['path'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function connect(): bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->setBucketRegion(self::DEFAULT_REGION);
|
|
||||||
$this->setApiUrl();
|
|
||||||
$this->buildClientConfig();
|
|
||||||
$this->getClient()->listBuckets();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (S3Exception $e) {
|
|
||||||
Log::error('Failed to connect to S3', ['exception' => $e]);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the configuration array for the S3 client.
|
|
||||||
* This method can be overridden by child classes to modify the configuration.
|
|
||||||
*/
|
|
||||||
public function buildClientConfig(): array
|
|
||||||
{
|
|
||||||
$this->clientConfig = [
|
|
||||||
'credentials' => [
|
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
|
||||||
'secret' => $this->storageProvider->credentials['secret'],
|
|
||||||
],
|
|
||||||
'region' => $this->getBucketRegion(),
|
|
||||||
'version' => 'latest',
|
|
||||||
'endpoint' => $this->getApiUrl(),
|
|
||||||
'use_path_style_endpoint' => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->clientConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ssh(Server $server): Storage
|
|
||||||
{
|
|
||||||
return new WasabiStorage($server, $this->storageProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setApiUrl(?string $region = null): void
|
|
||||||
{
|
|
||||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
|
||||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.wasabisys.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(array $paths): void {}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Web\Pages\Servers\Console;
|
namespace App\Web\Pages\Servers\Console;
|
||||||
|
|
||||||
use App\Web\Pages\Servers\Page;
|
use App\Web\Pages\Servers\Page;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
@ -27,4 +28,16 @@ public function getWidgets(): array
|
|||||||
[Widgets\Console::class, ['server' => $this->server]],
|
[Widgets\Console::class, ['server' => $this->server]],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('read-the-docs')
|
||||||
|
->label('Read the Docs')
|
||||||
|
->icon('heroicon-o-document-text')
|
||||||
|
->color('gray')
|
||||||
|
->url('https://vitodeploy.com/servers/console.html')
|
||||||
|
->openUrlInNewTab(),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
66
app/Web/Pages/Servers/NodeJS/Index.php
Normal file
66
app/Web/Pages/Servers/NodeJS/Index.php
Normal 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');
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
117
app/Web/Pages/Servers/NodeJS/Widgets/NodeJSList.php
Normal file
117
app/Web/Pages/Servers/NodeJS/Widgets/NodeJSList.php
Normal 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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
use App\Web\Pages\Servers\Firewall\Index as FirewallIndex;
|
use App\Web\Pages\Servers\Firewall\Index as FirewallIndex;
|
||||||
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
|
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
|
||||||
use App\Web\Pages\Servers\Metrics\Index as MetricsIndex;
|
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\PHP\Index as PHPIndex;
|
||||||
use App\Web\Pages\Servers\Services\Index as ServicesIndex;
|
use App\Web\Pages\Servers\Services\Index as ServicesIndex;
|
||||||
use App\Web\Pages\Servers\Settings as ServerSettings;
|
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])) {
|
if (auth()->user()->can('viewAny', [Service::class, $this->server])) {
|
||||||
$items[] = NavigationItem::make(PHPIndex::getNavigationLabel())
|
$items[] = NavigationItem::make(PHPIndex::getNavigationLabel())
|
||||||
->icon('heroicon-o-code-bracket')
|
->icon('icon-php-alt')
|
||||||
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
|
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
|
||||||
->url(PHPIndex::getUrl(parameters: ['server' => $this->server]));
|
->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])) {
|
if (auth()->user()->can('viewAny', [FirewallRule::class, $this->server])) {
|
||||||
$items[] = NavigationItem::make(FirewallIndex::getNavigationLabel())
|
$items[] = NavigationItem::make(FirewallIndex::getNavigationLabel())
|
||||||
->icon('heroicon-o-fire')
|
->icon('heroicon-o-fire')
|
||||||
|
@ -75,7 +75,7 @@ public function table(Table $table): Table
|
|||||||
private function serviceAction(string $type, string $icon): Action
|
private function serviceAction(string $type, string $icon): Action
|
||||||
{
|
{
|
||||||
return Action::make($type)
|
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')
|
->label(ucfirst($type).' Service')
|
||||||
->icon($icon)
|
->icon($icon)
|
||||||
->action(function (Service $service) use ($type) {
|
->action(function (Service $service) use ($type) {
|
||||||
|
@ -111,20 +111,19 @@ public function getHeaderActions(): array
|
|||||||
return $actions;
|
return $actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSecondSubNavigation(): array
|
|
||||||
{
|
|
||||||
if ($this->site->isInstalling()) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getSecondSubNavigation();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function deployAction(): Action
|
private function deployAction(): Action
|
||||||
{
|
{
|
||||||
return Action::make('deploy')
|
return Action::make('deploy')
|
||||||
->icon('heroicon-o-rocket-launch')
|
->icon('heroicon-o-rocket-launch')
|
||||||
->action(function () {
|
->action(function () {
|
||||||
|
if (! $this->site->deploymentScript?->content) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Deployment script is not set!')
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
run_action($this, function () {
|
run_action($this, function () {
|
||||||
app(Deploy::class)->run($this->site);
|
app(Deploy::class)->run($this->site);
|
||||||
|
|
||||||
|
@ -55,10 +55,14 @@ public static function form(): array
|
|||||||
->visible(fn ($get) => $get('provider') == StorageProvider::FTP)
|
->visible(fn ($get) => $get('provider') == StorageProvider::FTP)
|
||||||
->rules(fn ($get) => CreateStorageProvider::rules($get())['passive']),
|
->rules(fn ($get) => CreateStorageProvider::rules($get())['passive']),
|
||||||
]),
|
]),
|
||||||
|
TextInput::make('api_url')
|
||||||
|
->label('API URL')
|
||||||
|
->visible(fn ($get) => $get('provider') == StorageProvider::S3)
|
||||||
|
->rules(fn ($get) => CreateStorageProvider::rules($get())['api_url'])
|
||||||
|
->helperText('Required if you are using an S3 compatible provider like Cloudflare R2'),
|
||||||
TextInput::make('path')
|
TextInput::make('path')
|
||||||
->visible(fn ($get) => in_array($get('provider'), [
|
->visible(fn ($get) => in_array($get('provider'), [
|
||||||
StorageProvider::S3,
|
StorageProvider::S3,
|
||||||
StorageProvider::WASABI,
|
|
||||||
StorageProvider::FTP,
|
StorageProvider::FTP,
|
||||||
StorageProvider::LOCAL,
|
StorageProvider::LOCAL,
|
||||||
]))
|
]))
|
||||||
@ -70,16 +74,9 @@ public static function form(): array
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
Grid::make()
|
Grid::make()
|
||||||
->visible(fn ($get) => in_array($get('provider'), [
|
->visible(fn ($get) => $get('provider') == StorageProvider::S3)
|
||||||
StorageProvider::S3,
|
|
||||||
StorageProvider::WASABI,
|
|
||||||
]))
|
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('key')
|
TextInput::make('key')
|
||||||
->visible(fn ($get) => in_array($get('provider'), [
|
|
||||||
StorageProvider::S3,
|
|
||||||
StorageProvider::WASABI,
|
|
||||||
]))
|
|
||||||
->rules(fn ($get) => CreateStorageProvider::rules($get())['key'])
|
->rules(fn ($get) => CreateStorageProvider::rules($get())['key'])
|
||||||
->helperText(function ($get) {
|
->helperText(function ($get) {
|
||||||
return match ($get('provider')) {
|
return match ($get('provider')) {
|
||||||
@ -88,31 +85,14 @@ public static function form(): array
|
|||||||
text: 'How to generate?',
|
text: 'How to generate?',
|
||||||
external: true
|
external: true
|
||||||
),
|
),
|
||||||
StorageProvider::WASABI => new Link(
|
|
||||||
href: 'https://docs.wasabi.com/docs/creating-a-user-account-and-access-key',
|
|
||||||
text: 'How to generate?',
|
|
||||||
external: true
|
|
||||||
),
|
|
||||||
default => '',
|
default => '',
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
TextInput::make('secret')
|
TextInput::make('secret')
|
||||||
->visible(fn ($get) => in_array($get('provider'), [
|
|
||||||
StorageProvider::S3,
|
|
||||||
StorageProvider::WASABI,
|
|
||||||
]))
|
|
||||||
->rules(fn ($get) => CreateStorageProvider::rules($get())['secret']),
|
->rules(fn ($get) => CreateStorageProvider::rules($get())['secret']),
|
||||||
TextInput::make('region')
|
TextInput::make('region')
|
||||||
->visible(fn ($get) => in_array($get('provider'), [
|
|
||||||
StorageProvider::S3,
|
|
||||||
StorageProvider::WASABI,
|
|
||||||
]))
|
|
||||||
->rules(fn ($get) => CreateStorageProvider::rules($get())['region']),
|
->rules(fn ($get) => CreateStorageProvider::rules($get())['region']),
|
||||||
TextInput::make('bucket')
|
TextInput::make('bucket')
|
||||||
->visible(fn ($get) => in_array($get('provider'), [
|
|
||||||
StorageProvider::S3,
|
|
||||||
StorageProvider::WASABI,
|
|
||||||
]))
|
|
||||||
->rules(fn ($get) => CreateStorageProvider::rules($get())['bucket']),
|
->rules(fn ($get) => CreateStorageProvider::rules($get())['bucket']),
|
||||||
]),
|
]),
|
||||||
Checkbox::make('global')
|
Checkbox::make('global')
|
||||||
|
@ -211,7 +211,7 @@
|
|||||||
// 'ExampleClass' => App\Example\ExampleClass::class,
|
// 'ExampleClass' => App\Example\ExampleClass::class,
|
||||||
])->toArray(),
|
])->toArray(),
|
||||||
|
|
||||||
'version' => '2.0.0',
|
'version' => '2.1.0',
|
||||||
|
|
||||||
'demo' => env('APP_DEMO', false),
|
'demo' => env('APP_DEMO', false),
|
||||||
];
|
];
|
||||||
|
@ -40,10 +40,24 @@
|
|||||||
\App\Enums\PHP::V83,
|
\App\Enums\PHP::V83,
|
||||||
\App\Enums\PHP::V84,
|
\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' => [
|
'databases' => [
|
||||||
\App\Enums\Database::NONE,
|
\App\Enums\Database::NONE,
|
||||||
\App\Enums\Database::MYSQL57,
|
\App\Enums\Database::MYSQL57,
|
||||||
\App\Enums\Database::MYSQL80,
|
\App\Enums\Database::MYSQL80,
|
||||||
|
\App\Enums\Database::MYSQL84,
|
||||||
\App\Enums\Database::MARIADB103,
|
\App\Enums\Database::MARIADB103,
|
||||||
\App\Enums\Database::MARIADB104,
|
\App\Enums\Database::MARIADB104,
|
||||||
\App\Enums\Database::MARIADB106,
|
\App\Enums\Database::MARIADB106,
|
||||||
@ -59,6 +73,7 @@
|
|||||||
\App\Enums\Database::NONE => 'none',
|
\App\Enums\Database::NONE => 'none',
|
||||||
\App\Enums\Database::MYSQL57 => 'mysql',
|
\App\Enums\Database::MYSQL57 => 'mysql',
|
||||||
\App\Enums\Database::MYSQL80 => 'mysql',
|
\App\Enums\Database::MYSQL80 => 'mysql',
|
||||||
|
\App\Enums\Database::MYSQL84 => 'mysql',
|
||||||
\App\Enums\Database::MARIADB103 => 'mariadb',
|
\App\Enums\Database::MARIADB103 => 'mariadb',
|
||||||
\App\Enums\Database::MARIADB104 => 'mariadb',
|
\App\Enums\Database::MARIADB104 => 'mariadb',
|
||||||
\App\Enums\Database::MARIADB106 => 'mariadb',
|
\App\Enums\Database::MARIADB106 => 'mariadb',
|
||||||
@ -74,6 +89,7 @@
|
|||||||
\App\Enums\Database::NONE => '',
|
\App\Enums\Database::NONE => '',
|
||||||
\App\Enums\Database::MYSQL57 => '5.7',
|
\App\Enums\Database::MYSQL57 => '5.7',
|
||||||
\App\Enums\Database::MYSQL80 => '8.0',
|
\App\Enums\Database::MYSQL80 => '8.0',
|
||||||
|
\App\Enums\Database::MYSQL84 => '8.4',
|
||||||
\App\Enums\Database::MARIADB103 => '10.3',
|
\App\Enums\Database::MARIADB103 => '10.3',
|
||||||
\App\Enums\Database::MARIADB104 => '10.4',
|
\App\Enums\Database::MARIADB104 => '10.4',
|
||||||
\App\Enums\Database::MARIADB106 => '10.6',
|
\App\Enums\Database::MARIADB106 => '10.6',
|
||||||
@ -162,6 +178,7 @@
|
|||||||
'postgresql' => 'database',
|
'postgresql' => 'database',
|
||||||
'redis' => 'memory_database',
|
'redis' => 'memory_database',
|
||||||
'php' => 'php',
|
'php' => 'php',
|
||||||
|
'nodejs' => 'nodejs',
|
||||||
'ufw' => 'firewall',
|
'ufw' => 'firewall',
|
||||||
'supervisor' => 'process_manager',
|
'supervisor' => 'process_manager',
|
||||||
'vito-agent' => 'monitoring',
|
'vito-agent' => 'monitoring',
|
||||||
@ -174,6 +191,7 @@
|
|||||||
'postgresql' => \App\SSH\Services\Database\Postgresql::class,
|
'postgresql' => \App\SSH\Services\Database\Postgresql::class,
|
||||||
'redis' => \App\SSH\Services\Redis\Redis::class,
|
'redis' => \App\SSH\Services\Redis\Redis::class,
|
||||||
'php' => \App\SSH\Services\PHP\PHP::class,
|
'php' => \App\SSH\Services\PHP\PHP::class,
|
||||||
|
'nodejs' => \App\SSH\Services\NodeJS\NodeJS::class,
|
||||||
'ufw' => \App\SSH\Services\Firewall\Ufw::class,
|
'ufw' => \App\SSH\Services\Firewall\Ufw::class,
|
||||||
'supervisor' => \App\SSH\Services\ProcessManager\Supervisor::class,
|
'supervisor' => \App\SSH\Services\ProcessManager\Supervisor::class,
|
||||||
'vito-agent' => \App\SSH\Services\Monitoring\VitoAgent\VitoAgent::class,
|
'vito-agent' => \App\SSH\Services\Monitoring\VitoAgent\VitoAgent::class,
|
||||||
@ -186,6 +204,7 @@
|
|||||||
'mysql' => [
|
'mysql' => [
|
||||||
'5.7',
|
'5.7',
|
||||||
'8.0',
|
'8.0',
|
||||||
|
'8.4',
|
||||||
],
|
],
|
||||||
'mariadb' => [
|
'mariadb' => [
|
||||||
'10.3',
|
'10.3',
|
||||||
@ -204,6 +223,18 @@
|
|||||||
'redis' => [
|
'redis' => [
|
||||||
'latest',
|
'latest',
|
||||||
],
|
],
|
||||||
|
'nodejs' => [
|
||||||
|
'4',
|
||||||
|
'6',
|
||||||
|
'8',
|
||||||
|
'10',
|
||||||
|
'12',
|
||||||
|
'14',
|
||||||
|
'16',
|
||||||
|
'18',
|
||||||
|
'20',
|
||||||
|
'22',
|
||||||
|
],
|
||||||
'php' => [
|
'php' => [
|
||||||
'5.6',
|
'5.6',
|
||||||
'7.0',
|
'7.0',
|
||||||
@ -246,14 +277,17 @@
|
|||||||
\App\Enums\OperatingSystem::UBUNTU20 => [
|
\App\Enums\OperatingSystem::UBUNTU20 => [
|
||||||
'5.7' => 'mysql',
|
'5.7' => 'mysql',
|
||||||
'8.0' => 'mysql',
|
'8.0' => 'mysql',
|
||||||
|
'8.4' => 'mysql',
|
||||||
],
|
],
|
||||||
\App\Enums\OperatingSystem::UBUNTU22 => [
|
\App\Enums\OperatingSystem::UBUNTU22 => [
|
||||||
'5.7' => 'mysql',
|
'5.7' => 'mysql',
|
||||||
'8.0' => 'mysql',
|
'8.0' => 'mysql',
|
||||||
|
'8.4' => 'mysql',
|
||||||
],
|
],
|
||||||
\App\Enums\OperatingSystem::UBUNTU24 => [
|
\App\Enums\OperatingSystem::UBUNTU24 => [
|
||||||
'5.7' => 'mysql',
|
'5.7' => 'mysql',
|
||||||
'8.0' => 'mysql',
|
'8.0' => 'mysql',
|
||||||
|
'8.4' => 'mysql',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'mariadb' => [
|
'mariadb' => [
|
||||||
@ -489,15 +523,12 @@
|
|||||||
\App\Enums\StorageProvider::FTP,
|
\App\Enums\StorageProvider::FTP,
|
||||||
\App\Enums\StorageProvider::LOCAL,
|
\App\Enums\StorageProvider::LOCAL,
|
||||||
\App\Enums\StorageProvider::S3,
|
\App\Enums\StorageProvider::S3,
|
||||||
\App\Enums\StorageProvider::WASABI,
|
|
||||||
],
|
],
|
||||||
'storage_providers_class' => [
|
'storage_providers_class' => [
|
||||||
\App\Enums\StorageProvider::DROPBOX => \App\StorageProviders\Dropbox::class,
|
\App\Enums\StorageProvider::DROPBOX => \App\StorageProviders\Dropbox::class,
|
||||||
\App\Enums\StorageProvider::FTP => \App\StorageProviders\FTP::class,
|
\App\Enums\StorageProvider::FTP => \App\StorageProviders\FTP::class,
|
||||||
\App\Enums\StorageProvider::LOCAL => \App\StorageProviders\Local::class,
|
\App\Enums\StorageProvider::LOCAL => \App\StorageProviders\Local::class,
|
||||||
\App\Enums\StorageProvider::S3 => \App\StorageProviders\S3::class,
|
\App\Enums\StorageProvider::S3 => \App\StorageProviders\S3::class,
|
||||||
\App\Enums\StorageProvider::WASABI => \App\StorageProviders\Wasabi::class,
|
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
'ssl_types' => [
|
'ssl_types' => [
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\StorageProvider;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$wasabiProviders = \App\Models\StorageProvider::query()
|
||||||
|
->where('provider', 'wasabi')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
/** @var \App\Models\StorageProvider $provider */
|
||||||
|
foreach ($wasabiProviders as $provider) {
|
||||||
|
$provider->provider = StorageProvider::S3;
|
||||||
|
$credentials = $provider->credentials;
|
||||||
|
$credentials['api_url'] = "https://{$credentials['bucket']}.s3.{$credentials['region']}.wasabisys.com";
|
||||||
|
$provider->credentials = $credentials;
|
||||||
|
$provider->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
@ -14,21 +14,28 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$this->call([
|
$seeders = [
|
||||||
ProjectsSeeder::class,
|
ProjectsSeeder::class,
|
||||||
UsersSeeder::class,
|
UsersSeeder::class,
|
||||||
TagsSeeder::class,
|
];
|
||||||
ServerProvidersSeeder::class,
|
|
||||||
StorageProvidersSeeder::class,
|
if (config('app.demo')) {
|
||||||
SourceControlsSeeder::class,
|
$seeders = array_merge($seeders, [
|
||||||
NotificationChannelsSeeder::class,
|
TagsSeeder::class,
|
||||||
ServersSeeder::class,
|
ServerProvidersSeeder::class,
|
||||||
SitesSeeder::class,
|
StorageProvidersSeeder::class,
|
||||||
DatabasesSeeder::class,
|
SourceControlsSeeder::class,
|
||||||
CronJobsSeeder::class,
|
NotificationChannelsSeeder::class,
|
||||||
SshKeysSeeder::class,
|
ServersSeeder::class,
|
||||||
MetricsSeeder::class,
|
SitesSeeder::class,
|
||||||
ServerLogsSeeder::class,
|
DatabasesSeeder::class,
|
||||||
]);
|
CronJobsSeeder::class,
|
||||||
|
SshKeysSeeder::class,
|
||||||
|
MetricsSeeder::class,
|
||||||
|
ServerLogsSeeder::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->call($seeders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
public/build/assets/theme-ab462327.css
Normal file
1
public/build/assets/theme-ab462327.css
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"resources/css/filament/app/theme.css": {
|
"resources/css/filament/app/theme.css": {
|
||||||
"file": "assets/theme-d1a47f2d.css",
|
"file": "assets/theme-ab462327.css",
|
||||||
"isEntry": true,
|
"isEntry": true,
|
||||||
"src": "resources/css/filament/app/theme.css"
|
"src": "resources/css/filament/app/theme.css"
|
||||||
},
|
},
|
||||||
|
7
resources/svg/nodejs-alt.svg
Normal file
7
resources/svg/nodejs-alt.svg
Normal 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
2
resources/svg/nodejs.svg
Normal 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 |
5
resources/svg/php-alt.svg
Normal file
5
resources/svg/php-alt.svg
Normal 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 |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 742 B |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 51 KiB |
@ -1,5 +1,5 @@
|
|||||||
<div
|
<div
|
||||||
{{ $attributes->merge(["class" => "font-mono whitespace-pre relative h-[500px] w-full overflow-auto whitespace-pre-line rounded-xl border border-gray-200 bg-black p-5 text-gray-50 dark:border-gray-800"]) }}
|
{{ $attributes->merge(["class" => "font-mono relative h-[500px] w-full overflow-auto whitespace-pre-line rounded-xl border border-gray-200 bg-black p-5 text-gray-50 dark:border-gray-800"]) }}
|
||||||
>
|
>
|
||||||
{{ $slot }}
|
{{ $slot }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,13 +2,48 @@
|
|||||||
x-data="{
|
x-data="{
|
||||||
user: '{{ $server->ssh_user }}',
|
user: '{{ $server->ssh_user }}',
|
||||||
running: false,
|
running: false,
|
||||||
|
dir: '{{ cache()->get("console.$server->id.dir", "~") }}',
|
||||||
command: '',
|
command: '',
|
||||||
output: '',
|
output: '',
|
||||||
|
serverName: '{{ $server->name }}',
|
||||||
|
shellPrefix: '',
|
||||||
|
clearAfterCommand: false,
|
||||||
runUrl: '{{ route("servers.console.run", ["server" => $server]) }}',
|
runUrl: '{{ route("servers.console.run", ["server" => $server]) }}',
|
||||||
|
init() {
|
||||||
|
this.setShellPrefix()
|
||||||
|
$watch('user', async (value) => {
|
||||||
|
await this.getWorkingDir()
|
||||||
|
})
|
||||||
|
const consoleOutput = document.getElementById('console-output')
|
||||||
|
consoleOutput.addEventListener('mouseup', (event) => {
|
||||||
|
if (window.getSelection()?.toString()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.focusCommand()
|
||||||
|
})
|
||||||
|
this.focusCommand()
|
||||||
|
|
||||||
|
document.addEventListener('keydown', (event) => {
|
||||||
|
if (event.ctrlKey && event.key === 'l') {
|
||||||
|
event.preventDefault()
|
||||||
|
if (this.running) return
|
||||||
|
this.output = ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
async run() {
|
async run() {
|
||||||
if (! this.command) return
|
if (! this.command) return
|
||||||
this.running = true
|
this.running = true
|
||||||
this.output = this.command + '\n'
|
let output = this.shellPrefix + ' ' + this.command + '\n'
|
||||||
|
if (this.clearAfterCommand) {
|
||||||
|
this.output = output
|
||||||
|
} else {
|
||||||
|
this.output += output
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('console-output').scrollTop =
|
||||||
|
document.getElementById('console-output').scrollHeight
|
||||||
|
}, 100)
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -25,6 +60,7 @@
|
|||||||
const response = await fetch(this.runUrl, fetchOptions)
|
const response = await fetch(this.runUrl, fetchOptions)
|
||||||
const reader = response.body.getReader()
|
const reader = response.body.getReader()
|
||||||
const decoder = new TextDecoder('utf-8')
|
const decoder = new TextDecoder('utf-8')
|
||||||
|
this.setShellPrefix()
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (! this.running) {
|
if (! this.running) {
|
||||||
@ -39,65 +75,91 @@
|
|||||||
|
|
||||||
this.output += textChunk
|
this.output += textChunk
|
||||||
|
|
||||||
document.getElementById('console-output').scrollTop =
|
setTimeout(() => {
|
||||||
document.getElementById('console-output').scrollHeight
|
document.getElementById('console-output').scrollTop =
|
||||||
|
document.getElementById('console-output').scrollHeight
|
||||||
|
}, 100)
|
||||||
}
|
}
|
||||||
this.output += '\nDone!'
|
this.output += '\n'
|
||||||
|
await this.getWorkingDir()
|
||||||
this.running = false
|
this.running = false
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('command').focus()
|
||||||
|
}, 100)
|
||||||
},
|
},
|
||||||
stop() {
|
stop() {
|
||||||
this.running = false
|
this.running = false
|
||||||
},
|
},
|
||||||
|
setShellPrefix() {
|
||||||
|
this.shellPrefix = `${this.user}@${this.serverName}:${this.dir}$`
|
||||||
|
},
|
||||||
|
focusCommand() {
|
||||||
|
document.getElementById('command').focus()
|
||||||
|
},
|
||||||
|
async getWorkingDir() {
|
||||||
|
const response = await fetch(
|
||||||
|
'{{ route("servers.console.working-dir", ["server" => $server]) }}',
|
||||||
|
)
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json()
|
||||||
|
this.dir = data.dir
|
||||||
|
this.setShellPrefix()
|
||||||
|
}
|
||||||
|
},
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<div>
|
<div class="relative">
|
||||||
<x-console-view id="console-output">
|
<form class="flex items-center justify-between">
|
||||||
<div class="w-full" x-text="output"></div>
|
<x-filament::input.wrapper>
|
||||||
</x-console-view>
|
<x-filament::input.select id="user" name="user" x-model="user" class="w-full" x-bind:disabled="running">
|
||||||
<form onsubmit="return false" id="console-form" class="mt-5 flex items-center justify-between">
|
<option value="root">root</option>
|
||||||
<div class="grid w-full grid-cols-8 gap-2">
|
<option value="{{ $server->ssh_user }}">{{ $server->ssh_user }}</option>
|
||||||
<x-filament::input.wrapper class="col-span-1 w-full">
|
</x-filament::input.select>
|
||||||
<x-filament::input.select
|
</x-filament::input.wrapper>
|
||||||
id="user"
|
<div class="flex items-center">
|
||||||
name="user"
|
|
||||||
x-model="user"
|
|
||||||
class="w-full"
|
|
||||||
x-bind:disabled="running"
|
|
||||||
>
|
|
||||||
<option value="root">root</option>
|
|
||||||
<option value="{{ $server->ssh_user }}">{{ $server->ssh_user }}</option>
|
|
||||||
</x-filament::input.select>
|
|
||||||
</x-filament::input.wrapper>
|
|
||||||
<x-filament::input.wrapper class="col-span-6 w-full">
|
|
||||||
<x-filament::input
|
|
||||||
id="command"
|
|
||||||
name="command"
|
|
||||||
x-model="command"
|
|
||||||
type="text"
|
|
||||||
placeholder="Type your command here..."
|
|
||||||
class="mx-1 flex-grow"
|
|
||||||
autocomplete="off"
|
|
||||||
/>
|
|
||||||
</x-filament::input.wrapper>
|
|
||||||
<x-filament::button
|
<x-filament::button
|
||||||
color="gray"
|
color="gray"
|
||||||
icon="heroicon-o-play"
|
type="button"
|
||||||
type="submit"
|
x-on:click="output = ''"
|
||||||
id="btn-run"
|
icon="heroicon-o-trash"
|
||||||
x-on:click="run"
|
tooltip="Clear"
|
||||||
class="col-span-1"
|
|
||||||
x-show="!running"
|
x-show="!running"
|
||||||
/>
|
>
|
||||||
|
Clear
|
||||||
|
</x-filament::button>
|
||||||
<x-filament::button
|
<x-filament::button
|
||||||
color="gray"
|
color="gray"
|
||||||
type="button"
|
type="button"
|
||||||
id="btn-stop"
|
id="btn-stop"
|
||||||
x-on:click="stop"
|
x-on:click="stop"
|
||||||
class="col-span-1"
|
|
||||||
x-show="running"
|
x-show="running"
|
||||||
icon="heroicon-o-stop"
|
icon="heroicon-o-stop"
|
||||||
/>
|
tooltip="Stop"
|
||||||
|
class="ml-2"
|
||||||
|
>
|
||||||
|
Stop
|
||||||
|
</x-filament::button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<x-console-view id="console-output" class="mt-5">
|
||||||
|
<div class="w-full" x-text="output"></div>
|
||||||
|
</x-console-view>
|
||||||
|
<div
|
||||||
|
class="relative -mt-5 flex h-[50px] w-full items-center rounded-b-xl border-b border-l border-r border-gray-200 bg-black px-5 font-mono text-gray-50 dark:border-gray-800"
|
||||||
|
>
|
||||||
|
<form class="flex w-full items-center" x-show="!running" onsubmit="return false" id="console-form">
|
||||||
|
<div x-text="shellPrefix"></div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="h-5 flex-grow border-0 bg-transparent p-0 px-1 outline-none ring-0 focus:outline-none focus:ring-0"
|
||||||
|
autofocus
|
||||||
|
id="command"
|
||||||
|
name="command"
|
||||||
|
x-model="command"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
<button type="submit" id="btn-run" x-on:click="run" class="hidden"></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
94
tests/Feature/NodeJSTest.php
Normal file
94
tests/Feature/NodeJSTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -318,6 +318,11 @@ public static function installData(): array
|
|||||||
'php',
|
'php',
|
||||||
'7.4',
|
'7.4',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'nodejs',
|
||||||
|
'nodejs',
|
||||||
|
'16',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'supervisor',
|
'supervisor',
|
||||||
'process_manager',
|
'process_manager',
|
||||||
|
@ -52,6 +52,7 @@ public function test_see_providers_list(): void
|
|||||||
{
|
{
|
||||||
$this->actingAs($this->user);
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
|
/** @var StorageProviderModel $provider */
|
||||||
$provider = StorageProviderModel::factory()->create([
|
$provider = StorageProviderModel::factory()->create([
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'provider' => StorageProvider::DROPBOX,
|
'provider' => StorageProvider::DROPBOX,
|
||||||
@ -61,6 +62,7 @@ public function test_see_providers_list(): void
|
|||||||
->assertSuccessful()
|
->assertSuccessful()
|
||||||
->assertSee($provider->profile);
|
->assertSee($provider->profile);
|
||||||
|
|
||||||
|
/** @var StorageProviderModel $provider */
|
||||||
$provider = StorageProviderModel::factory()->create([
|
$provider = StorageProviderModel::factory()->create([
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'provider' => StorageProvider::S3,
|
'provider' => StorageProvider::S3,
|
||||||
@ -70,11 +72,6 @@ public function test_see_providers_list(): void
|
|||||||
->assertSuccessful()
|
->assertSuccessful()
|
||||||
->assertSee($provider->profile);
|
->assertSee($provider->profile);
|
||||||
|
|
||||||
$provider = StorageProviderModel::factory()->create([
|
|
||||||
'user_id' => $this->user->id,
|
|
||||||
'provider' => StorageProvider::WASABI,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->get(Index::getUrl())
|
$this->get(Index::getUrl())
|
||||||
->assertSuccessful()
|
->assertSuccessful()
|
||||||
->assertSee($provider->profile);
|
->assertSee($provider->profile);
|
||||||
|
@ -20,6 +20,7 @@ public function test_s3_connect_successful()
|
|||||||
$storageProvider = StorageProviderModel::factory()->create([
|
$storageProvider = StorageProviderModel::factory()->create([
|
||||||
'provider' => StorageProvider::S3,
|
'provider' => StorageProvider::S3,
|
||||||
'credentials' => [
|
'credentials' => [
|
||||||
|
'api_url' => 'https://fake-bucket.s3.us-east-1.s3-compatible.com',
|
||||||
'key' => 'fake-key',
|
'key' => 'fake-key',
|
||||||
'secret' => 'fake-secret',
|
'secret' => 'fake-secret',
|
||||||
'region' => 'us-east-1',
|
'region' => 'us-east-1',
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\StorageProviders;
|
|
||||||
|
|
||||||
use App\Enums\StorageProvider;
|
|
||||||
use App\Models\StorageProvider as StorageProviderModel;
|
|
||||||
use App\StorageProviders\S3;
|
|
||||||
use App\StorageProviders\Wasabi;
|
|
||||||
use Aws\Command;
|
|
||||||
use Aws\S3\Exception\S3Exception;
|
|
||||||
use Aws\S3\S3Client;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class WasabiTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_wasabi_connect_successful()
|
|
||||||
{
|
|
||||||
$storageProvider = StorageProviderModel::factory()->create([
|
|
||||||
'provider' => StorageProvider::WASABI,
|
|
||||||
'credentials' => [
|
|
||||||
'key' => 'fake-key',
|
|
||||||
'secret' => 'fake-secret',
|
|
||||||
'region' => 'us-east-1',
|
|
||||||
'bucket' => 'fake-bucket',
|
|
||||||
'path' => '/',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Mock the S3Client (Wasabi uses S3-compatible API)
|
|
||||||
$s3ClientMock = $this->getMockBuilder(S3Client::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->onlyMethods(['getCommand', 'execute'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
// Mock the getCommand method
|
|
||||||
$s3ClientMock->expects($this->once())
|
|
||||||
->method('getCommand')
|
|
||||||
->with('listBuckets')
|
|
||||||
->willReturn(new Command('listBuckets'));
|
|
||||||
|
|
||||||
// Mock the execute method
|
|
||||||
$s3ClientMock->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn(['Buckets' => []]);
|
|
||||||
|
|
||||||
// Mock the Wasabi class to return the mocked S3Client
|
|
||||||
$wasabi = $this->getMockBuilder(Wasabi::class)
|
|
||||||
->setConstructorArgs([$storageProvider])
|
|
||||||
->onlyMethods(['getClient'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$wasabi->expects($this->once())
|
|
||||||
->method('getClient')
|
|
||||||
->willReturn($s3ClientMock);
|
|
||||||
|
|
||||||
$this->assertTrue($wasabi->connect());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_wasabi_connect_failure()
|
|
||||||
{
|
|
||||||
$storageProvider = StorageProviderModel::factory()->create([
|
|
||||||
'provider' => StorageProvider::WASABI,
|
|
||||||
'credentials' => [
|
|
||||||
'key' => 'fake-key',
|
|
||||||
'secret' => 'fake-secret',
|
|
||||||
'region' => 'us-east-1',
|
|
||||||
'bucket' => 'fake-bucket',
|
|
||||||
'path' => '/',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Mock the S3Client (Wasabi uses S3-compatible API)
|
|
||||||
$s3ClientMock = $this->getMockBuilder(S3Client::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->onlyMethods(['getCommand', 'execute'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
// Mock the getCommand method
|
|
||||||
$s3ClientMock->expects($this->once())
|
|
||||||
->method('getCommand')
|
|
||||||
->with('listBuckets')
|
|
||||||
->willReturn(new Command('listBuckets'));
|
|
||||||
|
|
||||||
// Mock the execute method to throw an S3Exception
|
|
||||||
$s3ClientMock->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willThrowException(new S3Exception('Error', new Command('ListBuckets')));
|
|
||||||
|
|
||||||
// Mock the Wasabi class to return the mocked S3Client
|
|
||||||
$wasabi = $this->getMockBuilder(Wasabi::class)
|
|
||||||
->setConstructorArgs([$storageProvider])
|
|
||||||
->onlyMethods(['getClient'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$wasabi->expects($this->once())
|
|
||||||
->method('getClient')
|
|
||||||
->willReturn($s3ClientMock);
|
|
||||||
|
|
||||||
$this->assertFalse($wasabi->connect());
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user