innmind/ark

Servers' array management

3.1.0 2021-02-13 16:48 UTC

This package is auto-updated.

Last update: 2024-12-14 01:33:01 UTC


README

Build Status codecov Type Coverage

The ark is a simple tool to spinup new servers and trash the ones in service in your infrastructure.

It works with the Ovh api and uses the vps endpoints or with Scaleway.

Only the installation provided by the ark array can be asked to be disposed.

Ovh implementation detail

Since it's not possible to order new servers via the Ovh api this library rely on the state of your servers.

If a server is stopped it considers that it is available when asking for a new server. When a server is chosen as a new server it will reinstall the server with a template id that you must provide, the only way to connect to the server will be via a ssh key (no password is generated as we couldn't automate the reinstallation).

With ovh disposing a server simply means it will stop the server (allowing it to be considered as available when asking for a new server).

Installation

composer require innmind/ark

Usage

Scaleway

use function Innmind\Ark\scaleway;
use function Innmind\ScalewaySdk\bootstrap as sdk;
use Innmind\OperatingSystem\Factory;
use Innmind\ScalewaySdk\{
    Token,
    Region,
    User,
    Organization,
    Image,
};
use Innmind\SshKeyProvider\Local;
use Innmind\Url\Path;

$os = Factory::build();
$sdk = sdk($os->remote()->http(), $os->clock());
$scaleway = $sdk->autnenticated(new Token\Id('uuid')); // create an api token at https://console.scaleway.com/account/credentials

$ark = scaleway(
    $scaleway->servers(Region::paris1()),
    $scaleway->ips(Region::paris1()),
    $scaleway->users(),
    $os->process(),
    new Local(
        $os->control()->processes(),
        Path::of('/home/{serverUser}/.ssh'),
    ),
    new User\Id('your user uuid'),
    new Organization\Id('the organization uuid you want to create servers in'),
    new Image\Id('the image uuid you want to build'),
);

$installation = $ark->forge()->new();
$installAppOn($installation->location());
$ark->array(); // will contain the new server now

Ovh

The very first step is to buy vps servers from ovh, then you can start writing this kind of code:

use function Innmind\Ark\ovh;
use Innmind\OperatingSystem\Factory;
use Innmind\SshKeyProvider\Local;
use Innmind\Url\Path;
use Ovh\Api;

$os = Factory::build();

$ark = ovh(
    new Api(/* args */),
    new Local(
        $os->control()->processes(),
        Path::of('/home/{serverUser}/.ssh'),
    ),
    $os,
);

$installation = $ark->forge()->new();
$installAppOn($installation->location());
$ark->array(); // will contain the new server now

You can refer to the ovh documentation to know how you can generate the tokens needed to build the Api object.

Important: you need to generate the consumer key yourself as it can't be automated. The library requires the following access rights in order to work properly: POST</me*>, DELETE</me*>, GET</vps*> and POST</vps*>.