Skip to content

Commit 164dc01

Browse files
authored
ci: cache docker images on main and use in PR builds (#34841)
### Reason for this change > ECR Public repo allows 1 request/second for un-authenticated pulls and 10 request/second for authenticated pulls. We try to avoid making requests to any repos by caching the used image as much as possible. We do this on builds on main as a baseline and restore the cache on PRs. This assumes that most PRs won't add new images and adding new images is rare enough. ### Description of changes Add a cache for docker images. ### Describe any new or updated permissions being added None. ### Description of how you validated changes Run the commands manually. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4c75889 commit 164dc01

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

.github/workflows/pr-build.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,24 @@ jobs:
3232
- name: Set up Docker
3333
uses: docker/setup-buildx-action@v3
3434

35-
# @TODO
36-
# - name: Start ECR proxy
37-
# run: /root/ecr-proxy/start.sh
35+
- name: Load Docker images
36+
id: docker-cache
37+
uses: actions/cache/restore@v4
38+
with:
39+
path: |
40+
~/.docker-images.tar
41+
key: docker-cache-${{ runner.os }}
42+
43+
- name: Restore Docker images
44+
if: ${{ steps.docker-cache.outputs.cache-hit }}
45+
run: docker image load --input ~/.docker-images.tar
3846

3947
- name: Cache build artifacts
4048
uses: actions/cache@v4
4149
with:
4250
path: |
4351
~/.s3buildcache
44-
key: ${{ runner.os }}-${{ github.event.pull_request.base.ref }}-s3buildcache
52+
key: s3buildcache-${{ runner.os }}
4553

4654
- name: Configure system settings
4755
run: |
@@ -56,3 +64,15 @@ jobs:
5664

5765
- name: Check for uncommitted changes
5866
run: git diff-index --exit-code --ignore-space-at-eol --stat HEAD
67+
68+
- name: Export Docker images
69+
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
70+
run: docker image save --output ~/.docker-images.tar $(docker image list --format '{{ if ne .Repository "<none>" }}{{ .Repository }}{{ if ne .Tag "<none>" }}:{{ .Tag }}{{ end }}{{ else }}{{ .ID }}{{ end }}')
71+
72+
- name: Cache Docker images
73+
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
74+
uses: actions/cache/save@v4
75+
with:
76+
path: |
77+
~/.docker-images.tar
78+
key: docker-cache-${{ runner.os }}

0 commit comments

Comments
 (0)