Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Simple Use Case Scenario

Farshid Tavakolizadeh edited this page Feb 25, 2019 · 3 revisions

This page demonstrates the usage of Deployment Manager's API to perform a simple deployment on a target device.

1. List Targets

GET http://localhost:8080/targets

{
  "total": 1,
  "items": [
    {
      "id": "my-laptop",
      "tags": [
        "dev",
        "macOS",
        "amd64"
      ],
      "updatedAt": 1551102080782
    }
  ],
  "page": 1,
  "perPage": 100
}

The above response consists of one target only. This means that there is only one target registered to the manager. We can address this device by it's name my-laptop or by one of the tags dev macOS amd64.

2. Make a deployment order

We would like to deploy a Go file along with some configuration files, build it on the target itself, and then execute it.

The source files are:

  • ./package/count_to_three.go
  • ./package/config.json

Since these files are available on the same server that the manager is running, we can simply provide the path to the files relative to the manager's execution directory. If the files were located elsewhere, we had to compress them in Zip format and pass them as a Base64 encoded string.

The API supports both YAML and JSON formats. Here, we write and submit YAML:

POST http://localhost:8080/orders

source:
  paths: # we provide the path to the whole directory (for convenience)
    - package
  #zip: <base64-string>

deploy:
  install:
    commands: # build the file
      - go build package/count_to_three.go

  run:
    commands: # execute it
      - ./count_to_three

  target:
    ids:
    tags: # target the device using the dev tag
      - dev

# status info is sent all the time, but we need all the logs
debug: true

The response is:

{
   "id":"d0b734f2-b388-4a49-883b-e5753b597888",
   "debug":true,
   "createdAt":1551104013971,
   "build":null,
   "deploy":{
      "install":{
         "commands":[
            "go build package/count_to_three.go"
         ]
      },
      "run":{
         "commands":[
            "./count_to_three"
         ],
         "autoRestart":false
      },
      "target":{
         "ids":null,
         "tags":[
            "dev"
         ]
      },
      "match":{
         "ids":null,
         "tags":[
            "dev"
         ],
         "list":[
            "my-laptop"
         ]
      }
   }
}

We get the order ID and see that the order has matched our target: my-laptop

Following the successful submission, the manager compresses the source files, sends the to the target, and executes the deployment commands.

3. See logs

GET http://localhost:8080/logs?task=d0b734f2-b388-4a49-883b-e5753b597888

{
  "total": 22,
  "items": [
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$manager",
      "output": "STAGE-START",
      "time": 1551104014029,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$manager",
      "output": "compressed to 573 bytes",
      "time": 1551104014122,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$manager",
      "output": "sent announcement",
      "time": 1551104014153,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$agent",
      "output": "STAGE-START",
      "time": 1551104014156,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$agent",
      "output": "received announcement",
      "time": 1551104014156,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$agent",
      "output": "subscribed to task",
      "time": 1551104014157,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$manager",
      "output": "sent task",
      "time": 1551104015175,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$agent",
      "output": "received task and unsubscribed",
      "time": 1551104015179,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$agent",
      "output": "decompressed archive of 573 bytes",
      "time": 1551104015182,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$agent",
      "output": "STAGE-END",
      "time": 1551104015182,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "install",
      "command": "$agent",
      "output": "STAGE-START",
      "time": 1551104015182,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "install",
      "command": "go build package/count_to_three.go",
      "output": "EXEC-START",
      "time": 1551104015182,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "install",
      "command": "go build package/count_to_three.go",
      "output": "EXEC-END",
      "time": 1551104015596,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "install",
      "command": "$agent",
      "output": "STAGE-END",
      "time": 1551104015596,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "$agent",
      "output": "STAGE-START",
      "time": 1551104015598,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "./count_to_three",
      "output": "EXEC-START",
      "time": 1551104015598,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "./count_to_three",
      "output": "hello 1",
      "time": 1551104015610,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "./count_to_three",
      "output": "hello 2",
      "time": 1551104016610,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "./count_to_three",
      "output": "hello 3",
      "time": 1551104017612,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "./count_to_three",
      "output": "EXEC-END",
      "time": 1551104018618,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "run",
      "command": "$agent",
      "output": "STAGE-END",
      "time": 1551104018618,
      "target": "my-laptop"
    },
    {
      "task": "d0b734f2-b388-4a49-883b-e5753b597888",
      "stage": "transfer",
      "command": "$manager",
      "output": "STAGE-END",
      "time": 1551104025274,
      "target": "my-laptop"
    }
  ],
  "page": 1,
  "perPage": 100
}