npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@firstandthird/dockercloud

v0.4.1

Published

Node.js library for Docker Cloud API

Downloads

4

Readme

Dockercloud

Circle CI

Node.js library for Docker Cloud API

Installation

npm install @firstandthird/dockercloud

Usage

Initilization

To use this class firstly you need to instantiate a new instance:

import DockerCloud from 'dockercloud'

const dockerCloud = new DockerCloud('username', 'password', 'namespace')

Methods

All methods return promises.

connect

Connect to DockerCloud and listen for events. This method is required to be called before using the waitUntil* methods.

Example:

await dockerCloud.connect()
const stack = await dockerCloud.findStackById('stackId')
await dockerCloud.waitUntilStackIsTerminated(stack)

disconnect

Disconnect from DockerCloud. This method returns nothing.

queryStacks

The value returned by the promise will be a list of the stacks in your account.

const stacks = await dockerCloud.queryStacks()

findStackById

The value returned by the promise will be the stack with the id passed.

try {
  const stack = await dockerCloud.findStackById('stackId')
  // Do something with the stack
} catch (error) {
  // If the error is empty the stack isn't found (404)
}

findStackByName

Same as findStackById, but if the stack isn't found instead of rejection the promise resolves returning nothing

createStack

Create a new stack

await dockerCloud.createStack({
  name: 'human readable name',
  nickname: 'optional nickname',
  services: [{
    "name": "hello-word",
    "image": "tutum/hello-world",
    "target_num_containers": 2
  }]
})

removeStack

Remove a stack; the parameter is the stack object.

const stack = await dockerCloud.findStackById('uuid')
dockerCloud.removeStack(stack)

startStack

Start a stack; the parameter is the stack object.

const stack = await dockerCloud.findStackById('uuid')
dockerCloud.startStack(stack)

getStackServices

Get the services connected to a stack; the parameter is the stack object.

const stack = await dockerCloud.findStackById('uuid')
const services = dockerCloud.getStackServices(stack)

waitUntilStackIsTerminated

Wait until a stack is terminated

await dockerCloud.connect()
const stack = await dockerCloud.findStackById('stackId')
await dockerCloud.waitUntilStackIsTerminated(stack)

waitUntilStackIsRunning

Wait until a stack is running

await dockerCloud.connect()
const stack = await dockerCloud.findStackById('stackId')
await dockerCloud.waitUntilStackIsRunning(stack)

findServiceById

The value returned by the promise will be the service with the id passed.

try {
  const stack = await dockerCloud.findServiceById('serviceId')
} catch (error) {
  // If the error is empty the service isn't found (404)
}

findServiceByName

Same as findServiceById, but if the service isn't found instead of rejection the promise resolves returning nothing

createService

Create a new service

await dockerCloud.createService({
  image: "tutum/hello-world",
  name: "Optional name",
  target_num_containers: 2, // Optional, default 1
  run_command: "/run.sh", // Optional, The command used to start the containers of this service, overriding the value specified in the image. (default: null)
  entrypoint: "/usr/sbin/sshd", // Optional, The command prefix used to start the containers of this service, overriding the value specified in the image. (default: null)
  container_ports: [{ // Optional, An array of objects with port information to be published in the containers for this service, which will be added to the image port information. (default: [])
    protocol: "tcp",
    inner_port: 80,
    outer_port: 80,
    published: false
  }],
  container_envvars: [{ // Optional, An array of objects with environment variables to be added in the service containers on launch (overriding any image-defined environment variables). (default: [])
    key: "DB_PASSWORD",
    value: "mypass"
  }],
  linked_to_service: [{ // Optional, An array of service resource URIs to link this service to, including the link name. (default: [])
    to_service: "/api/app/v1/service/80ff1635-2d56-478d-a97f-9b59c720e513/",
    name: "db"
  }],
  bindings: [{ // Optional, An array of bindings this service has to mount. (default: [])
    volumes_from: "/api/app/v1/service/80ff1635-2d56-478d-a97f-9b59c720e513/",
    container_path: "",
    rewritable: true,
    host_path: ""
  }],
  autorestart: "OFF", // Optional,  Whether the containers for this service should be restarted if they stop, i.e. ALWAYS (default: OFF, possible values: OFF, ON_FAILURE, ALWAYS)
  autodestroy: "OFF", // Optional, Whether the containers should be terminated if they stop, i.e. OFF (default: OFF, possible values: OFF, ON_SUCCESS, ALWAYS)
  sequential_deployment: false, // Optional, Whether the containers should be launched and scaled in sequence. (default: false)
  roles: ["global"], // Optional, A list of Docker Cloud API roles to grant the service
  privileged: false, // Optional, Whether to start the containers with Docker’s privileged flag set or not
  deployment_strategy: "EMPTIEST_NODE", // Optional, Container distribution among nodes
  tags: ["tag1","tag2"],
  autoredeploy: false, // Optional,  Whether to redeploy the containers of the service when its image is updated in Docker Cloud registry. (default: false)
  net: "bridge", // Optional, possible values: bridge, host
  pid: "host", // Optional, Set the PID (Process) Namespace mode for the containers. (default: none)
  working_dir: "/var/app/", // Optional, Working directory for running binaries within a container of this service. (default: /)
  nickname: "Optional nickname"
})

removeService

Remove a service; the parameter is the service object.

const service = await dockerCloud.findServiceById('uuid')
dockerCloud.removeService(service)

startService

Start a service; the parameter is the service object.

const service = await dockerCloud.findServiceById('uuid')
dockerCloud.startService(service)

redeployService

Redeploy a service; the parameter is the service object.

const service = await dockerCloud.findServiceById('uuid')
dockerCloud.redeployService(service)

getServiceContainers

Get the containers connected to a service; the parameter is the service object.

const service = await dockerCloud.findServiceById('uuid')
const containers = dockerCloud.getServiceContainers(service)

findContainerById

The value returned by the promise will be the container with the id passed.

try {
  const stack = await dockerCloud.findContainerById('containerId')
} catch (error) {
  // If the error is empty the container isn't found (404)
}

waitUntilContainerIsStopped

Wait until a container is stopped

await dockerCloud.connect()
const container = await dockerCloud.findContainerById('containerId')
await dockerCloud.waitUntilContainerIsStopped(container)

findActionById

The value returned by the promise will be the action with the id passed.

try {
  const stack = await dockerCloud.findActionById('actionId')
} catch (error) {
  // If the error is empty the action isn't found (404)
}

waitUntilActionIsSuccess

Wait until an action is successful

await dockerCloud.connect()
const action = await dockerCloud.findActionById('actionId')
await dockerCloud.waitUntilActionIsSuccess(action)

extractUuid

Extract the UUID from an URL

const uuuid = dockerCloud.extractUuid('/api/app/v1/action/7c42003e-eb39-4adc-b5b9-cbb7607fc698/')
uuuid === '7c42003e-eb39-4adc-b5b9-cbb7607fc698'