How to search old docker tags using AQL or CLI

Hirofumi Iwashita
2021-08-22 06:37

The main purpose is searching for some old docker tags using AQL or CLI and List Docker Tags is for deleting them. 
For example, the following instructions show us how to search 4(limit) old hello-world tags based on modified date in docker-local repository.

  1. Count total tags

    $ curl -s -X GET http://localhost:8081/artifactory/api/docker/docker-local/v2/hello-world/tags/list -u admin:password | jq '.tags | length'
    11
    $

  2. Calculate the offset(7) using total tags number(11) and limit(4) you want to delete

    11 - 4 = 7

  3. Specify offset(7) and limit(4) parameters and search tags (AQL version)

    $ curl -X POST http://localhost:8081/artifactory/api/search/aql -u admin:password -H "Content-Type: text/plain" -d 'items.find({"repo":"docker-local"},{"path":{"$ne":"."}},{"type":"folder"}).include("repo","name","path","modified").sort({"$asc" : ["modified"]}).offset(7).limit(4)'

    {
    "results" : [ {
      "repo" : "docker-local",
      "path" : "hello-world",
      "name" : "7.0",
      "modified" : "2020-06-19T23:44:40.670Z"
    },{
      "repo" : "docker-local",
      "path" : "hello-world",
      "name" : "8.0",
      "modified" : "2020-06-19T23:44:42.898Z"
    },{
      "repo" : "docker-local",
      "path" : "hello-world",
      "name" : "10.0",
      "modified" : "2020-06-19T23:44:44.983Z"
    },{
      "repo" : "docker-local",
      "path" : "hello-world",
      "name" : "9.0",
      "modified" : "2020-06-19T23:44:44.983Z"
    } ],
    "range" : {
      "start_pos" : 7,
      "end_pos" : 4,
      "total" : 4,
      "limit" : 4
    }
    }
    $

  4. Specify offset(7) and limit(4) parameters and search tags (CLI version)

    $ cat spec.json
    {
    "files": [
    {
    "aql": {
    "items.find": {
    "repo":"docker-local",
    "path":{"$ne":"."},
    "type":"folder"
    }
    },
    "sortBy": ["modified"],
    "sortOrder": "asc",
    "offset": 7,
    "limit": 4
    }
    ]
    }
    $ jfrog rt s --url http://localhost:8081/artifactory --user admin --password password --spec spec.json
    [Info] Searching artifacts...
    [Info] Found 4 artifacts.
    [
      {
        "path": "docker-local/hello-world/7.0",
        "type": "folder",
        "created": "2020-06-19T23:44:40.670Z",
        "modified": "2020-06-19T23:44:40.670Z"
      },
      {
        "path": "docker-local/hello-world/8.0",
        "type": "folder",
        "created": "2020-06-19T23:44:42.898Z",
        "modified": "2020-06-19T23:44:42.898Z"
      },
      {
        "path": "docker-local/hello-world/10.0",
        "type": "folder",
        "created": "2020-06-19T23:44:44.983Z",
        "modified": "2020-06-19T23:44:44.983Z"
      },
      {
        "path": "docker-local/hello-world/9.0",
        "type": "folder",
        "created": "2020-06-19T23:44:44.983Z",
        "modified": "2020-06-19T23:44:44.983Z"
      }
    ]
    $