1.3.1 • Published 7 years ago

cl-host-app-api v1.3.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

Host App Client

Client library for interacting with Host App Api. For use in dashboard browser/mobile app.

Terminology

Host

Host is a container with a dedicated IP address. Each user can have multiple containers. Containers have different sizes (cpu, mem, disk).

Host Application

Host Application provides user interface for project management and monitoring of host resources (cpu, mem, disk).

Project

Project is a cluster of services (Docker containers) linked together in an isolated network. Each project must have it's unique slug name. Slug is a value at least 3 characters long and can only contain -[a-z0-9] (for example my-project-1).

Project Service

Project service is a docker container running a specific image (for example node:4, or mysql, etc.). Each service can have defined specific configuration (for example {"rootPassword": "test1234", "defaultDatabase": "test"}) and port forwarding (host port to container port). Multiple ports can be assigned to each service but no two services can share the same source port (host port).

Usage

Local dev

For local development use DummyHostAppClient to simulate real client behaviour without running entire infrastructure.

Basic usage

/*
  NOTE: `HostAppApi` is for example showcase only and should be replaced with relative path or else 
*/
import { DummyHostAppClient } from 'HostAppApi'
import {
  Project,
  createProjectSlug,
  createProjectName,
  createServiceCode,
  createNetworkPort,
  ClientEvents,
  ProjectState
} from 'HostAppApi'

const client = new DummyHostAppClient()

client.on(ClientEvents.ProjectAdded, project => {
  console.log('project added', project)
})

client.on(ClientEvents.ProjectUpdated, project => {
  console.log('project updated', project)
})

client.on(ClientEvents.ProjectRemoved, project => {
  console.log('project removed', project)
})

const testProject1 = {
  slug: createProjectSlug('project-1'),
  name: createProjectName('Test Project 1'),
  services: [
    {
      service: createServiceCode('node:4'),
      base: true,
      ports: [
        {
          source: createNetworkPort(2000),
          destination: createNetworkPort(3000)
        }
      ]
    } 
  ]
}

client.createProject(testProject1)

testProject1.name = createProjectName('Test Project 1 Updated')
client.updateProject(testProject1)

client.startProject(testProject1)
client.stopProject(testProject1)

client.deleteProject(testProject1)

Dummy Client specific methods

Call these methods for local tests

  • initTestData - Auto generates predefined projects (to simulate existing projects on real host)
  • startSysUsageGenerator - Starts hardware usage events simulation (cpu, mem, disk usage events)
  • endSysUsageGenerator - Stops hardware usage events simulation. Use this method to clear interval timer (needed to finish tests, etc., use in afterAll method for example)

For example

client.initTestData()
client.startSysUsageGenerator()
1.3.1

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago