Updated on 2023-04-04 GMT+08:00

Adding an Image Retention Policy

Scenario

This section describes how to add an image retention policy using APIs. For details on how to call APIs, see Calling APIs.

Involved APIs

In this example, the following APIs are used:

Procedure

  1. Add an image retention policy.
    • URI format

      POST /v2/manage/namespaces/{namespace}/repos/{repository}/retentions

      For details, see Adding an Image Retention Policy.

    • Example request

      POST https://{endpoint}/v2/manage/namespaces/group/repos/test/retentions

      Body:

      {
          "algorithm": "or",
          "rules": [
              {
                  "template": "date_rule",
                  "params": {
                      "days": "30"
                  },
                  "tag_selectors": [
                      {
                          "kind": "label",
                          "pattern": "v5"
                      },
                      {
                          "kind": "label",
                          "pattern": "1.0.1"
                      },
                      {
                          "kind": "regexp",
                          "pattern": "^123$"
                      }
                  ]
              }
          ]
      }
    • Example response
      {
          "id": 34
      }
  2. Delete an image retention policy.
    • URI format

      DELETE /v2/manage/namespaces/{namespace}/repos/{repository}/retentions/{retention_id}

      For details, see Deleting an Image Retention Policy.

    • Example request

      DELETE https://{endpoint}/v2/manage/namespaces/group/repos/test/retentions/34

    • Example response
      {}