Skip to content

chipsoffury/fly_io_dart_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

High-level API for interacting with the Fly.io API

Initialization

Construct a new Fly.io client by calling FlyMachinesRestClient with your Fly.io API token:

var flyClient = FlyMachinesRestClient(FLY_AUTH_TOKEN);

Usage

Here is a simple usage example:

var flyClient = FlyMachinesRestClient(env['FLY_AUTH_TOKEN']!);
var machines = await flyClient.listMachines('cof-health-test');

for (final machine in machines) {
    print('machine = ${m.id}, '
          'state = ${m.state}, '
          'image = ${m.config.image}');
}

var createMachineRequest = 

You can create, list, update, and delete Fly.io resources, namely - applications and machines:

var appName = 'test-app';
var serverPort = '8080';
var created = await flyClient.createApplication();

if (created) {
    var createMachineRequest = CreateMachineRequest(
        machineName,
        MachineConfig(
            image: gameServerImage.image,
            size: MachineSize.shared_cpu_2x,
            env: {
                'SERVER_PORT': serverPort,
                'JWT_SECRET': 'some-secret',
            },
            services: [
                MachineService(
                    ServiceProtocol.tcp,
                    serverPort,
                    [
                      MachineServicePort(
                        443,
                        [MachineServiceConnectionHandler.tls, MachineServiceConnectionHandler.http],
                      ),
                    ],
                    concurrency: MachineServiceConcurrency(MachineServiceConcurrencyType.connections, 50, 100),
                    checks: [
                      MachineCheck(
                        grace_period: '3s',
                        interval: '10s',
                        timeout: '2s',
                        method: 'get',
                        path: '/internal/health',
                        protocol: 'http',
                        type: MachineCheckType.http,
                        port: serverPort,
                      ),
                    ],
                ),
            ],
        ),
        region: FlyRegion.ewr,
    );

    try {
        var machineInfo = await flyMachinesRestClient.createMachine(
          'test-app',
          createMachineRequest,
        );
        return machineInfo;
    } catch (e) {
        print('error here: $e');
        rethrow;
    }
}

You can wait for the machine to enter a specific state, as well:

var machineId = await flyMachinesRestClient.waitForMachineStatus(
    'app-name',
    'machine-id',
    FlyMachineStatus.started,
    timeoutSeconds: 20,
);

Prometheus Metrics

You can also retrieve metrics from your Fly.io application using the FlyMetricsRestClient:

var flyMetricsClient = FlyMetricsRestClientProvider.get(env['FLY_AUTH_TOKEN']!);
var metrics = await flyMetricsClient.getCpuMemUsage('app-name');

print(metrics);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages