API inconsistent with UI?

Hello people,

I am playing a bit with the rancher api to do continuous deployment and I got to the point where I can deploy an app but it looks like the api is not working as documented in http://docs.rancher.com/rancher/api/api-resources/environment/ for the upgrade action, more clearly in the Output part it says: An updated copy of the environment resource

I have created this small example:

{
    "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: busybox\r\n  stdin_open: true\r\n",
    "name": "myapp",
    "rancherCompose": "busybox:\r\n  scale: 1\r\n",
    "startOnCreate": true,
    "type": "environment"
}

If I am understanding the documentation well, the output of a POST to /environments/<id>?action=upgrade with the following body

{
    "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: nginx:1.7.7\r\n  stdin_open: true\r\n",
    "rancherCompose": "busybox:\r\n  scale: 1\r\n"
}

Should return

{
  "id": "1e5",
( snip )
  "name": "myapp",
  "state": "upgrading",
  "accountId": "1a5",
  "created": "2016-03-24T17:55:27Z",
  "createdTS": 1458842127000,
  "description": null,
  "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: nginx:1.7.7\r\n  stdin_open: true\r\n",
( snip )
  "transitioningMessage": "In Progress",
  "transitioningProgress": null,
  "uuid": "321f460e-de6f-4645-9190-33fe8fe300dd"
}

But it is returning:

{
  "id": "1e5",
( snip )
  "name": "myapp",
  "state": "upgrading",
  "accountId": "1a5",
  "created": "2016-03-24T17:55:27Z",
  "createdTS": 1458842127000,
  "description": null,
  "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: busybox\r\n  stdin_open: true\r\n",
( snip )
  "transitioningMessage": "In Progress",
  "transitioningProgress": null,
  "uuid": "321f460e-de6f-4645-9190-33fe8fe300dd"
}

Even after doing the action=finishupgrade and then doing GET /v1/environments?name=myapp it shows the docker-compose field not updated with the new payload.

{
  "type": "collection",
  "resourceType": "environment",
  "links": {
    "self": "http://172.19.8.20:8081/v1/environments"
  },
  "createTypes": {},
  "actions": {},
  "data": [
    {
      "id": "1e5",
      "type": "environment",
      "links": {
        "self": "http://172.19.8.20:8081/v1/environments/1e5",
        "account": "http://172.19.8.20:8081/v1/environments/1e5/account",
        "services": "http://172.19.8.20:8081/v1/environments/1e5/services",
        "composeConfig": "http://172.19.8.20:8081/v1/environments/1e5/composeconfig"
      },
      "actions": {
        "upgrade": "http://172.19.8.20:8081/v1/environments/1e5/?action=upgrade",
        "update": "http://172.19.8.20:8081/v1/environments/1e5/?action=update",
        "remove": "http://172.19.8.20:8081/v1/environments/1e5/?action=remove",
        "addoutputs": "http://172.19.8.20:8081/v1/environments/1e5/?action=addoutputs",
        "activateservices": "http://172.19.8.20:8081/v1/environments/1e5/?action=activateservices",
        "deactivateservices": "http://172.19.8.20:8081/v1/environments/1e5/?action=deactivateservices",
        "exportconfig": "http://172.19.8.20:8081/v1/environments/1e5/?action=exportconfig"
      },
      "name": "myapp",
      "state": "active",
      "accountId": "1a5",
      "created": "2016-03-24T17:55:27Z",
      "createdTS": 1458842127000,
      "description": null,
      "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: busybox\r\n  stdin_open: true\r\n",
      "environment": null,
      "externalId": "",
      "healthState": "healthy",
      "kind": "environment",
      "outputs": null,
      "previousExternalId": null,
      "rancherCompose": "busybox:\r\n  scale: 1\r\n",
      "removed": null,
      "startOnCreate": true,
      "transitioning": "no",
      "transitioningMessage": null,
      "transitioningProgress": null,
      "uuid": "321f460e-de6f-4645-9190-33fe8fe300dd"
    }
  ],
  "sortLinks": {
    "accountId": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=accountId",
    "created": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=created",
    "description": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=description",
    "externalId": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=externalId",
    "healthState": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=healthState",
    "id": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=id",
    "kind": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=kind",
    "name": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=name",
    "removeTime": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=removeTime",
    "removed": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=removed",
    "state": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=state",
    "uuid": "http://172.19.8.20:8081/v1/environments?name=myapp&sort=uuid"
  },
  "pagination": {
    "first": null,
    "previous": null,
    "next": null,
    "limit": 100,
    "total": null,
    "partial": false
  },
  "sort": null,
  "filters": {
    "accountId": null,
    "created": null,
    "description": null,
    "externalId": null,
    "healthState": null,
    "id": null,
    "kind": null,
    "name": [
      {
        "modifier": "eq",
        "value": "myapp"
      }
    ],
    "removeTime": null,
    "removed": null,
    "state": null,
    "uuid": null
  },
  "createDefaults": {}
}

