Skip to content

Add two new actions 'info' and 'list' with an optional quiet mode

Tortue Torche requested to merge github/fork/tortuetorche/patch-1 into master

Hi,

Here two actions info and list, which can be useful in a Continuous Integration (CI)/Continuous Delivery CD workflow, with tool like GitLab CI:

The info action:

psu -a info -u admin -p password -l http://portainer.local -n mystack

Output the JSON object of the stack if it's already deployed:

{
  "Id": "mystack_jpofkc0i9uo9wtx1zesuk649w",
  "Name": "mystack",
  "Type": "1",
  "EndpointID": "1",
  "EntryPoint": "docker-compose.yml",
  "SwarmID": "jpofkc0i9uo9wtx1zesuk649w",
  "ProjectPath": "/data/compose/mystack_jpofkc0i9uo9wtx1zesuk649w",
  "Env": [
    {
      "name": "MYSQL_ROOT_PASSWORD",
      "value": "password"
    }
  ]
}

The info action with the quiet mode enabled:

psu -a info -u admin -p password -l http://portainer.local -n mystack -q

Output the stack name if it's already deployed:

mystack

The list action:

psu -a list -u admin -p password -l http://portainer.local

Output a JSON array of the stacks already deployed:

[
  {
    "Id": "mystack_jpofkc0i9uo9wtx1zesuk649w",
    "Name": "mystack",
    "Type": "1",
    "EndpointID": "1",
    "EntryPoint": "docker-compose.yml",
    "SwarmID": "jpofkc0i9uo9wtx1zesuk649w",
    "ProjectPath": "/data/compose/mystack_jpofkc0i9uo9wtx1zesuk649w",
    "Env": [
      {
        "name": "MYSQL_ROOT_PASSWORD",
        "value": "password"
      }
    ]
  },
  {
    "Id": "mysecondstack_i0649w9uo9wtx1zesujpofkck",
    "Name": "mysecondstack",
    "Type": "1",
    "EndpointID": "1",
    "EntryPoint": "docker-compose.yml",
    "SwarmID": "i0649w9uo9wtx1zesujpofkck",
    "ProjectPath": "/data/compose/mysecondstack_i0649w9uo9wtx1zesujpofkck"
  },
  {
    "Id": "mythirdstack_w9uo9wtxi064ujpofkck91zes",
    "Name": "mythirdstack",
    "Type": "1",
    "EndpointID": "1",
    "EntryPoint": "docker-compose.yml",
    "SwarmID": "mythirdstack_w9uo9wtxi064ujpofkck91zes",
    "ProjectPath": "/data/compose/mythirdstack_mythirdstack_w9uo9wtxi064ujpofkck91zes"
  },
]

The list action with the quiet mode enabled:

psu -a list -u admin -p password -l http://portainer.local -q

Output the name of the stacks already deployed:

mystack
mysecondstack
mythirdstack

Feedback are welcome!

NB: I also plan to add two new actions status (borrowed from Helm) and rollout (borrowed from kubectl). But for services/tasks instead of stack centric with the help of theses resources: https://gist.github.com/deviantony/77026d402366b4b43fa5918d41bc42f8#execute-docker-queries-against-a-specific-endpoint and https://docs.docker.com/engine/api/v1.30/#operation/TaskList

Cheers, Tortue Torche

Merge request reports