-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e46ecd7
commit 62b968c
Showing
3 changed files
with
263 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,113 @@ | ||
# DigitalOcean Registry Cleanup Action | ||
|
||
This action deletes tags older than a specified number of days from a | ||
DigitalOcean container registry, excluding the "latest" tag. Before using this | ||
action, ensure you've set up `doctl` and authenticated with DigitalOcean. | ||
This action helps manage tags in a DigitalOcean container registry by providing flexible cleanup options. It can delete tags based on age and/or keep a specific number of recent tags. The action always preserves the "latest" tag. | ||
|
||
## Features | ||
|
||
- Delete tags older than a specified number of days | ||
- Keep a specified number of most recent tags | ||
- Safety check to prevent accidental deletion of all images | ||
- Dry run mode to preview changes | ||
- Preserves the "latest" tag | ||
|
||
## Inputs | ||
|
||
### `repository_name` | ||
**Required**. Name of the DigitalOcean container registry repository. | ||
|
||
Name of the DigitalOcean container registry repository. Required. | ||
|
||
### `dry_run` | ||
### `days` | ||
Number of days. Tags older than these many days will be deleted. | ||
- Default: "2" | ||
- Optional | ||
|
||
If set to true, it will display tags to be deleted without actually deleting | ||
them. Default is "false". | ||
### `keep_last` | ||
Number of most recent tags to keep, regardless of age. | ||
- Optional | ||
- Example: "3" will keep the three most recent tags | ||
|
||
### `days` | ||
### `dry_run` | ||
If set to true, shows what would be deleted without making any changes. | ||
- Default: "false" | ||
- Optional | ||
|
||
Number of days. Tags older than these many days will be deleted. Default is "2". | ||
### `bypass_safety` | ||
Bypass the safety check that prevents deletion when no recent images exist. | ||
- Default: "false" | ||
- Optional | ||
|
||
## Example usage | ||
## Usage Examples | ||
|
||
```yml | ||
### Basic Usage | ||
```yaml | ||
- name: Install doctl | ||
uses: digitalocean/action-doctl@v2 | ||
with: | ||
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | ||
|
||
- name: Log in to DigitalOcean Container Registry with short-lived credentials | ||
- name: Log in to DigitalOcean Container Registry | ||
run: doctl registry login --expiry-seconds 1200 | ||
|
||
- uses: raisedadead/action-docr-cleanup@v1 | ||
- name: Cleanup Registry | ||
uses: raisedadead/action-docr-cleanup@v1 | ||
with: | ||
repository_name: 'your-repository-name' | ||
dry_run: 'true' | ||
days: '7' | ||
``` | ||
## Manual run: | ||
### Keep Recent Tags | ||
```yaml | ||
- uses: raisedadead/action-docr-cleanup@v1 | ||
with: | ||
repository_name: 'your-repository-name' | ||
days: '7' | ||
keep_last: '3' # Keep 3 most recent tags | ||
``` | ||
Assuming you have | ||
[doctl installed](https://docs.digitalocean.com/reference/doctl/) and | ||
authenticated with your user, you can run the following commands: | ||
### Dry Run Mode | ||
```yaml | ||
- uses: raisedadead/action-docr-cleanup@v1 | ||
with: | ||
repository_name: 'your-repository-name' | ||
days: '7' | ||
dry_run: 'true' # Preview changes without deleting | ||
``` | ||
```bash | ||
doctl registry login --expiry-seconds 1200 | ||
### Bypass Safety Check | ||
```yaml | ||
- uses: raisedadead/action-docr-cleanup@v1 | ||
with: | ||
repository_name: 'your-repository-name' | ||
days: '7' | ||
bypass_safety: 'true' # Disable safety checks | ||
``` | ||
For help on the script: | ||
## Manual Usage | ||
You can also run the script directly after installing [doctl](https://docs.digitalocean.com/reference/doctl/) and authenticating: | ||
```bash | ||
./entrypoint.sh -h | ||
``` | ||
# Login to registry | ||
doctl registry login --expiry-seconds 1200 | ||
|
||
To run the script in dry-run mode: | ||
# View help | ||
./entrypoint.sh -h | ||
|
||
```bash | ||
./entrypoint.sh -d -n <number of days> <repository-name> | ||
``` | ||
# Dry run with 7-day threshold | ||
./entrypoint.sh -d -n 7 your-repository-name | ||
|
||
To run the script: | ||
# Keep 3 most recent tags, delete others older than 7 days | ||
./entrypoint.sh -n 7 --keep-last 3 your-repository-name | ||
|
||
```bash | ||
./entrypoint.sh -n <number of days> <repository-name> | ||
# Bypass safety check | ||
./entrypoint.sh -n 7 -b your-repository-name | ||
``` | ||
|
||
example: | ||
## Safety Features | ||
|
||
```bash | ||
./entrypoint.sh -n 1 myapp | ||
``` | ||
1. The "latest" tag is always preserved | ||
2. By default, the action won't delete tags if no images newer than the threshold exist | ||
3. Dry run mode allows previewing changes before actual deletion | ||
|
||
## License | ||
|
||
Software: The software as it is licensed under the [MIT](LICENSE) License, | ||
please feel free to extend, re-use, share the code. | ||
Licensed under the [MIT](LICENSE) License. Feel free to extend, reuse, and share. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
name: 'DigitalOcean Registry Cleanup Action' | ||
description: 'Deletes tags older than a specified number of days from a DigitalOcean container registry' | ||
author: 'Mrugesh Mohapatra' | ||
name: "DigitalOcean Registry Cleanup Action" | ||
description: "Deletes tags from a DigitalOcean container registry based on age and count criteria" | ||
author: "Mrugesh Mohapatra" | ||
branding: | ||
icon: 'trash' | ||
color: 'red' | ||
icon: "trash" | ||
color: "red" | ||
inputs: | ||
repository_name: | ||
description: 'Name of the DigitalOcean container registry repository' | ||
description: "Name of the DigitalOcean container registry repository" | ||
required: true | ||
dry_run: | ||
description: 'If set to true, it will display tags to be deleted without actually deleting them' | ||
description: "If true, shows what would be deleted without making any changes" | ||
required: false | ||
default: 'false' | ||
default: "false" | ||
days: | ||
description: 'Number of days. Tags older than these many days will be deleted' | ||
description: "Delete tags older than these many days" | ||
required: false | ||
default: "2" | ||
bypass_safety: | ||
description: "Bypass the safety check that prevents deletion when no recent images exist" | ||
required: false | ||
default: "false" | ||
keep_last: | ||
description: "Number of most recent tags to keep, regardless of age" | ||
required: false | ||
default: '2' | ||
|
||
runs: | ||
using: 'composite' | ||
using: "composite" | ||
steps: | ||
- run: $GITHUB_ACTION_PATH/entrypoint.sh ${{ inputs.dry_run == 'true' && '-d' || '' }} -n ${{ inputs.days }} ${{ inputs.repository_name }} | ||
- run: | | ||
$GITHUB_ACTION_PATH/entrypoint.sh \ | ||
${{ inputs.dry_run == 'true' && '-d' || '' }} \ | ||
-n ${{ inputs.days }} \ | ||
${{ inputs.bypass_safety == 'true' && '-b' || '' }} \ | ||
${{ inputs.keep_last && format('--keep-last {0}', inputs.keep_last) || '' }} \ | ||
${{ inputs.repository_name }} | ||
shell: bash |
Oops, something went wrong.