diff --git a/English/SUMMARY.md b/English/SUMMARY.md index d2e607494..34dace5d1 100644 --- a/English/SUMMARY.md +++ b/English/SUMMARY.md @@ -1114,6 +1114,7 @@ * [Edit quota limit](vcontainer-registry/repository/edit-quota-limit.md) * [Manage image](vcontainer-registry/repository/manage-image.md) * [Repository History](vcontainer-registry/repository/repository-history.md) + * [Retention Policy](vcontainer-registry/repository/retention-policy.md) * [Repository user](vcontainer-registry/repository-user/README.md) * [Create repository user](vcontainer-registry/repository-user/create-repository-user.md) * [Edit user information](vcontainer-registry/repository-user/edit-user-information.md) diff --git a/English/vcontainer-registry/repository/README.md b/English/vcontainer-registry/repository/README.md index 3a910857b..df2debc1b 100644 --- a/English/vcontainer-registry/repository/README.md +++ b/English/vcontainer-registry/repository/README.md @@ -29,3 +29,7 @@ For more details, refer to the "Repository User" section. **VIEW HISTORY** The access history of the Repository allows you to track all actions related to it, including actions on the Repository itself and related Images. For more information, refer to the "Repository History" section. + +**RETENTION POLICY** + +Clean up old artifacts in the Repository automatically. You set rules to choose which artifacts to keep; vCR deletes the rest on a schedule or when you click Run now. For more details, refer to the "[Retention Policy](retention-policy.md)" section. diff --git a/English/vcontainer-registry/repository/retention-policy.md b/English/vcontainer-registry/repository/retention-policy.md new file mode 100644 index 000000000..838c647c0 --- /dev/null +++ b/English/vcontainer-registry/repository/retention-policy.md @@ -0,0 +1,227 @@ +# Retention Policy + +A retention policy helps you clean up old artifacts in a Repository automatically. You set rules to choose which artifacts to keep; vCR deletes the rest on a schedule or when you click **Run now**. + +This feature suits teams whose CI pushes many tags (for example, one new tag per commit) and who want to control storage usage and quota cost. + +{% hint style="warning" %} +Artifacts deleted by a retention policy **cannot be restored**. Always use **Dry run** to check before a real run or before you set a schedule. +{% endhint %} + +## What is a retention policy + +A retention policy is a set of rules that decide which artifacts in a repository are **kept**. When the policy runs, every in-scope artifact that no enabled rule keeps is **permanently deleted**. + +Each repository has at most **one** retention policy. It has up to **15 rules** and **one schedule**. A repository without a policy shows an empty rule list and the schedule **None**. + +Without a policy, every image you push is kept forever. Old build tags pile up, take up storage, and count toward the repository quota. + +**Terms used on the portal** + +| Term | Meaning | Example | +| --- | --- | --- | +| Repository | Your repository on vCR, the billing unit | `my-team` | +| Image | One image name in the repository | `my-team/backend` | +| Artifact | One pushed version of an image, identified by its digest (it can have one or more tags, or no tag) | `backend@sha256:ab12…` | +| Tag | A name that points to an artifact | `v1.4.2`, `latest` | +| Untagged artifact | An artifact with no tags left, usually created when you push over an existing tag | — | + +## How rules work + +Each rule is evaluated on its own, then the results are combined: **an artifact is kept if at least one enabled rule keeps it.** An artifact that no rule keeps is deleted. Disabled rules are ignored. + +Each rule has 3 parts: + +1. **Images** — *matching* or *excluding* a pattern. This part selects the images the rule looks at. +2. **Retain condition** — one of the templates below, with a number from 0 to 10000. +3. **Tags** — *matching* or *excluding* a pattern, plus the **Include untagged artifacts** checkbox. + +| Template (as shown on the portal) | Keeps | +| --- | --- | +| retain the most recently pushed N artifacts per image | The N newest pushed artifacts, counted per image | +| retain the most recently pulled N artifacts per image | The N most recently pulled artifacts, counted per image | +| retain the artifacts pushed within the last N days | Artifacts pushed in the last N days | +| retain the artifacts pulled within the last N days | Artifacts pulled in the last N days | +| retain always | Every artifact the rule matches (no number needed) | + +**Patterns** + +* `**` matches everything, `*` matches any string of characters, `?` matches exactly one character. +* Use commas to enter several values: `backend,frontend` or `v1.*,release-*`. +* Allowed characters: letters, digits and `. _ - / * ? { } , [ ]`, up to 255 characters. The pattern cannot be empty. + +**The number 0.** If you enter 0, the rule keeps no artifacts. Every matching artifact is deleted, unless another rule keeps it. The form shows a warning when you enter 0, for example: *Retain 0 most recently pushed artifacts: every matching artifact in each image will be deleted unless another rule retains it.* Use it with care. + +**Images or tags outside every rule** are not touched by the policy. Only artifacts that a rule looks at (by image and tag pattern) can be deleted. + +## How to use it on the portal + +Go to **Container Registry → Repository list**, click a repository, then open the **Retention policy** tab (next to the Images, Users and History tabs). The tab has 3 sections: **Retention rules**, **Schedule** and **Retention runs**. + +### Add a rule + +1. Click **Add rule**. The **Add retention rule** dialog opens. It has 2 numbered sections. +2. **1. Select images** — in **For the images**, choose *matching* or *excluding*, then enter image names or a pattern (for example `**` for all images). +3. **2. Choose artifacts to keep**: + * In **By artifact count or number of days**, choose a template and enter a number. + * In **Tags**, choose *matching* or *excluding* and enter tags or a pattern. + * Tick **Include untagged artifacts** if you want the rule to also look at untagged artifacts. +4. Click Save. The rule appears in the list as a sentence, for example: *For the images \*\*, retain the most recently pushed 10 artifacts per image with tags \*\* (excluding untagged artifacts).* + +You cannot save two identical rules in the same repository. + +### Edit, disable or delete a rule + +Use the **Action** menu on the rule's row: + +* **Edit** — change the rule. +* **Disable** / **Enable** — a disabled rule stays in the list with the status **Disabled**, but it is not used when the policy runs. +* **Delete** — remove the rule. A confirm dialog shows the rule before it is deleted. + +### Set a schedule + +1. In the **Schedule** section, click **Edit**. +2. Choose a schedule type: + * **None** — runs only when you click Run now. + * **Hourly** — every hour, at minute 0. + * **Daily** — every day at 00:00 UTC (07:00 Vietnam time). + * **Weekly** — every Sunday at 00:00 UTC (07:00 Vietnam time). + * **Custom** — a 6-field cron expression in UTC: `second minute hour day-of-month month day-of-week`. Example: `0 0 2 * * *` runs at 02:00 UTC (09:00 Vietnam time). Runs must be at least 1 hour apart. +3. Save. The schedule applies to all rules of the repository. + +The Schedule section shows the time in UTC and in your local time. + +### Check with Dry run + +A dry run applies all enabled rules to the repository exactly like a real run, but it **deletes nothing**. Use it to see in advance **which images** the rules touch, and **which artifacts (tags)** would be deleted or kept. + +**Steps** + +1. Click **Dry run**. A new row appears in **Retention runs** with **Dry run = Yes**. +2. Wait until the status changes to **Success**. The page refreshes every 10 seconds. +3. Click **Show tasks** on that row. Each image that the rules look at is one row (one task). Above the table you see: *Dry run: nothing was deleted. "Retained / Total" shows how many artifacts a real run would keep.* +4. Read the **Retained / Total** column for each image: + +| Example | Meaning for a real run | +| --- | --- | +| `10 / 10` | This image loses no artifacts | +| `10 / 37` | 10 artifacts are kept, **27 artifacts would be deleted** | +| `0 / 12` | **All 12 artifacts would be deleted**. Check your rules again (for example a count of 0, or a tag pattern that is too narrow) | + +5. Click **Log** on an image to see exactly **which artifacts and tags** would be deleted or kept (see below). + +An image that is not in the task list is outside the scope of every rule, so it is not touched. + +{% hint style="info" %} +Run a dry run again every time you add, edit, enable or disable a rule, and always before you click **Run now** or set a schedule. A real run gives the same result as the dry run if no artifacts are pushed or pulled between the two runs. +{% endhint %} + +### View the retention log on the vCR portal + +You can read the detailed log of each image directly on the vCR portal; you do not need Harbor. Logs are available for **Dry run**, **Run now** and **Schedule** runs. + +1. In **Retention runs**, click **Show tasks** on the run you want to check. +2. Click **Log** on the image's row. The **Retention log of image <image name>** window opens. + +The log starts with a header that shows the repository, how rules are combined, and whether the run is a dry run (`Dry Run: true`). Then it shows a table with one row per artifact. The main columns are: + +| Column | Meaning | +| --- | --- | +| Digest | The digest of the artifact | +| Tag | The tags of the artifact (empty for an untagged artifact) | +| PushedTime / PulledTime | The last push / pull time, used by the push / pull templates | +| Retention | The result: `RETAIN` = kept, `DEL` = deleted (or would be deleted in a dry run), `ERR` = deletion failed | + +Example log of a dry run: + +``` +Run retention process. + Repository: my-team/backend + Rule Algorithm: or + Dry Run: true ++-----------------+--------+-------+--------+---------------------+---------------------+---------------------+-----------+ +| DIGEST | TAG | KIND | LABELS | PUSHEDTIME | PULLEDTIME | CREATEDTIME | RETENTION | ++-----------------+--------+-------+--------+---------------------+---------------------+---------------------+-----------+ +| sha256:ab12... | v1.4.2 | image | | 2026/11/18 09:12:01 | 2026/11/19 02:00:13 | 2026/11/18 09:12:01 | RETAIN | +| sha256:cd34... | v1.4.1 | image | | 2026/11/10 08:01:44 | | 2026/11/10 08:01:44 | DEL | +| sha256:ef56... | | image | | 2026/10/02 15:30:10 | | 2026/10/02 15:30:10 | DEL | ++-----------------+--------+-------+--------+---------------------+---------------------+---------------------+-----------+ +``` + +{% hint style="warning" %} +**Notes about the log** + +* Read the log on the vCR portal (Retention policy tab). Do not use the Harbor UI to view or edit the retention policy. +* In a dry run, `DEL` means the artifact **would** be deleted in a real run; nothing has been deleted yet. +* In a real run, a row with `ERR`, or a "Retention error for artifact" line, means that artifact was **not** deleted. The task can still show **Success**, but it also shows the warning *N artifact(s) failed to delete*. +* If the log is empty, the window shows **No log**. Wait until the run has finished, then open it again. +{% endhint %} + +### Run now + +Click **Run now**. The **Run retention policy now** dialog warns that artifacts not retained by any rule will be permanently deleted. You can click **Run now** to continue, or **Dry run** to check first. + +{% hint style="info" %} +The **Run now** and **Dry run** buttons are disabled until the repository has at least one enabled rule. +{% endhint %} + +### Track a run + +The **Retention runs** table has these columns: + +| Column | Meaning | +| --- | --- | +| Status | Pending, Scheduled, Running, Success, Stopped, Error or Failed | +| Dry run | Yes for a dry run, No for a real run | +| Execution type | Manual (you clicked a button) or Schedule | +| Start time | When the run started | +| Duration | Shown when the run has finished | + +The page refreshes every 10 seconds while a run is in progress. + +Click **Show tasks** to see one task per image, with its status, **Retained / Total**, start time and duration. Click **Log** on a task to read the retention log of that image. + +**Failed deletions.** A task can show **Success** even when some artifacts could not be deleted. In this case the task shows the warning *N artifact(s) failed to delete*. Open the **Log** and look for lines with "Retention error for artifact" or **Retention = ERR** to see why. + +### Abort a run + +Click **Abort** on a running run and confirm. The run stops after a few seconds and changes to **Stopped**. If the run had already finished, its result is kept. Artifacts that were already deleted are not restored. + +## Examples + +| Goal | Rule setup | Result | +| --- | --- | --- | +| Keep the 10 newest builds of every image | Images matching `**` · retain the most recently pushed 10 artifacts per image · tags matching `**` | Each image keeps its 10 newest artifacts; older ones are deleted | +| Keep releases forever, clean up dev builds | Rule 1: images `**` · retain always · tags matching `v*,release-*`. Rule 2: images `**` · retain the artifacts pushed within the last 14 days · tags matching `**` | Release tags are never deleted; other tags are kept for 14 days | +| Delete only untagged artifacts | Rule 1: images `**` · retain the most recently pushed 0 artifacts per image · tags `**` + include untagged artifacts. Rule 2: images `**` · retain always · tags `**`, excluding untagged artifacts | All tagged artifacts are kept; untagged artifacts are deleted | +| Clean up only one image | Images matching `backend` · retain the most recently pushed 5 artifacts per image · tags `**` | Only `backend` is cleaned up; other images are not touched | +| Clean up all images except one | Images excluding `base` · retain the most recently pushed 5 artifacts per image · tags `**` | Every image except `base` is cleaned up | +| Keep what is still in use | Images `**` · retain the artifacts pulled within the last 30 days · tags `**` | Artifacts not pulled in the last 30 days are deleted | + +{% hint style="info" %} +After you add or edit rules, run a **Dry run** and check the **Retained / Total** column before you set a schedule. +{% endhint %} + +## Limits + +| Item | Limit | +| --- | --- | +| Retention policies per repository | 1 | +| Rules per repository | 15 | +| Schedules per repository | 1 | +| Count / days in a rule | 0 to 10000 | +| Pattern length | 1 to 255 characters | +| Custom cron | 6 fields, UTC, runs at least 1 hour apart | +| Duplicate rules | Not allowed | + +## FAQ + +**Can I restore deleted artifacts?** No. Deleted artifacts cannot be restored. Always use Dry run first. + +**Why does the schedule use UTC?** The registry runs on UTC time. Add 7 hours to get Vietnam time. The portal also shows the schedule in your local time. + +**What happens when I delete a rule?** The rule is deleted right away. The next run uses only the remaining enabled rules. + +**Can I set a schedule before I add rules?** Yes. But a run only deletes artifacts when there is at least one enabled rule, and Run now and Dry run need at least one enabled rule. + +**Why does a task show Success but some artifacts are still there?** Some deletions may have failed. Look for the *failed to delete* warning on the task and read the **Log**. See [Track a run](#track-a-run). diff --git a/Vietnamese/SUMMARY.md b/Vietnamese/SUMMARY.md index 3d9796d3a..752eb29ab 100644 --- a/Vietnamese/SUMMARY.md +++ b/Vietnamese/SUMMARY.md @@ -1114,6 +1114,7 @@ * [Cách chỉnh sửa Quota Limit](vcontainer-registry/repository/cach-chinh-sua-quota-limit.md) * [Cách quản lý Image](vcontainer-registry/repository/cach-quan-ly-image.md) * [Xem lịch sử Repository History](vcontainer-registry/repository/xem-lich-su-repository-history.md) + * [Cấu hình Retention Policy](vcontainer-registry/repository/cau-hinh-retention-policy.md) * [Repository User](vcontainer-registry/cach-tao-repository-user/README.md) * [Tạo Repository User](vcontainer-registry/cach-tao-repository-user/tao-repository-user.md) * [Điều chỉnh thông tin](vcontainer-registry/cach-tao-repository-user/dieu-chinh-thong-tin.md) diff --git a/Vietnamese/vcontainer-registry/repository/README.md b/Vietnamese/vcontainer-registry/repository/README.md index 883f7443b..10b677362 100644 --- a/Vietnamese/vcontainer-registry/repository/README.md +++ b/Vietnamese/vcontainer-registry/repository/README.md @@ -29,6 +29,10 @@ Xem danh sách Repository User được đính kèm bằng cách nhấp vào tab Lịch sử truy cập của Repository giúp bạn theo dõi tất cả các hành động liên quan đến nó, bao gồm cả những hành động đối với Repository và Images liên quan. Tham khảo thêm tại Repository History. +**CẤU HÌNH RETENTION POLICY** + +Tự động dọn dẹp các artifact cũ trong Repository. Bạn đặt các rule để chọn artifact cần giữ lại; vCR sẽ xoá phần còn lại theo lịch chạy hoặc khi bạn bấm Chạy ngay. Tham khảo chi tiết tại Retention Policy. + #### Bài viết liên quan * [Create Repository](cach-tao-repository.md) @@ -36,5 +40,6 @@ Lịch sử truy cập của Repository giúp bạn theo dõi tất cả các h * [Image Management](cach-quan-ly-image.md) * [Repository User](../cach-tao-repository-user/) * [Repository History](xem-lich-su-repository-history.md) +* [Retention Policy](cau-hinh-retention-policy.md)
diff --git a/Vietnamese/vcontainer-registry/repository/cau-hinh-retention-policy.md b/Vietnamese/vcontainer-registry/repository/cau-hinh-retention-policy.md new file mode 100644 index 000000000..843728065 --- /dev/null +++ b/Vietnamese/vcontainer-registry/repository/cau-hinh-retention-policy.md @@ -0,0 +1,227 @@ +# Cấu hình Retention Policy + +Retention policy giúp bạn tự động dọn dẹp các artifact cũ trong Repository. Bạn đặt các rule để chọn artifact cần giữ lại; vCR sẽ xoá phần còn lại theo lịch chạy hoặc khi bạn bấm **Chạy ngay**. + +Tính năng này phù hợp với các team có CI push nhiều tag (ví dụ mỗi commit một tag mới) và muốn kiểm soát dung lượng lưu trữ cũng như chi phí quota. + +{% hint style="warning" %} +Artifact bị retention policy xoá **không thể khôi phục**. Hãy luôn dùng **Chạy thử** để kiểm tra trước khi chạy thật hoặc đặt lịch chạy. +{% endhint %} + +## Retention policy là gì + +Retention policy là tập hợp các rule quy định artifact nào trong repository được **giữ lại**. Khi policy chạy, mọi artifact trong phạm vi mà không được rule nào đang bật giữ lại sẽ bị **xoá vĩnh viễn**. + +Mỗi repository có tối đa **một** retention policy, gồm tối đa **15 rule** và **một lịch chạy**. Repository chưa có policy sẽ hiển thị danh sách rule trống và lịch chạy **Không**. + +Nếu không có policy, mọi image bạn push sẽ được giữ mãi. Các tag build cũ tích tụ dần, chiếm dung lượng và được tính vào quota của repository. + +**Các thuật ngữ trên portal** + +| Thuật ngữ | Ý nghĩa | Ví dụ | +| --- | --- | --- | +| Repository | Repository của bạn trên vCR, là đơn vị tính phí | `my-team` | +| Image | Một tên image trong repository | `my-team/backend` | +| Artifact | Một phiên bản đã push của image, xác định bằng digest (có thể có một hoặc nhiều tag, hoặc không có tag) | `backend@sha256:ab12…` | +| Tag | Tên trỏ tới một artifact | `v1.4.2`, `latest` | +| Artifact không có tag | Artifact không còn tag nào, thường sinh ra khi push đè một tag đã có | — | + +## Cách rule hoạt động + +Mỗi rule được tính độc lập, rồi gộp kết quả lại: **artifact được giữ nếu có ít nhất một rule đang bật giữ nó.** Artifact không được rule nào giữ sẽ bị xoá. Rule đã tắt sẽ bị bỏ qua. + +Mỗi rule gồm 3 phần: + +1. **Image** — *khớp với* hoặc *loại trừ* một pattern. Phần này chọn image mà rule sẽ xét. +2. **Điều kiện giữ** — một trong các mẫu bên dưới, kèm một số từ 0 đến 10000. +3. **Tag** — *khớp với* hoặc *loại trừ* một pattern, cùng ô chọn **Bao gồm artifact không có tag**. + +| Mẫu điều kiện (như trên portal) | Giữ lại | +| --- | --- | +| giữ N artifact được push gần nhất cho mỗi image | N artifact push mới nhất, tính theo từng image | +| giữ N artifact được pull gần nhất cho mỗi image | N artifact được pull gần nhất, tính theo từng image | +| giữ các artifact được push trong N ngày gần nhất | Artifact được push trong N ngày qua | +| giữ các artifact được pull trong N ngày gần nhất | Artifact được pull trong N ngày qua | +| luôn giữ | Mọi artifact mà rule khớp (không cần nhập số) | + +**Pattern** + +* `**` khớp tất cả, `*` khớp chuỗi ký tự bất kỳ, `?` khớp đúng một ký tự. +* Dùng dấu phẩy để nhập nhiều giá trị: `backend,frontend` hoặc `v1.*,release-*`. +* Ký tự cho phép: chữ, số và `. _ - / * ? { } , [ ]`, tối đa 255 ký tự. Không được để trống. + +**Số 0.** Nếu nhập 0, rule đó không giữ artifact nào. Mọi artifact khớp sẽ bị xoá, trừ khi có rule khác giữ lại. Form sẽ hiện cảnh báo khi bạn nhập 0, ví dụ: *Giữ 0 artifact được push gần nhất: mọi artifact khớp trong mỗi image sẽ bị xoá, trừ khi có rule khác giữ lại.* Hãy dùng cẩn thận. + +**Image hoặc tag nằm ngoài mọi rule** sẽ không bị policy đụng tới. Chỉ những artifact mà rule xét tới (theo pattern image và tag) mới có thể bị xoá. + +## Hướng dẫn sử dụng trên portal + +Vào **Container Registry → danh sách Repository**, bấm vào một repository, rồi mở tab **Retention policy** (cạnh các tab Images, Users và History). Tab gồm 3 phần: **Retention rule**, **Lịch chạy** và **Lịch sử chạy**. + +### Thêm rule + +1. Bấm **Thêm rule**. Hộp thoại **Thêm retention rule** mở ra, gồm 2 phần được đánh số. +2. **1. Chọn image** — ở ô **Áp dụng cho image**, chọn *khớp với* hoặc *loại trừ*, rồi nhập tên image hoặc pattern (ví dụ `**` cho tất cả image). +3. **2. Chọn artifact cần giữ lại**: + * Ở ô **Theo số lượng artifact hoặc số ngày**, chọn một mẫu điều kiện và nhập số. + * Ở ô **Tag**, chọn *khớp với* hoặc *loại trừ*, rồi nhập tag hoặc pattern. + * Tick **Bao gồm artifact không có tag** nếu muốn rule xét cả artifact không có tag. +4. Bấm Lưu. Rule hiển thị trong danh sách dưới dạng một câu, ví dụ: *Với image \*\*, giữ 10 artifact được push gần nhất cho mỗi image có tag \*\* (không bao gồm artifact không có tag).* + +Không thể lưu hai rule giống hệt nhau trong cùng một repository. + +### Sửa, tắt hoặc xoá rule + +Dùng menu **Thao tác** ở dòng của rule: + +* **Sửa** — thay đổi rule. +* **Tắt** / **Bật** — rule đã tắt vẫn nằm trong danh sách với trạng thái **Đã tắt**, nhưng không được dùng khi policy chạy. +* **Xoá** — xoá rule. Hộp xác nhận sẽ hiện lại nội dung rule trước khi xoá. + +### Đặt lịch chạy + +1. Ở phần **Lịch chạy**, bấm **Sửa**. +2. Chọn kiểu lịch: + * **Không** — chỉ chạy khi bạn bấm Chạy ngay. + * **Hằng giờ** — mỗi giờ, vào phút 0. + * **Hằng ngày** — mỗi ngày lúc 00:00 UTC (07:00 giờ Việt Nam). + * **Hằng tuần** — mỗi Chủ nhật lúc 00:00 UTC (07:00 giờ Việt Nam). + * **Tuỳ chỉnh** — biểu thức cron 6 trường theo giờ UTC: `giây phút giờ ngày tháng thứ`. Ví dụ: `0 0 2 * * *` chạy lúc 02:00 UTC (09:00 giờ Việt Nam). Các lần chạy phải cách nhau ít nhất 1 giờ. +3. Lưu lại. Lịch chạy áp dụng cho tất cả rule của repository. + +Phần Lịch chạy hiển thị giờ chạy theo UTC và theo giờ của bạn. + +### Kiểm tra bằng Chạy thử (Dry run) + +Chạy thử áp dụng toàn bộ rule đang bật lên repository giống hệt một lần chạy thật, nhưng **không xoá gì cả**. Dùng Chạy thử để biết trước rule sẽ tác động tới **những image nào** và **những artifact (tag) nào** sẽ bị xoá hoặc được giữ lại. + +**Các bước** + +1. Bấm **Chạy thử**. Một dòng mới xuất hiện trong **Lịch sử chạy** với cột **Chạy thử = Có**. +2. Chờ trạng thái chuyển sang **Thành công**. Trang tự làm mới mỗi 10 giây. +3. Bấm **Xem các tác vụ** ở dòng đó. Mỗi image mà rule xét tới là một dòng (một tác vụ). Phía trên bảng có thông báo: *Chạy thử: không có gì bị xoá. Cột "Giữ lại / Tổng" cho biết số artifact sẽ được giữ lại nếu chạy thật.* +4. Đọc cột **Giữ lại / Tổng** của từng image: + +| Ví dụ | Ý nghĩa nếu chạy thật | +| --- | --- | +| `10 / 10` | Image này không mất artifact nào | +| `10 / 37` | 10 artifact được giữ, **27 artifact sẽ bị xoá** | +| `0 / 12` | **Toàn bộ 12 artifact sẽ bị xoá**. Hãy kiểm tra lại rule (ví dụ số 0 hoặc pattern tag quá hẹp) | + +5. Bấm **Log** ở một image để xem chính xác **từng artifact, tag nào** sẽ bị xoá hay được giữ (xem phần bên dưới). + +Image không xuất hiện trong danh sách tác vụ thì không nằm trong phạm vi của rule nào, nên sẽ không bị đụng tới. + +{% hint style="info" %} +Hãy Chạy thử lại mỗi khi thêm, sửa, bật hoặc tắt rule, và luôn Chạy thử trước khi bấm **Chạy ngay** hoặc đặt lịch chạy. Kết quả của lần chạy thật sẽ khớp với kết quả Chạy thử nếu bạn không push hoặc pull thêm artifact giữa hai lần chạy. +{% endhint %} + +### Xem log retention trên portal vCR + +Bạn có thể xem log chi tiết của từng image ngay trên portal vCR, không cần vào Harbor. Log có cho cả lần **Chạy thử** và lần **Chạy ngay** / chạy **Theo lịch**. + +1. Trong **Lịch sử chạy**, bấm **Xem các tác vụ** ở lần chạy cần xem. +2. Bấm **Log** ở dòng của image. Cửa sổ **Log retention của image <tên image>** mở ra. + +Log gồm phần đầu cho biết repository, cách gộp rule và lần chạy có phải Chạy thử hay không (`Dry Run: true`), sau đó là bảng liệt kê từng artifact. Các cột chính: + +| Cột | Ý nghĩa | +| --- | --- | +| Digest | Digest của artifact | +| Tag | Các tag của artifact (trống nếu là artifact không có tag) | +| PushedTime / PulledTime | Lần push / pull gần nhất, dùng cho các mẫu điều kiện theo push / pull | +| Retention | Kết quả: `RETAIN` = được giữ, `DEL` = bị xoá (hoặc sẽ bị xoá nếu là Chạy thử), `ERR` = xoá thất bại | + +Ví dụ minh hoạ log của một lần Chạy thử: + +``` +Run retention process. + Repository: my-team/backend + Rule Algorithm: or + Dry Run: true ++-----------------+--------+-------+--------+---------------------+---------------------+---------------------+-----------+ +| DIGEST | TAG | KIND | LABELS | PUSHEDTIME | PULLEDTIME | CREATEDTIME | RETENTION | ++-----------------+--------+-------+--------+---------------------+---------------------+---------------------+-----------+ +| sha256:ab12... | v1.4.2 | image | | 2026/11/18 09:12:01 | 2026/11/19 02:00:13 | 2026/11/18 09:12:01 | RETAIN | +| sha256:cd34... | v1.4.1 | image | | 2026/11/10 08:01:44 | | 2026/11/10 08:01:44 | DEL | +| sha256:ef56... | | image | | 2026/10/02 15:30:10 | | 2026/10/02 15:30:10 | DEL | ++-----------------+--------+-------+--------+---------------------+---------------------+---------------------+-----------+ +``` + +{% hint style="warning" %} +**Lưu ý về log** + +* Log chỉ xem được trên portal vCR (tab Retention policy). Không dùng Harbor UI để xem hay sửa retention policy. +* Ở lần Chạy thử, `DEL` nghĩa là artifact **sẽ** bị xoá nếu chạy thật; chưa có gì bị xoá. +* Ở lần chạy thật, nếu có dòng `ERR` hoặc dòng "Retention error for artifact", artifact đó **chưa** bị xoá. Tác vụ vẫn có thể hiện **Thành công**, nhưng sẽ kèm cảnh báo *N artifact xoá thất bại*. +* Nếu log trống, cửa sổ sẽ hiện **Không có log**. Hãy chờ lần chạy kết thúc rồi mở lại. +{% endhint %} + +### Chạy ngay + +Bấm **Chạy ngay**. Hộp thoại **Chạy retention policy ngay** cảnh báo rằng các artifact không được rule nào giữ lại sẽ bị xoá vĩnh viễn. Bạn có thể bấm **Chạy ngay** để tiếp tục, hoặc **Chạy thử** để kiểm tra trước. + +{% hint style="info" %} +Nút **Chạy ngay** và **Chạy thử** bị khoá cho tới khi repository có ít nhất một rule đang bật. +{% endhint %} + +### Theo dõi lần chạy + +Bảng **Lịch sử chạy** gồm các cột: + +| Cột | Ý nghĩa | +| --- | --- | +| Trạng thái | Đang chờ, Đã lên lịch, Đang chạy, Thành công, Đã dừng, Lỗi hoặc Thất bại | +| Chạy thử | Có nếu là chạy thử, Không nếu là chạy thật | +| Kiểu chạy | Thủ công (bạn bấm nút) hoặc Theo lịch | +| Thời gian bắt đầu | Thời điểm bắt đầu chạy | +| Thời lượng | Hiển thị khi lần chạy đã kết thúc | + +Trang tự làm mới mỗi 10 giây khi có lần chạy đang diễn ra. + +Bấm **Xem các tác vụ** để xem mỗi image một tác vụ, gồm trạng thái, **Giữ lại / Tổng**, thời gian bắt đầu và thời lượng. Bấm **Log** ở một tác vụ để đọc log retention của image đó. + +**Xoá thất bại.** Một tác vụ có thể hiện **Thành công** dù vẫn có artifact không xoá được. Khi đó tác vụ sẽ hiện cảnh báo *N artifact xoá thất bại*. Mở **Log** và tìm các dòng "Retention error for artifact" hoặc cột **Retention = ERR** để xem lý do. + +### Dừng lần chạy + +Bấm **Dừng** ở lần chạy đang chạy và xác nhận. Lần chạy sẽ dừng sau ít giây và chuyển sang trạng thái **Đã dừng**. Nếu lần chạy đã xong trước đó, kết quả được giữ nguyên. Các artifact đã bị xoá sẽ không được khôi phục. + +## Ví dụ + +| Mục tiêu | Cách đặt rule | Kết quả | +| --- | --- | --- | +| Giữ 10 bản build mới nhất của mọi image | Image khớp với `**` · giữ 10 artifact được push gần nhất cho mỗi image · tag khớp với `**` | Mỗi image giữ 10 artifact mới nhất; các artifact cũ hơn bị xoá | +| Giữ bản release mãi mãi, dọn bản build dev | Rule 1: image `**` · luôn giữ · tag khớp với `v*,release-*`. Rule 2: image `**` · giữ các artifact được push trong 14 ngày gần nhất · tag khớp với `**` | Tag release không bao giờ bị xoá; các tag khác được giữ 14 ngày | +| Chỉ xoá artifact không có tag | Rule 1: image `**` · giữ 0 artifact được push gần nhất cho mỗi image · tag `**` + bao gồm artifact không có tag. Rule 2: image `**` · luôn giữ · tag `**`, không bao gồm artifact không có tag | Mọi artifact có tag được giữ; artifact không có tag bị xoá | +| Chỉ dọn một image | Image khớp với `backend` · giữ 5 artifact được push gần nhất cho mỗi image · tag `**` | Chỉ `backend` được dọn; các image khác không bị đụng tới | +| Dọn mọi image trừ một image | Image loại trừ `base` · giữ 5 artifact được push gần nhất cho mỗi image · tag `**` | Mọi image trừ `base` được dọn | +| Giữ những gì còn được dùng | Image `**` · giữ các artifact được pull trong 30 ngày gần nhất · tag `**` | Artifact không được pull trong 30 ngày sẽ bị xoá | + +{% hint style="info" %} +Sau khi thêm hoặc sửa rule, hãy **Chạy thử** và kiểm tra cột **Giữ lại / Tổng** trước khi đặt lịch chạy. +{% endhint %} + +## Giới hạn + +| Mục | Giới hạn | +| --- | --- | +| Số retention policy mỗi repository | 1 | +| Số rule mỗi repository | 15 | +| Số lịch chạy mỗi repository | 1 | +| Số lượng / số ngày trong rule | 0 đến 10000 | +| Độ dài pattern | 1 đến 255 ký tự | +| Cron tuỳ chỉnh | 6 trường, giờ UTC, các lần chạy cách nhau ít nhất 1 giờ | +| Rule trùng nhau | Không cho phép | + +## Câu hỏi thường gặp + +**Có khôi phục được artifact đã xoá không?** Không. Artifact đã xoá không thể khôi phục. Luôn Chạy thử trước. + +**Vì sao lịch chạy dùng giờ UTC?** Registry chạy theo giờ UTC. Cộng thêm 7 giờ để ra giờ Việt Nam. Portal cũng hiển thị lịch chạy theo giờ của bạn. + +**Xoá một rule thì sao?** Rule bị xoá ngay. Lần chạy sau chỉ dùng các rule đang bật còn lại. + +**Có đặt lịch chạy trước khi thêm rule được không?** Được. Nhưng policy chỉ xoá artifact khi có ít nhất một rule đang bật, và Chạy ngay / Chạy thử cũng cần ít nhất một rule đang bật. + +**Vì sao tác vụ báo Thành công nhưng một số artifact vẫn còn?** Có thể một số artifact xoá thất bại. Xem cảnh báo *artifact xoá thất bại* ở tác vụ và đọc **Log**. Xem phần [Theo dõi lần chạy](#theo-doi-lan-chay).