Just came through the following question about how to create a stack using catalog api and I have tried what @vincent suggested but I am facing a problem with the POST
step.
Note: I am using v2-beta
api so I am doing the POST
request against this URL: /v2-beta/projects/<projectID>/stacks
and previously I tried the v1 api /v1/projects/<projectID>/environments
which have the same result.
The data i sent:
{'environment': {'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'}
And the response I got:
{"id":"da2a00ba-3ac3-447a-9581-c9920a6a0588",
"type":"error","links":{},"actions: {},"status":422,"code":"InvalidFormat",
"message":null,"detail":null,"fieldName":"environment","baseType":"error"}
The response is telling me that there is an error with the datatype
of environment
which I pass it as a dict
after debugging a little I noticed that the Rancher API is seeing the value as string like this:
{
"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 donât know why the value changed even if i printed the payload before passing it to the POST
request to make sure that I am passing the correct format.
Rancher version is 1.2.1