Skip to content

Commit 8c4f568

Browse files
committed
ci: cache container images to GitHub Container Registry
These image builds have been reliably failing recently. Not sure why. More upstream rate limiting? Let's add container registry based caching to image builds using the GitHub Container Registry.
1 parent 7a68aa0 commit 8c4f568

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

.github/workflows/linux.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
- xcb
5353
- xcb.cross
5454
runs-on: ubuntu-22.04
55+
permissions:
56+
packages: write
5557
steps:
5658
- uses: actions/checkout@v3
5759

@@ -60,9 +62,41 @@ jobs:
6062
with:
6163
python-version: '3.11'
6264

65+
- name: Set up Docker Buildx
66+
uses: docker/setup-buildx-action@v2
67+
68+
- name: Login to GitHub Container Registry
69+
uses: docker/login-action@v2
70+
with:
71+
registry: ghcr.io
72+
username: ${{ github.actor }}
73+
password: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Generate Dockerfiles
76+
run: |
77+
./build-linux.py --make-target empty
78+
6379
- name: Build Image
80+
uses: docker/build-push-action@v4
81+
with:
82+
context: .
83+
file: build/${{ matrix.image }}.Dockerfile
84+
labels: org.opencontainers.image.source=https://github.com/${{ github.repository }}
85+
# Cache from/to the current branch of the current repo as the primary cache key.
86+
# Cache from the default branch of the current repo so branches can have cache hits.
87+
# Cache from the default branch of the canonical repo so forks can have cache hits.
88+
# Ignore errors on cache writes so CI of forks works without a valid GHCR config.
89+
cache-from: |
90+
type=registry,ref=ghcr.io/indygreg/${{ github.repository }}:${{ matrix.image }}-${{ github.ref_name }}
91+
type=registry,ref=ghcr.io/indygreg/${{ github.repository }}:${{ matrix.image }}-main
92+
type=registry,ref=ghcr.io/indygreg/python-build-standalone:${{ matrix.image }}-main
93+
cache-to: |
94+
type=registry,ref=ghcr.io/indygreg/${{ github.repository }}:${{ matrix.image }}-${{ github.ref_name }},ignore-errors=true
95+
outputs: |
96+
type=docker,dest=build/image-${{ matrix.image }}.tar
97+
98+
- name: Compress Image
6499
run: |
65-
./build-linux.py --make-target toolchain-image-${{ matrix.image }}
66100
zstd -v -T0 -6 --rm build/image-*.tar
67101
68102
- name: Upload Docker Image

0 commit comments

Comments
 (0)