|
| 1 | +<!-- header:start --> |
| 2 | + |
| 3 | +#  GitHub Action: Docker - Clean images |
| 4 | + |
| 5 | +<div align="center"> |
| 6 | + <img src="../../../.github/logo.svg" width="60px" align="center" alt="Docker - Clean images" /> |
| 7 | +</div> |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +<!-- header:end --> |
| 12 | + |
| 13 | +<!-- badges:start --> |
| 14 | + |
| 15 | +[](https://github.com/marketplace/actions/docker---clean-images) |
| 16 | +[](https://github.com/hoverkraft-tech/ci-github-container/releases) |
| 17 | +[](http://choosealicense.com/licenses/mit/) |
| 18 | +[](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-container?style=social) |
| 19 | +[](https://github.com/hoverkraft-tech/ci-github-container/blob/main/CONTRIBUTING.md) |
| 20 | + |
| 21 | +<!-- badges:end --> |
| 22 | + |
| 23 | +<!-- overview:start --> |
| 24 | + |
| 25 | +## Overview |
| 26 | + |
| 27 | +Action to clean up container images from GitHub Container Registry (ghcr.io). |
| 28 | +This is a wrapper around the ghcr-cleanup-action that provides a consistent interface |
| 29 | +for image cleanup operations including deleting untagged images, pruning old tags, |
| 30 | +and managing image lifecycle. |
| 31 | + |
| 32 | +<!-- overview:end --> |
| 33 | + |
| 34 | +## Permissions |
| 35 | + |
| 36 | +Set permissions to write packages. This is required to delete images. |
| 37 | + |
| 38 | +```yaml |
| 39 | +permissions: |
| 40 | + packages: write |
| 41 | +``` |
| 42 | +
|
| 43 | +<!-- usage:start --> |
| 44 | +
|
| 45 | +## Usage |
| 46 | +
|
| 47 | +```yaml |
| 48 | +- uses: hoverkraft-tech/ci-github-container/actions/docker/clean-images@c5d2c29ccdc9d357ea7b0e8e2567fa4643c05758 # copilot/refactor-cleanup-action-architecture |
| 49 | + with: |
| 50 | + # Comma-separated list of packages to cleanup. |
| 51 | + # Example: "application-1,application-2" |
| 52 | + # |
| 53 | + # This input is required. |
| 54 | + package: "" |
| 55 | + |
| 56 | + # Comma-separated list of tags to delete (supports wildcard syntax). |
| 57 | + # Example: `pr-*,dev` |
| 58 | + # |
| 59 | + # This input is required. |
| 60 | + tags: "" |
| 61 | + |
| 62 | + # GitHub token with the packages:write and packages:delete scopes. |
| 63 | + # See https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registries. |
| 64 | + # |
| 65 | + # Default: `${{ github.token }}` |
| 66 | + github-token: ${{ github.token }} |
| 67 | +``` |
| 68 | +
|
| 69 | +<!-- usage:end --> |
| 70 | +
|
| 71 | +<!-- inputs:start --> |
| 72 | +
|
| 73 | +## Inputs |
| 74 | +
|
| 75 | +| **Input** | **Description** | **Required** | **Default** | |
| 76 | +| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------------------- | |
| 77 | +| **`package`** | Comma-separated list of packages to cleanup. | **true** | - | |
| 78 | +| | Example: "application-1,application-2" | | | |
| 79 | +| **`tags`** | Comma-separated list of tags to delete (supports wildcard syntax). | **true** | - | |
| 80 | +| | Example: `pr-*,dev` | | | |
| 81 | +| **`github-token`** | GitHub token with the packages:write and packages:delete scopes. | **false** | `$\{\{ github.token }}` | |
| 82 | +| | See <https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registries>. | | | |
| 83 | + |
| 84 | +<!-- inputs:end --> |
| 85 | + |
| 86 | +<!-- secrets:start --> |
| 87 | +<!-- secrets:end --> |
| 88 | + |
| 89 | +<!-- outputs:start --> |
| 90 | + |
| 91 | +## Outputs |
| 92 | + |
| 93 | +| **Output** | **Description** | |
| 94 | +| ------------------------------ | --------------------------------------- | |
| 95 | +| **`deleted-package-ids`** | The package IDs that were deleted. | |
| 96 | +| **`deleted-package-versions`** | The package versions that were deleted. | |
| 97 | + |
| 98 | +<!-- outputs:end --> |
| 99 | + |
| 100 | +<!-- examples:start --> |
| 101 | + |
| 102 | +## Examples |
| 103 | + |
| 104 | +### Clean up pull request images |
| 105 | + |
| 106 | +Delete images tagged with a pull request pattern after the PR is closed: |
| 107 | + |
| 108 | +```yaml |
| 109 | +name: Clean PR Images |
| 110 | +on: |
| 111 | + pull_request: |
| 112 | + types: [closed] |
| 113 | +
|
| 114 | +jobs: |
| 115 | + cleanup: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + permissions: |
| 118 | + packages: write |
| 119 | + steps: |
| 120 | + - uses: hoverkraft-tech/ci-github-container/actions/docker/clean-images@c5d2c29ccdc9d357ea7b0e8e2567fa4643c05758 # copilot/refactor-cleanup-action-architecture |
| 121 | + with: |
| 122 | + package: my-app |
| 123 | + delete-tags: pr-${{ github.event.pull_request.number }}-* |
| 124 | +``` |
| 125 | + |
| 126 | +### Clean up untagged images |
| 127 | + |
| 128 | +Remove all untagged images to save storage: |
| 129 | + |
| 130 | +```yaml |
| 131 | +name: Clean Untagged Images |
| 132 | +on: |
| 133 | + schedule: |
| 134 | + - cron: "0 3 * * *" # Daily at 3 AM |
| 135 | +
|
| 136 | +jobs: |
| 137 | + cleanup: |
| 138 | + runs-on: ubuntu-latest |
| 139 | + permissions: |
| 140 | + packages: write |
| 141 | + steps: |
| 142 | + - uses: hoverkraft-tech/ci-github-container/actions/docker/clean-images@c5d2c29ccdc9d357ea7b0e8e2567fa4643c05758 # copilot/refactor-cleanup-action-architecture |
| 143 | + with: |
| 144 | + package: my-app |
| 145 | + delete-untagged: true |
| 146 | +``` |
| 147 | + |
| 148 | +<!-- examples:end --> |
| 149 | + |
| 150 | +<!-- |
| 151 | +// jscpd:ignore-start |
| 152 | +--> |
| 153 | + |
| 154 | +<!-- contributing:start --> |
| 155 | + |
| 156 | +## Contributing |
| 157 | + |
| 158 | +Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/ci-github-container/blob/main/CONTRIBUTING.md) for more details. |
| 159 | + |
| 160 | +<!-- contributing:end --> |
| 161 | + |
| 162 | +<!-- security:start --> |
| 163 | +<!-- security:end --> |
| 164 | + |
| 165 | +<!-- license:start --> |
| 166 | + |
| 167 | +## License |
| 168 | + |
| 169 | +This project is licensed under the MIT License. |
| 170 | + |
| 171 | +SPDX-License-Identifier: MIT |
| 172 | + |
| 173 | +Copyright © 2025 hoverkraft |
| 174 | + |
| 175 | +For more details, see the [license](http://choosealicense.com/licenses/mit/). |
| 176 | + |
| 177 | +<!-- license:end --> |
| 178 | + |
| 179 | +<!-- generated:start --> |
| 180 | + |
| 181 | +--- |
| 182 | + |
| 183 | +This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor). |
| 184 | + |
| 185 | +<!-- generated:end --> |
| 186 | + |
| 187 | +<!-- |
| 188 | +// jscpd:ignore-end |
| 189 | +--> |
0 commit comments