mex-docs

Deploy Docker to MEX Using the API

API Flow

  1. Build the Docker Image
  2. Push the Image to the MobiledgeX Docker Repository
  3. Login and get bearer token
  4. Create an App
  5. Create a Cluster
  6. Create an App Instance
  7. Retrieve connect information for the created App Instance

Prerequisites:

Build the Docker Container

Download the Code:

Build the Docker Image

Push to MeX Docker Repository

Login / Retrieve Token

Request

$ curl -s -XPOST https://console.mobiledgex.net/api/v1/login \
 -H "Content-Type: application/json" \
 -d '{ "password": "somepass", "username": "demo" }'

Response

{"token":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODYyOTcxNTMsImlhdCI6MTU4NjIxMDc1MywidXNlcm5hbWUiOiJkZW1vIiwiZW1haWwiOiJkZW1vQG1vYmlsZWRnZXguY29tIiwia2lkIjoyfQ.bAqdwNw2stM0r24nrbu08c7qbZjraOGoTLVCopYvsIoX1uxKoEeOm8i78ihp8Tze9gKxttLTx76hKYS6tKo0sA"}

Notes

All subsequent calls are shown with two assumptions:

  1. You are using resty and have it configured properly with a base url of https://console.mobiledgex.net/api/v1
  2. You have a .curlrc file setup with the following values:
    1. -H "Content-Type: application/json"
    2. -H "Authorization: Bearer <JWT Token>"

For 2xx responses, the body of the response will be printed to stdout. For all other responses the body will be dumped to stderr.

Create an App

Request

POST /auth/ctrl/CreateApp < payload.json

payload.json

{
"Region": "EU",
"App": {
  "key": {
    "developer_key" : {
      "name": "demoorg"
    },
    "name": "testapp",
    "organization": "demoorg",
    "version": "1.0"
  },
  "deployment": "docker",
  "access_type": 0,
  "image_path": "docker.mobiledgex.net/demoorg/images/test:1.0",
  "image_type": 1,
  "internal_ports": true,
  "default_flavor": {
    "name": "m4.small"
  },
  "revision": 0,
  "access_ports": "TCP:8000"
}
}

Response

{

}

Create a Cluster

Request

POST api/v1/auth/ctrl/CreateClusterInst < payload.json

payload.json

{
  "Region": "EU",
  "ClusterInst": {
    "allocated_ip": "dynamic",
    "ip_access": 1,
    "key": {
      "cloudlet_key": {
        "operator_key": {
          "name": "TDG"
        },
        "developer_key" : {
    "name": "demoorg"
      },

        "name": "munich-main"
      },
      "organization": "string",
      "cluster_key": {
        "name": "testcluster"
      }
    },
    "node_flavor": "m4.small",
    "deployment": "docker"
  }
}

Response

{"data":{"message":"Creating"}}
{"data":{"message":"Creating Dedicated VM for Docker"}}
{"data":{"message":"Creating Heat Stack for munich-main-testcluster-demoorg"}}
{"data":{"message":"Creating Heat Stack for munich-main-testcluster-demoorg, Heat Stack Status: CREATE_IN_PROGRESS"}}
{"data":{"message":"Setting Up Root LB"}}
{"data":{"message":"Ready"}}
{"data":{"message":"Created ClusterInst successfully"}}

Deploy an App Instance

Request

POST api/v1/auth/ctrl/CreateAppInst < payload.json

payload.json

{
  "Region": "EU",
  "AppInst": {
    "key": {
      "app_key": {
        "organization": "demoorg",
        "name": "testapp",
        "version": "1.0",
        "developer_key": {
          "name": "demoorg"
        }
      },
      "cluster_inst_key": {
        "cluster_key": {
          "name": "testcluster"
        },
        "cloudlet_key": {
          "operator_key": {
            "name": "TDG"
          },
          "name": "munich-main"
        },
        "developer": "demoorg"
      }
    },
    "flavor": {
      "name": "m4.small"
    }
  }
}

Response

  {"data":{"message":"Seeding docker secret"}}
  {"data":{"message":"Deploying Docker App"}}
  {"data":{"message":"Configuring Firewall Rules and DNS"}}
  {"data":{"message":"Creating"}}
  {"data":{"message":"Ready"}}
  {"data":{"message":"Created AppInst successfully"}}  

Test Your Application

Get FQDN and Port; payload content is used to filter (note that this is not currently working - see EDGECLOUD-2412).

Request

POST /auth/ctrl/ShowAppInst \
  '{"region": "EU", "appinst": { "key": { "app_key": {"name": "testapp", "version": "1.0" }}}}' \
  | json -Hag data.key.app_key.name data.key.app_key.version data.uri data.mapped_ports

Response

testapp 1.0 testcluster.munich-main.tdg.mobiledgex.net [
  {
    "proto": 1,
    "internal_port": 8000,
    "public_port": 8000
  }
]

Test

$ curl testcluster.munich-main.tdg.mobiledgex.net:8000

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Lobster|Saira+Condensed&display=swap" rel="stylesheet">
    <title>Hello World!</title>
    <style>
      body {
        margin: 0;
      }

      .center-me {
        display: flex;
        justify-content: center;
        align-items: center;
        /*font-family: 'Saira Condensed', sans-serif;*/
		font-family: 'Lobster', cursive;
        font-size: 100px;
        height: 100vh;
      }
    </style>
  </head>
  <body>

    <div class="center-me">
      <p>Hello World! 🥳</p>
    </div>

  </body>
</html>%