Use API to start new container from catalog

I have a catalog entry that I use to fire up new instances, with questions (user name etc)

is it possible to use the API to take a catalog entry, supply the answers to the questions and spin up the new container ?

I can’t seem to find an api for catalog entries in the documentation

thanks

Bump… does anyone have any idea on how to take a catalog entry and spin up a stack from it ?

There is no “deploy this catalog entry” API call… the catalog API supplies compose yaml files, the UI generates a key/value map of answers, and those are passed to the standard create stack call (environment in the API…).

(Note: this is for Cattle orchestration… Kubernetes has different endpoints because it goes to the kubectl service directly)

http://docs.rancher.com/rancher/latest/en/api/api-resources/environment/

Basically POST /v1/projects/<projectId>/environments

{
  name: "My App",
  dockerCompose: "your docker-compose yaml",
  rancherCompose: "your rancher-compose yaml",
  environment: {
    question1: "answer1",
    question2: "answer2"
  }
}

For double confusion, the answers go in the property called environment, because the substitution is intended for environment variables in libcompose.

@vincent What are the following fields for in the context of POST /v1/projects/<projectId>/environments?

  • externald
  • outputs
  • previousEnvironments
  • previousExternalId

The docs page isn’t very clear about them. I’d be more than happy to contribute, if you could explain those to me. :slight_smile:

externalId is an arbitrary string, but if it’s of the form catalog://<the ID of a catalog template> then it’s used by the UI to determine if upgrades to the stack from a new version of the catalog template are available.

outputs is for a feature that we didn’t really do anything with.

previousEnvironments and previousExternalId are not really meant to be set by you, but are used to store the previous enviornment map and external ID during an upgrade.

Thanks for that! Pull request created. :metal:

@vincent, @jmls

I found some API key as http://<rancher_server>/v1-catalog

seems it works.

Whenever I try to POST the data i get the following:

{"id":"da2a00ba-3ac3-447a-9581-c9920a6a0588","type":"error","links":{},"actions":{},"status":422,"code":"InvalidFormat","message":null,"detail":null,"fieldName":"environment","baseType":"error"}

The data is like the following:

 {'environment': {u'public_port': 8035}, 'rancherCompose': u'.catalog:\n  name: "Wordpress"\n  version: "v0.1-educaas1"\n  description: "Blog tool, publishing platform and CMS"\n  uuid: Wordpress-0\n  minimum_rancher_version: v0.51.0\n  questions:    \n    - variable: public_port\n      description: "public port to access the wordpress site"\n      label: "Public Port"\n      required: true\n      default: "80"\n      type: "int"\n\n\nwordpress:\n', 'name': 'API tester', 'dockerCompose': u'wordpress:\n  image: wordpress\n  links:\n    - db:mysql\n  ports:\n    - ${public_port}:80\n\ndb:\n  image: mariadb\n  environment:\n    MYSQL_ROOT_PASSWORD: example\n'}

What should I do ?

Note:
When I checked the Audit Logs I noticed that Rancher got the request as follows:

    {
  "environment": "public_port",
  "name": "API tester",
  "rancherCompose": ".catalog:\n  name: \"Wordpress\"\n  version: \"v0.1-educaas1\"\n  description: \"Blog tool, publishing platform and CMS\"\n  uuid: Wordpress-0\n  minimum_rancher_version: v0.51.0\n  questions:    \n    - variable: public_port\n      description: \"public port to access the wordpress site\"\n      label: \"Public Port\"\n      required: true\n      default: \"80\"\n      type: \"int\"\n\n\nwordpress:\n",
  "dockerCompose": "wordpress:\n  image: wordpress\n  links:\n    - db:mysql\n  ports:\n    - ${public_port}:80\n\ndb:\n  image: mariadb\n  environment:\n    MYSQL_ROOT_PASSWORD: example\n"
}

I have no idea why there is a different environment value as i sent it as a dictionary with key and value