@@ -132,6 +132,11 @@ func verifyTestManifest(image string) {
132
132
}
133
133
}
134
134
135
+ func isBuildahAvail () bool {
136
+ _ , err := exec .LookPath ("buildah" )
137
+ return err == nil
138
+ }
139
+
135
140
func buildFunc (cmd * cobra.Command , args []string ) {
136
141
if len (args ) != 1 {
137
142
log .Fatalf ("build command needs exactly 1 argument" )
@@ -162,8 +167,19 @@ func buildFunc(cmd *cobra.Command, args []string) {
162
167
if enableTests {
163
168
baseImageName += "-intermediate"
164
169
}
165
- dbcmd := exec .Command ("docker" , "build" , "." , "-f" , "build/Dockerfile" , "-t" , baseImageName )
166
- o , err := dbcmd .CombinedOutput ()
170
+
171
+ var buildCmd * exec.Cmd
172
+ if isBuildahAvail () {
173
+ buildCmd = exec .Command ("buildah" , "bud" ,
174
+ "-f" , filepath .Join (scaffold .BuildDir , scaffold .DockerfileFile ),
175
+ "--isolation" , "rootless" ,
176
+ "-t" , baseImageName )
177
+ } else {
178
+ buildCmd = exec .Command ("docker" , "build" , "." ,
179
+ "-f" , filepath .Join (scaffold .BuildDir , scaffold .DockerfileFile ),
180
+ "-t" , baseImageName )
181
+ }
182
+ o , err := buildCmd .CombinedOutput ()
167
183
if err != nil {
168
184
if enableTests {
169
185
log .Fatalf ("failed to build intermediate image for %s image: %v (%s)" , image , err , string (o ))
@@ -205,8 +221,22 @@ func buildFunc(cmd *cobra.Command, args []string) {
205
221
}
206
222
}
207
223
208
- testDbcmd := exec .Command ("docker" , "build" , "." , "-f" , testDockerfile , "-t" , image , "--build-arg" , "NAMESPACEDMAN=" + namespacedManBuild , "--build-arg" , "BASEIMAGE=" + baseImageName )
209
- o , err = testDbcmd .CombinedOutput ()
224
+ var testBuildCmd * exec.Cmd
225
+ if isBuildahAvail () {
226
+ testBuildCmd = exec .Command ("buildah" , "bud" ,
227
+ "-f" , testDockerfile ,
228
+ "--isolation" , "rootless" ,
229
+ "-t" , image ,
230
+ "--build-arg" , "NAMESPACEDMAN=" + namespacedManBuild ,
231
+ "--build-arg" , "BASEIMAGE=" + baseImageName )
232
+ } else {
233
+ testBuildCmd = exec .Command ("docker" , "build" , "." ,
234
+ "-f" , testDockerfile ,
235
+ "-t" , image ,
236
+ "--build-arg" , "NAMESPACEDMAN=" + namespacedManBuild ,
237
+ "--build-arg" , "BASEIMAGE=" + baseImageName )
238
+ }
239
+ o , err = testBuildCmd .CombinedOutput ()
210
240
if err != nil {
211
241
log .Fatalf ("failed to output build image %s: %v (%s)" , image , err , string (o ))
212
242
}
0 commit comments