Search code examples
dockerdocker-ucp

How to get a single stack from Docker UCP API


I'm writing devops pipelines in a Docker Enterprise 3.2 environment.

I am able to fetch all stacks from the UCP API. Now I need to fetch single stacks but the documentation seems to omit completely this resource.

Is there anything as:

ucp_url/api/stacks/my_awesome_stack_name

or

ucp_url/api/stacks?name=my_awesome_stack_name

?


Solution

  • Short answer

    The field namespace is the identifier of the stack. Calling api/stacks/my_namespace will get the desired stack.

    How I found this

    After fiddling a bit with the documentation and the api, I realized that the stacks resource is just another collection that can be selected using its identifier.

    When you invoke api/stacks you'll receive a collection of stacks looking like this:

    [
      {
        "namespace": "my_awesome_namespace_1",
        "services": []
        ...
        "namespace": "my_awesome_namespace_2",
        "services": []
        ...
      }
    ]
    

    I simply tried api/stacks/my_awesome_namespace_1 and received the desired object in json format.

    And beyond

    I believe the most important thing to this answer is that this method could be generalized to any UCP resource.

    1. fetch all resources of a given resource type
    2. try to determine which field is the identifier
    3. try calling my_awesome_resource/my_awesome_resource_identifier
    4. cheer up :)