But here is the oddest part, the UI shows it updated:

Any idea of what am I doing wrong?

You’re not doing anything wrong, this is just a bug that the {docker,rancher}Compose fields aren’t updated on upgrade. The UI is looking at the actual services resources which are created as a result of the upgrade, it doesn’t parse and interpret YAML. Or that they exist t all… I don’t think anything we do actually reads those fields after the stack (environment) is created. The live config is in the environment.links.composeConfig

Is there a github tracking this bug that you can link me to? should I open one?

Please [& thanks] open an issue.

I’m guessing we’ll probably just hide those fields. It’s already available in the composeConfig link (as a ZIP) or in the result of the exportconfig action (POST ${environment.links.exportconfig}) so you can use either one of those if you need the current YAML for a stack/environment.

I think (from my tests) both composeConfig and POST ${environment.links.exportconfig} return a zip file, it would be very helpful if one of those returned a string with the docker-compose yaml because otherwise if I want to use those two programatically I would have to use a zip library to store the zip in memory, unzip it, probably keep a temporary file on disk and so on and so forth.

The exportconfig action returns a JSON object with the 2 strings in it. It’s used for the YAML display in the UI.

Awesome, that will do < strike that

versus

http GET http://172.19.8.20:8081/v1/environments/1e5/?action=exportconfig
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 602
Content-Type: application/json; charset=utf-8
Date: Thu, 24 Mar 2016 19:22:56 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: Jetty(9.2.11.v20150529)
Set-Cookie: PL=rancher;Path=/
Vary: Accept-Encoding, User-Agent
X-Api-Account-Id: 1a1
X-Api-Client-Ip: 172.19.8.1
X-Api-Schemas: http://172.19.8.20:8081/v1/schemas

{
    "accountId": "1a5",
    "actions": {
        "activateservices": "http://172.19.8.20:8081/v1/environments/1e5/?action=activateservices",
        "addoutputs": "http://172.19.8.20:8081/v1/environments/1e5/?action=addoutputs",
        "deactivateservices": "http://172.19.8.20:8081/v1/environments/1e5/?action=deactivateservices",
        "exportconfig": "http://172.19.8.20:8081/v1/environments/1e5/?action=exportconfig",
        "remove": "http://172.19.8.20:8081/v1/environments/1e5/?action=remove",
        "update": "http://172.19.8.20:8081/v1/environments/1e5/?action=update",
        "upgrade": "http://172.19.8.20:8081/v1/environments/1e5/?action=upgrade"
    },
    "created": "2016-03-24T17:55:27Z",
    "createdTS": 1458842127000,
    "data": {
        "fields": {
            "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: busybox\r\n  stdin_open: true\r\n",
            "previousExternalId": null,
            "rancherCompose": "busybox:\r\n  scale: 1\r\n",
            "startOnCreate": true
        }
    },
    "description": null,
    "dockerCompose": "busybox:\r\n  labels:\r\n    io.rancher.container.pull_image: always\r\n  tty: true\r\n  command:\r\n  - sh\r\n  - -c\r\n  - while true; do echo bla; sleep 1; done\r\n  image: busybox\r\n  stdin_open: true\r\n",
    "environment": null,
    "externalId": "",
    "healthState": "healthy",
    "id": "1e5",
    "kind": "environment",
    "links": {
        "account": "http://172.19.8.20:8081/v1/environments/1e5/account",
        "composeConfig": "http://172.19.8.20:8081/v1/environments/1e5/composeconfig",
        "self": "http://172.19.8.20:8081/v1/environments/1e5",
        "services": "http://172.19.8.20:8081/v1/environments/1e5/services"
    },
    "name": "myapp",
    "outputs": null,
    "previousExternalId": null,
    "rancherCompose": "busybox:\r\n  scale: 1\r\n",
    "removeTime": null,
    "removed": null,
    "startOnCreate": true,
    "state": "active",
    "transitioning": "no",
    "transitioningMessage": null,
    "transitioningProgress": null,
    "type": "environment",
    "uuid": "321f460e-de6f-4645-9190-33fe8fe300dd"
}

I have created this github issue https://github.com/rancher/rancher/issues/4113