abdullahfaqeir / laravel-dynamic-servers-vultr
Vultr provider for Spatie's Laravel Dynamic Servers package
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- sammyjo20/saloon: ^2.0
- sammyjo20/saloon-laravel: ^2.0
- spatie/laravel-dynamic-servers: ^1.0
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-09 05:12:21 UTC
README
This package provides a Server Provider for Spatie's Laravel Dynamic Servers Package.
Installation
You can install the package via composer:
composer require abdullahfaqeir/laravel-dynamic-servers-vultr
Afterward make sure to publish the EventServiceProvider that comes with this package:
php artisan dynamic-servers-vultr:install
Usage
In your config/dynamic-servers.php register the Vulter provider
return [ 'providers' => [ 'vultr' => [ 'class' => AbdullahFaqeir\LaravelDynamicServersVultr\Vultr\VultrServerProvider::class, 'maximum_servers_in_account' => 15, 'options' => [ 'token' => env('VULTR_TOKEN'), 'region' => env('VULTR_REGION'), ], ], ], ];
In your app/Providers/DynamicServersProvider.php register a new server type using the Vultr provider
public function register() { .... $vultrServer = ServerType::new('small') ->provider('vultr') ->configuration(function (Server $server) { return [ 'label' => Str::slug($server->name), "region" => $server->option('region'), 'plan' => 'vc2-1c-1gb', "vpc_uuid" => '62420e18-5628-4f6c-9ee4-aca48a5a7c17', 'os_id' => 1743, 'enable_ipv6' => true, 'backups' => 'disabled', 'tags' => [ 'tag1', 'tag2' ] ]; }); DynamicServers::registerServerType($vultrServer); }
Events
After the base package's CreateServerJob
is executed, a new job, VerifyServerStartedJob
will be dispatched and will
check every 20 seconds to make sure that the provider eventually marks the Instance as running.
After it ensures it runs, no other attempt is made to fetch again the server meta.
Considering that Vultr will return the ip address of a instance only after it has been full created we need to fetch once more the instance meta.
For this, we will use the base package's event 'ServerRunningEvent'.
This package, publishes a App\Providers\VultrEventServiceProvider
in your project.
By default there is a single listener, configured and it will fetch again the Instance's meta after the base package has ensured that it is running.
protected $listen = [ ServerRunningEvent::class => [ UpdateServerMeta::class, ], ];
You may customise the listener, disable it or replace it with a your own.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.