Aller au contenu

omniplay/docker Référence de l’API

Étage
Fournisseur · Omniplay
Version
1.x
Suite de conformité
non branchée
Vérifié en réel
Vérifié en partie
Licence
MIT
composer require omniplay/docker:1.x-dev

Lue dans les fichiers PHP du paquet au commit f8a7c20c4dde : ses espaces de noms, classes, interfaces et énumérations, leurs constantes, propriétés et méthodes publiques avec leur PHPDoc, et les options que prennent ses fabriques. Rien n’en est exécuté.

Omniplay\Docker

  • DockerFactory class

    "docker": options services (by service name: image, port, env, command, address, network, labels, host_port, memory, cpus - see Template), host ("unix:///var/run/docker.sock", "tcp://10.0.0.5:2375", "https://10.0.0.5:2376"), api_version ("v1.44"), public_host (where players reach the published ports), region ("local"), secret_env ("OMNIPLAY_TICKET_SECRET"), name_prefix ("omniplay-"), auto_remove (true), stop_timeout (10 seconds), tls (the HTTP client's cafile, local_cert, local_pk for a TLS engine), heartbeat_url (the application's heartbeat route, handed to each server as OMNIPLAY_HEARTBEAT_URL), user_agent.

    12 options · 1 method

  • DockerHosting class

    Game servers as containers of a Docker Engine, through its HTTP API: a server is created from its service's template (POST /containers/create), started, and inspected for the host port Docker published; it is stopped (and removed, unless Docker removes it itself) by its container's id.

    7 methods · 1 constant

  • Template class

    What a server of one service runs, as the configuration gives it: the image, the port the server listens on inside its container ("7777/udp"), its command, its environment, the address players are given ("{host}" the provider's public host, "{port}" the port Docker published), and what Docker limits it to.

    2 methods · 10 properties

Omniplay\Docker

DockerFactory class

final class DockerFactory extends ProviderFactory DockerFactory.php:24

"docker": options services (by service name: image, port, env, command, address, network, labels, host_port, memory, cpus - see Template), host ("unix:///var/run/docker.sock", "tcp://10.0.0.5:2375", "https://10.0.0.5:2376"), api_version ("v1.44"), public_host (where players reach the published ports), region ("local"), secret_env ("OMNIPLAY_TICKET_SECRET"), name_prefix ("omniplay-"), auto_remove (true), stop_timeout (10 seconds), tls (the HTTP client's cafile, local_cert, local_pk for a TLS engine), heartbeat_url (the application's heartbeat route, handed to each server as OMNIPLAY_HEARTBEAT_URL), user_agent.

Options

OptionDefault
services[]required
host'unix:///var/run/docker.sock'
api_version'v1.44'
public_host'127.0.0.1'
region'local'
secret_env'OMNIPLAY_TICKET_SECRET'
name_prefix'omniplay-'
auto_removetrue
stop_timeout10
tls[]
heartbeat_urlnull
user_agent'omniplay/1.0 (+https://github.com/glitchr-omnisense/omniplay)'

DockerFactory::__construct()

public function __construct(readonly ?HttpClientInterface $http = null)

DockerHosting class

final class DockerHosting implements ProviderInterface, HostingInterface DockerHosting.php:34

Game servers as containers of a Docker Engine, through its HTTP API: a server is created from its service's template (POST /containers/create), started, and inspected for the host port Docker published; it is stopped (and removed, unless Docker removes it itself) by its container's id.

The server's environment holds its ticket secret (OMNIPLAY_TICKET_SECRET unless configured otherwise), its id - which is its tickets' room - (OMNIPLAY_SERVER_ID, OMNIPLAY_ROOM), its service, capacity, port, declared engine and the application's heartbeat route (OMNIPLAY_HEARTBEAT_URL, when configured). The secret goes into the container and nowhere else: not into the Server returned, not into its labels. Whoever can read the engine's API (docker inspect) reads it: the engine's socket is root's.

Its labels (omniplay.server, .service, .capacity, .region, .tags, .engine, .port) are what running() rebuilds the servers from.

const LABEL = 'omniplay.'

DockerHosting::__construct()

public function __construct(readonly JsonClient $json, readonly string $base, readonly array $templates, readonly string $publicHost = '127.0.0.1', readonly string $region = 'local', readonly string $secretEnv = 'OMNIPLAY_TICKET_SECRET', readonly string $prefix = 'omniplay-', readonly bool $autoRemove = true, readonly int $stopTimeout = 10, readonly array $options = [], readonly string $where = 'a Docker Engine', readonly ?string $heartbeatUrl = null)
$templates

by service

$options

the HTTP client's, on every call (a unix socket's "bindto")

DockerHosting::getName()

public function getName(): string

DockerHosting::getTitle()

public function getTitle(): string

DockerHosting::capabilities()

public function capabilities(): Capabilities

DockerHosting::start()

public function start(Service $service, string $secret, ?string $region = null, array $tags = []): Server

DockerHosting::stop()

public function stop(Server $server): void

DockerHosting::running()

public function running(?string $service = null): array

Template class

final readonly class Template Template.php:14

What a server of one service runs, as the configuration gives it: the image, the port the server listens on inside its container ("7777/udp"), its command, its environment, the address players are given ("{host}" the provider's public host, "{port}" the port Docker published), and what Docker limits it to.

public string $image
public string $port
public array $env

the server's own variables (omniplay's are set after them)

public ?array $command

the image's command when null

public string $address
public ?string $network
public array $labels

besides omniplay's

public ?int $hostPort

the host port to publish on (one server at a time); any free one when null

public ?int $memory

bytes

public ?float $cpus

Template::__construct()

public function __construct(public string $image, public string $port = '7777/udp', public array $env = [], public ?array $command = null, public string $address = '{host}:{port}', public ?string $network = null, public array $labels = [], public ?int $hostPort = null, public ?int $memory = null, public ?float $cpus = null)
$env

the server's own variables (omniplay's are set after them)

$command

the image's command when null

$labels

besides omniplay's

$hostPort

the host port to publish on (one server at a time); any free one when null

$memory

bytes

Template::fromArray()

public static function fromArray(string $service, array $values): self

A service's entry of the "services" option.