@@ -63,13 +63,9 @@ inputs:
63
63
default : ' false'
64
64
description : ' Generate tag only.'
65
65
required : false
66
- CACHE_FROM :
67
- default : ' type=gha'
68
- description : ' Cache from.'
69
- required : false
70
- CACHE_TO :
71
- default : ' type=gha,mode=max'
72
- description : ' Cache to.'
66
+ ENABLE_CACHE :
67
+ default : ' false'
68
+ description : ' Whether to use cache when building the image'
73
69
required : false
74
70
outputs :
75
71
IMAGE_TAG :
@@ -126,15 +122,31 @@ runs:
126
122
run : echo BUILD_ARGS=${{inputs.BUILD_ARGS}} >> $GITHUB_ENV
127
123
shell : bash
128
124
129
- - name : Build and export to Docker
125
+ - name : Build and export to Docker without cache
130
126
uses : docker/build-push-action@v6
131
- if : inputs.TAG_ONLY == 'false'
127
+ if : inputs.ENABLE_CACHE == 'false'
128
+ with :
129
+ load : true
130
+ tags : |
131
+ ${{ steps.meta.outputs.tags }}
132
+ no-cache : true
133
+ file : ${{ inputs.FILE }}
134
+ context : ${{ inputs.CONTEXT }}
135
+ # cannot use multiple platforms with `load`, build a single arch image for validation purposes in CI
136
+ platforms : linux/amd64
137
+ build-args : ${{ env.BUILD_ARGS }}
138
+ secrets : ${{ env.DOCKER_SECRETS }}
139
+
140
+ - name : Build and export to Docker with cache
141
+ uses : docker/build-push-action@v6
142
+ if : inputs.ENABLE_CACHE == 'true'
132
143
with :
133
144
load : true
134
145
tags : |
135
146
${{ steps.meta.outputs.tags }}
136
- # cache-from: type=gha
137
- # cache-to: type=gha,mode=max
147
+ cache-from : type=gha
148
+ cache-to : type=gha,mode=max
149
+ no-cache : false
138
150
file : ${{ inputs.FILE }}
139
151
context : ${{ inputs.CONTEXT }}
140
152
# cannot use multiple platforms with `load`, build a single arch image for validation purposes in CI
@@ -155,16 +167,31 @@ runs:
155
167
docker logs test
156
168
${{ inputs.CONTAINER_TEST_COMMAND }}
157
169
158
- - name : Build and push
159
- if : inputs.PUSH == 'true' # && inputs.TAG_ONY == 'false'
170
+ - name : Build and push with cache
171
+ if : inputs.PUSH == 'true' && inputs.ENABLE_CACHE == 'true'
172
+ uses : docker/build-push-action@v6
173
+ with :
174
+ push : true
175
+ tags : |
176
+ ${{ steps.meta.outputs.tags }}
177
+ cache-from : type=gha
178
+ cache-to : type=gha,mode=max
179
+ no-cache : false
180
+ file : ${{ inputs.FILE }}
181
+ context : ${{ inputs.CONTEXT }}
182
+ platforms : ${{ inputs.PLATFORMS }}
183
+ build-args : ${{ env.BUILD_ARGS }}
184
+ secrets : ${{ env.DOCKER_SECRETS }}
185
+
186
+ - name : Build and push without cache
187
+ if : inputs.PUSH == 'true' && inputs.ENABLE_CACHE == 'false'
160
188
uses : docker/build-push-action@v6
161
189
with :
162
190
push : true
163
191
tags : |
164
192
${{ steps.meta.outputs.tags }}
165
- cache-from : ${{ inputs.CACHE_FROM }}
166
- cache-to : ${{ inputs.CACHE_TO }}}
167
193
file : ${{ inputs.FILE }}
194
+ no-cache : true
168
195
context : ${{ inputs.CONTEXT }}
169
196
platforms : ${{ inputs.PLATFORMS }}
170
197
build-args : ${{ env.BUILD_ARGS }}
0 commit comments