ARTIFACTORY: How to determine which images within a docker repository are using the most space

AuthorFullName__c
Kayvan Sofastaee
articleNumber
000005825
FirstPublishedDate
2023-07-19T15:53:31Z
lastModifiedDate
2023-07-19

ARTIFACTORY: How to determine which images within a docker repository are using the most space

Docker repositories in Artifactory are typically designed to handle a certain level of load and traffic. Some organizations over-utilized their docker repository. When a Docker repository is over-utilized, it can lead to performance issues. The repository may become slower in handling requests and may struggle to keep up with the increased load. From this maintenance work needs to be in place.

To be able to prevent these situations, it is vital knowing the layer sizes of each tag digest in a Docker repository can provide several advantages in preventing over-utilization and optimizing resource usage. By knowing the sizes of Docker layer tags, you can estimate the amount of storage space required for each image. This information allows you to allocate resources more effectively, ensuring you have sufficient storage capacity to accommodate the images without over-utilizing the repository. When you have visibility into the sizes of Docker layers, you can plan your resource allocation and scaling requirements more accurately. You can estimate the growth rate of the repository, predict future storage needs, and scale your infrastructure accordingly to accommodate increasing demands.
 

AQL / RestAPIs


To determine which layers within a docker repository are using the most space can be accomplished using AQL, Artifactory Query Language.  We will be able to pull up the layers and sizes in the repository of our choosing. We can use AQL to look for the docker layers tag and use RestAPIs to provide folder info, file info, and storage summary info explained here.
 

Example:

First create AQL Script file (example.aql) that contains: 

items.find( 
{
        "repo": {"$eq": "test-docker-remote-cache"},
        "$and": [
            {"type":"file"},
            {
                "$and": [
                    {"path": {"$match": "*nginx*"}}
                ]
            }
        ]
    })
.include("name","path","size")


Then used the command below to make the call to retrieve the information created from the "aql" script:

curl -X POST -uadmin:<password> 'https://<ARTIFACTORY_URL>/artifactory/api/search/aql' -T example.aql


The results to running the above command: 

{
"results" : [ {

  "path" : "library/nginx/1.24.0-alpine",
  "name" : "list.manifest.json",
  "size" : 1645
},{

"path" : "library/nginx/sha256__0bb91b50c42bc6677acff40ea0f050b655c5c2cc1311e783097a04061191340b",
"name" : "manifest.json",

  "size" : 1571
},{

  "path" : "library/nginx/sha256__7e4f9e3295d61e2d26b2b568c2e5d9707a50bbd69afaabdfea942bdd216183a8",
"name" : "sha256__20779f060cd3ec277650210aa15654e9ad332ba27e4933f738febc7892f21610",

  "size" : 1788531  ##layer size
},{

"path" : "library/nginx/sha256__0bb91b50c42bc6677acff40ea0f050b655c5c2cc1311e783097a04061191340b",
"name" : "sha256__ad570474ca7c3653588972408b7f01499a4a6cd2d8bc9fb9e4f4ba332a61d11d",

  "size" : 25695730
},{

"path" : "library/nginx/sha256__7e4f9e3295d61e2d26b2b568c2e5d9707a50bbd69afaabdfea942bdd216183a8",
"name" : "sha256__c41833b44d910632b415cd89a9cdaa4d62c9725dc56c99a7ddadafd6719960f9",

  "size" : 3261854
},{

"path" : "library/nginx/sha256__0bb91b50c42bc6677acff40ea0f050b655c5c2cc1311e783097a04061191340b",
"name" : "sha256__d981f2c20c93e1c57a46cd87bc5b9a554be5323072a0d0ab4b354aabd237bbcf",

  "size" : 30052747
},{

"path" : "library/nginx/sha256__7e4f9e3295d61e2d26b2b568c2e5d9707a50bbd69afaabdfea942bdd216183a8",
"name" : "sha256__e5382a11adf2600437da72df68012b6432b1eb0d03f7a107accccd3dab938912",

  "size" : 11139336 
} ],

"range" : {
  "start_pos" : 0,
  "end_pos" : 7,
  "total" : 7 
}


This then gives the size of each layer in the docker repository.

In addition this documentation provided can help for collecting all images in a repo as well using AQL.


Lastly, we can run this API to gather the Artifact Count/Size for the folders in the repo of our choosing. Same thing we would do in UI but more in an efficient way.

Example:

This is the command to run to gather the Artifact Count/Size for 'test-docker-remote-cache':

curl -XPOST -uadmin:<password> localhost:8081/artifactory/api/artifactgeneral/artifactsCount 
-H "Content-type: Application/json" --data '{"name":"library","repositoryPath":"test-docker-remote-cache/"}'


Output:

{
  "artifactsCount" : 22,
  "artifactSize" : "68.62 MB"
}


From this we can achieve the size of the Image with all the tags, and can sum up all the tags resulted from the query as well.