1111- Provide multiple pruning strategies including a new "keep latest N images" option
1212- Better error handling and logging
1313
14- ## Architecture
15-
16- ### File Structure
17-
18- ``` plaintext
19- scripts/prune/
20- ├── main.py # Main CLI script
21- ├── strategies.py # Pruning strategy implementations
22- ├── requirements.txt # Python dependencies
23- └── registries/
24- ├── __init__.py
25- ├── base.py # Abstract base classes
26- ├── factory.py # Registry factory
27- ├── ghcr.py # GitHub Container Registry implementation
28- └── dockerhub.py # Docker Hub implementation
29- ```
30-
31- ### Registry Implementations
14+ ## Usage Examples
3215
33- - ** GHCRRegistry** : Uses GitHub API with token authentication
34- - ** DockerHubRegistry** : Uses Docker Hub API with username/password authentication
16+ ### Environment Variables
3517
36- ### Pruning Strategies
18+ To use the script, you need to set up environment variables for authentication. The script supports both Docker Hub and GitHub Container Registry.
3719
38- 1 . ** PruneUntaggedByAge** : Delete untagged images older than specified days
39- 2 . ** PruneAllUntagged** : Delete all untagged images
40- 3 . ** KeepLatestCount** : Keep only the latest N images (NEW)
20+ #### Docker Hub
4121
42- ## Usage Examples
22+ ``` bash
23+ export DOCKER_USERNAME=< your_docker_username>
24+ export DOCKER_PASSWORD=< your_docker_password_or_token>
25+ ```
4326
44- ### Environment Variables
27+ #### GitHub Container Registry
4528
4629``` bash
47- # For GitHub Container Registry
4830export GHCR_TOKEN=< your_github_token>
49-
50- # For Docker Hub
51- export DOCKER_USERNAME=< your_docker_username>
52- export DOCKER_PASSWORD=< your_docker_password_or_token>
5331```
5432
5533### Command Examples
@@ -84,11 +62,11 @@ The script is integrated into two GitHub Actions workflows:
8462
8563### Production Usage (` cd.yml ` )
8664
87- The script runs after successful image builds to clean up old untagged images:
65+ The script runs after successful image builds to clean up old images:
8866
8967``` yaml
90- - name : Prune old untagged images
91- run : python scripts/prune/main.py --container ${{ env.IMAGE_NAME }} --registry all --prune-untagged-age 7 --verbose
68+ - name : Prune old images
69+ run : python scripts/prune/main.py --container ${{ env.IMAGE_NAME }} --registry all --keep-latest 25 --verbose
9270` ` `
9371
9472### Automated Testing (` test-prune-script.yml`)
@@ -122,7 +100,7 @@ The script includes a comprehensive test suite to ensure reliability and correct
122100
123101` ` ` plaintext
124102tests/
125- ├── README.md # Testing documentation
103+ ├── README.md # Testing documentation
126104├── __init__.py # Package initialization
127105├── test_prune.py # Comprehensive unit tests (20 tests)
128106├── test_integration.py # Integration tests (7 tests)
@@ -134,10 +112,10 @@ tests/
134112**From the prune script root directory:**
135113
136114` ` ` bash
137- python test_runner.py # Master test runner
115+ python test_runner.py # Master test runner
138116` ` `
139117
140- **** From the tests directory:**
118+ **From the tests directory:**
141119
142120` ` ` bash
143121python tests/run_all_tests.py # Run all test suites
@@ -156,12 +134,3 @@ The test suite covers:
156134- ✅ Dry-run functionality
157135- ✅ Multi-registry support
158136- ✅ Authentication handling
159-
160- # ## Test Results
161-
162- All tests are currently passing :
163-
164- - 20/20 unit tests passed
165- - 7/7 integration tests passed
166-
167- Run the test suite with `python test_runner.py` to generate current results.
0 commit comments