7171 if '${{ github.ref_type }}' == 'tag':
7272 local_tag = join_tag(('ghcr.io', '${{ github.repository }}', version))
7373 else:
74- local_tag = join_tag(('localhost', '${{ github.repository }}', 'latest'))
74+ # Use ghcr tag for local testing so we can `docker pull` after pushing
75+ local_tag = join_tag(('ghcr.io', '${{ github.repository }}', 'latest'))
7576
7677 product = itertools.product(registries, repos, tags)
7778 tags_csv = ','.join(map(join_tag, product))
@@ -85,25 +86,53 @@ jobs:
8586 out.write(f'{k}={v}\n')
8687
8788 - uses : actions/checkout@v4
88- # QEMU is used for non-x86_64 builds
8989 - uses : docker/setup-qemu-action@v3
90- # buildx adds additional features to docker build
9190 - uses : docker/setup-buildx-action@v3
9291 with :
9392 driver-opts : network=host
9493
95- # Here, we want to do the docker build twice:
96- # The first build pushes to our local registry for testing.
97- # The second build pushes to Docker Hub and ghcr.io
98- - name : Build (local only)
99- uses : docker/build-push-action@v3
100- id : docker_build
94+ # Single-build flow to avoid filling runner disk with duplicate exports.
95+ - name : Build image for PR (load only)
96+ if : github.event_name == 'pull_request'
97+ uses : docker/build-push-action@v5
10198 with :
10299 context : .
103100 file : ./Dockerfile
104101 tags : ${{ steps.info.outputs.local_tag }}
105102 load : true
106103 cache-from : type=gha
104+ cache-to : type=gha,mode=max
105+
106+ - name : Login to DockerHub
107+ if : (github.event_name == 'push' || github.event_name == 'release') && contains(steps.info.outputs.tags_csv, 'docker.io')
108+ uses : docker/login-action@v3
109+ with :
110+ username : ${{ secrets.DOCKERHUB_USERNAME }}
111+ password : ${{ secrets.DOCKERHUB_PASSWORD }}
112+ - name : Login to GitHub Container Registry
113+ if : (github.event_name == 'push' || github.event_name == 'release') && contains(steps.info.outputs.tags_csv, 'ghcr.io')
114+ uses : docker/login-action@v3
115+ with :
116+ registry : ghcr.io
117+ username : ${{ github.repository_owner }}
118+ password : ${{ secrets.GITHUB_TOKEN }}
119+
120+ - name : Build and push
121+ uses : docker/build-push-action@v5
122+ if : (github.event_name == 'push' || github.event_name == 'release')
123+ with :
124+ context : .
125+ file : ./Dockerfile
126+ tags : ${{ steps.info.outputs.tags_csv }}
127+ platforms : linux/amd64 # add more architectures here if supported
128+ push : ${{ steps.info.outputs.push }}
129+ cache-from : type=gha
130+ cache-to : type=gha,mode=max
131+
132+ - name : Pull image for examples
133+ if : github.event_name != 'pull_request'
134+ run : docker pull ${{ steps.info.outputs.local_tag }}
135+
107136 # If you have a directory called examples/incoming/ and examples/outgoing/, then
108137 # run your ChRIS plugin with no parameters, and assert that it creates all the files
109138 # which are expected. File contents are not compared.
@@ -135,31 +164,6 @@ jobs:
135164 fi
136165 done
137166
138- - name : Login to DockerHub
139- if : (github.event_name == 'push' || github.event_name == 'release') && contains(steps.info.outputs.tags_csv, 'docker.io')
140- uses : docker/login-action@v3
141- with :
142- username : ${{ secrets.DOCKERHUB_USERNAME }}
143- password : ${{ secrets.DOCKERHUB_PASSWORD }}
144- - name : Login to GitHub Container Registry
145- if : (github.event_name == 'push' || github.event_name == 'release') && contains(steps.info.outputs.tags_csv, 'ghcr.io')
146- uses : docker/login-action@v3
147- with :
148- registry : ghcr.io
149- username : ${{ github.repository_owner }}
150- password : ${{ secrets.GITHUB_TOKEN }}
151- - name : Build and push
152- uses : docker/build-push-action@v5
153- if : (github.event_name == 'push' || github.event_name == 'release')
154- with :
155- context : .
156- file : ./Dockerfile
157- tags : ${{ steps.info.outputs.tags_csv }}
158- # if non-x86_84 architectures are supported, add them here
159- platforms : linux/amd64 # ,linux/arm64,linux/ppc64le
160- push : ${{ steps.info.outputs.push }}
161- cache-to : type=gha,mode=max
162-
163167 - name : Upload ChRIS Plugin
164168 id : upload
165169 if : github.ref_type == 'tag'
0 commit comments