abdullahfaqeir/laravel-dynamic-servers-vultr

Vultr provider for Spatie's Laravel Dynamic Servers package

1.0.0 2023-03-22 14:39 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.