Skip to content

Commit e16249b

Browse files
committed
👷 Docker push to GHCR
Also publish to the GitHub Container Registry as a fallback method, refs TODO-1887
1 parent ffe2dcf commit e16249b

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

.github/workflows/docker.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,59 @@ on:
66
workflow_dispatch:
77

88
env:
9-
IMAGE_NAME: kivy/buildozer
10-
SHOULD_PUBLISH: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) }}
9+
DOCKERHUB_IMAGE: kivy/buildozer
10+
GHCR_IMAGE: ghcr.io/${{ github.repository }}
11+
# TODO
12+
# SHOULD_PUBLISH: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) }}
13+
SHOULD_PUBLISH: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/feature/github_container_registry' || startsWith(github.ref, 'refs/tags/')) }}
1114

1215
jobs:
1316
build:
1417
runs-on: ubuntu-24.04
1518
timeout-minutes: 60
19+
permissions:
20+
contents: read
21+
packages: write
1622
steps:
1723
- uses: actions/checkout@v4
1824
- uses: docker/setup-buildx-action@v3
25+
26+
# Login to DockerHub
1927
- uses: docker/login-action@v3
2028
if: ${{ env.SHOULD_PUBLISH == 'true' }}
2129
with:
2230
username: ${{ secrets.DOCKERHUB_USERNAME }}
2331
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
# Login to GHCR
34+
- uses: docker/login-action@v3
35+
if: ${{ env.SHOULD_PUBLISH == 'true' }}
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
2441
- name: Build and Push Multi-platform Image
2542
uses: docker/build-push-action@v6
2643
with:
2744
push: ${{ env.SHOULD_PUBLISH == 'true' }}
28-
tags: ${{ env.IMAGE_NAME }}:latest
45+
tags: |
46+
${{ env.DOCKERHUB_IMAGE }}:latest
47+
${{ env.GHCR_IMAGE }}:latest
2948
platforms: linux/amd64,linux/arm64
30-
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:latest
31-
cache-to: ${{ env.SHOULD_PUBLISH == 'true' && format('type=registry,ref={0}:latest,mode=max', env.IMAGE_NAME) || '' }}
49+
cache-from: type=registry,ref=${{ env.DOCKERHUB_IMAGE }}:latest
50+
cache-to: ${{ env.SHOULD_PUBLISH == 'true' && format('type=registry,ref={0}:latest,mode=max', env.DOCKERHUB_IMAGE) || '' }}
51+
3252
- name: Local Build for Testing
3353
uses: docker/build-push-action@v6
3454
with:
3555
# Load image into local Docker daemon
3656
load: true
37-
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:latest
38-
tags: ${{ env.IMAGE_NAME }}:latest
57+
cache-from: type=registry,ref=${{ env.DOCKERHUB_IMAGE }}:latest
58+
tags: ${{ env.DOCKERHUB_IMAGE }}:latest
3959
# Run the locally built image to test it
4060
- name: Docker run
41-
run: docker run ${{ env.IMAGE_NAME }} --version
61+
run: docker run ${{ env.DOCKERHUB_IMAGE }} --version
4262

4363
update-readme:
4464
runs-on: ubuntu-24.04
@@ -50,5 +70,5 @@ jobs:
5070
with:
5171
username: ${{ secrets.DOCKERHUB_USERNAME }}
5272
password: ${{ secrets.DOCKERHUB_TOKEN }}
53-
repository: ${{ env.IMAGE_NAME }}
73+
repository: ${{ env.DOCKERHUB_IMAGE }}
5474
readme-filepath: README.md

0 commit comments

Comments
 (0)