|
| 1 | +# Docker Image Caching Action |
| 2 | + |
| 3 | +This action provides intelligent Docker image caching to avoid rate limiting issues from Docker registries, particularly useful for ECR Public Registry and Docker Hub. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🗂️ **Smart Caching**: Automatically generates cache keys based on image names |
| 8 | +- 🔄 **Incremental Updates**: Merges new images with existing cache |
| 9 | +- ⚡ **Fast Restoration**: Loads cached images before attempting pulls |
| 10 | +- 🛡️ **Rate Limit Protection**: Includes retry logic and specific ECR error handling |
| 11 | +- 📊 **Detailed Reporting**: Provides comprehensive cache hit/miss reporting |
| 12 | +- 🔍 **AutoKitteh Updates**: Intelligent version checking and automatic updates for AutoKitteh images |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +### Basic Usage |
| 17 | + |
| 18 | +```yaml |
| 19 | +- name: Cache Docker Images |
| 20 | + uses: ./.github/actions/cache-docker-images |
| 21 | + with: |
| 22 | + cache-key: "my-project-images" |
| 23 | + images: "postgres:15-alpine,temporalio/auto-setup:1.24.2,public.ecr.aws/autokitteh/server:latest" |
| 24 | +``` |
| 25 | +
|
| 26 | +### Advanced Usage |
| 27 | +
|
| 28 | +```yaml |
| 29 | +- name: Cache Docker Images |
| 30 | + id: docker-cache |
| 31 | + uses: ./.github/actions/cache-docker-images |
| 32 | + with: |
| 33 | + cache-key: "test-env-images-v2" |
| 34 | + images: "postgres:15-alpine,temporalio/auto-setup:${{ matrix.temporal-version }},public.ecr.aws/autokitteh/server:latest" |
| 35 | + restore-only: "false" |
| 36 | + |
| 37 | +- name: Check cache results |
| 38 | + run: | |
| 39 | + echo "Cache hit: ${{ steps.docker-cache.outputs.cache-hit }}" |
| 40 | + echo "Loaded images: ${{ steps.docker-cache.outputs.images-loaded }}" |
| 41 | +``` |
| 42 | +
|
| 43 | +### AutoKitteh Update Checking |
| 44 | +
|
| 45 | +```yaml |
| 46 | +- name: Cache Docker Images with AutoKitteh Updates |
| 47 | + id: docker-cache |
| 48 | + uses: ./.github/actions/cache-docker-images |
| 49 | + with: |
| 50 | + cache-key: "test-env-images-v2" |
| 51 | + images: "postgres:15-alpine,public.ecr.aws/autokitteh/server:v1.2.3" |
| 52 | + check-updates: "true" |
| 53 | + |
| 54 | +- name: Check what was updated |
| 55 | + run: | |
| 56 | + echo "Cache hit: ${{ steps.docker-cache.outputs.cache-hit }}" |
| 57 | + echo "Loaded images: ${{ steps.docker-cache.outputs.images-loaded }}" |
| 58 | + echo "Updated images: ${{ steps.docker-cache.outputs.updated-images }}" |
| 59 | +``` |
| 60 | +
|
| 61 | +## Inputs |
| 62 | +
|
| 63 | +| Input | Description | Required | Default | |
| 64 | +|-------|-------------|----------|---------| |
| 65 | +| `cache-key` | Base cache key for the Docker images | No | `"docker-images"` | |
| 66 | +| `images` | Comma-separated list of Docker images to cache | Yes | - | |
| 67 | +| `restore-only` | Only restore cache, don't save new cache | No | `"false"` | |
| 68 | +| `check-updates` | Check for AutoKitteh updates and pull newer versions | No | `"false"` | |
| 69 | + |
| 70 | +## Outputs |
| 71 | + |
| 72 | +| Output | Description | |
| 73 | +|--------|-------------| |
| 74 | +| `cache-hit` | Whether the cache was restored (`"true"` or `"false"`) | |
| 75 | +| `images-loaded` | Comma-separated list of images loaded from cache | |
| 76 | +| `updated-images` | Comma-separated list of AutoKitteh images that were updated | |
| 77 | + |
| 78 | +## How It Works |
| 79 | + |
| 80 | +1. **Cache Key Generation**: Creates a unique cache key based on image names and runner OS |
| 81 | +2. **Cache Restoration**: Attempts to restore previously cached Docker images |
| 82 | +3. **Image Loading**: Loads cached images using `docker load` |
| 83 | +4. **Missing Image Detection**: Identifies which images need to be pulled |
| 84 | +5. **Smart Pulling**: Only pulls missing images with retry logic |
| 85 | +6. **AutoKitteh Update Checking**: (Optional) Checks GitHub releases for newer AutoKitteh versions |
| 86 | +7. **Intelligent Updates**: Only pulls AutoKitteh images if a newer version is available |
| 87 | +8. **Cache Saving**: Saves newly pulled images to cache for future runs |
| 88 | + |
| 89 | +## Integration with Existing Workflows |
| 90 | + |
| 91 | +### Replace existing Docker pulls |
| 92 | + |
| 93 | +**Before:** |
| 94 | +```yaml |
| 95 | +- name: Pull Docker images |
| 96 | + run: | |
| 97 | + docker pull postgres:15-alpine |
| 98 | + docker pull temporalio/auto-setup:1.24.2 |
| 99 | + docker pull public.ecr.aws/autokitteh/server:latest |
| 100 | +``` |
| 101 | + |
| 102 | +**After:** |
| 103 | +```yaml |
| 104 | +- name: Cache and pull Docker images |
| 105 | + uses: ./.github/actions/cache-docker-images |
| 106 | + with: |
| 107 | + cache-key: "my-workflow-images-v1" |
| 108 | + images: "postgres:15-alpine,temporalio/auto-setup:1.24.2,public.ecr.aws/autokitteh/server:latest" |
| 109 | +``` |
| 110 | + |
| 111 | +### Use in matrix builds |
| 112 | + |
| 113 | +```yaml |
| 114 | +strategy: |
| 115 | + matrix: |
| 116 | + browser: [Chrome, Firefox, Safari] |
| 117 | + |
| 118 | +steps: |
| 119 | + - name: Cache Docker images for ${{ matrix.browser }} |
| 120 | + uses: ./.github/actions/cache-docker-images |
| 121 | + with: |
| 122 | + cache-key: "test-images-${{ matrix.browser }}-v1" |
| 123 | + images: "postgres:15-alpine,temporalio/auto-setup:1.24.2,public.ecr.aws/autokitteh/server:latest" |
| 124 | +``` |
| 125 | + |
| 126 | +## Benefits |
| 127 | + |
| 128 | +- **Reduces Rate Limiting**: Avoids repeated pulls from registries |
| 129 | +- **Faster Builds**: Cached images load much faster than network pulls |
| 130 | +- **Cost Savings**: Reduces bandwidth usage in CI/CD |
| 131 | +- **Reliability**: Builds continue even if registries have temporary issues |
| 132 | +- **Smart Updates**: Only pulls AutoKitteh images when there's actually a new version |
| 133 | +- **Version Awareness**: Automatically tracks and compares semantic versions |
| 134 | + |
| 135 | +## Cache Behavior |
| 136 | + |
| 137 | +- **Cache Duration**: GitHub Actions cache retention (up to 7 days by default) |
| 138 | +- **Cache Size**: Compressed Docker images (typically 50-80% smaller) |
| 139 | +- **Cache Scope**: Per repository and branch |
| 140 | +- **Cache Keys**: Include image names hash to ensure consistency |
| 141 | + |
| 142 | +## Error Handling |
| 143 | + |
| 144 | +The action includes specific error handling for: |
| 145 | +- ECR Public Registry rate limits |
| 146 | +- Docker Hub rate limits |
| 147 | +- Network timeouts |
| 148 | +- Corrupted cache files |
| 149 | +- Missing images |
| 150 | + |
| 151 | +## Troubleshooting |
| 152 | + |
| 153 | +### Cache misses frequently |
| 154 | +- Check if image tags are changing (use specific tags instead of `latest`) |
| 155 | +- Verify cache key consistency across runs |
| 156 | +- Consider cache size limits (10GB per repository) |
| 157 | + |
| 158 | +### Images fail to load from cache |
| 159 | +- Cache may be corrupted - action will fall back to pulling |
| 160 | +- Check Docker daemon status |
| 161 | +- Verify sufficient disk space |
| 162 | + |
| 163 | +### Rate limiting still occurs |
| 164 | +- Increase retry attempts in the action |
| 165 | +- Consider using authenticated registry access |
| 166 | +- Use alternative registries or mirrors |
| 167 | + |
| 168 | +## AutoKitteh Update Feature |
| 169 | + |
| 170 | +When `check-updates: "true"` is enabled, the action will: |
| 171 | +
|
| 172 | +1. **Check GitHub Releases**: Queries the AutoKitteh repository for the latest release |
| 173 | +2. **Version Comparison**: Compares current image version with the latest release |
| 174 | +3. **Smart Updates**: Only pulls if a newer version is available |
| 175 | +4. **Cache Updates**: Automatically updates the cache with new versions |
| 176 | +5. **Detailed Reporting**: Reports which images were updated |
| 177 | +
|
| 178 | +### Supported AutoKitteh Image Formats |
| 179 | +
|
| 180 | +- `public.ecr.aws/autokitteh/server:v1.2.3` - Specific version |
| 181 | +- `public.ecr.aws/autokitteh/server:latest` - Always checks for updates |
| 182 | +- Any image containing "autokitteh" in the name |
| 183 | + |
| 184 | +## Version History |
| 185 | + |
| 186 | +- **v1.0**: Initial release with basic caching |
| 187 | +- **v1.1**: Added retry logic and ECR-specific error handling |
| 188 | +- **v1.2**: Improved cache merging and cleanup |
| 189 | +- **v1.3**: Added intelligent AutoKitteh version checking and updates |
0 commit comments