Skip to content

Commit 61bf262

Browse files
committed
feat: dont use explicit buildx if not needed
1 parent a2d100d commit 61bf262

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pkg/actions/deploy_build.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ func (d *Deploy) buildServiceApp(ctx context.Context, app *config.ServiceApp, ev
178178
return err
179179
}
180180

181+
explicitBuildx := false
182+
181183
cmdArgs := []string{
182-
"buildx", "build",
183184
"--platform=linux/amd64",
184185
"--tag", app.AppBuild.LocalDockerImage,
185186
"--file", app.Build.Dockerfile,
186-
"--load", // Load the image into docker after build.
187187
"--progress=plain",
188188
}
189189

@@ -201,7 +201,13 @@ func (d *Deploy) buildServiceApp(ctx context.Context, app *config.ServiceApp, ev
201201
cacheFrom := fmt.Sprintf("type=local,modes=max,src=%s", dockerBuildCacheDir)
202202
cacheTo := fmt.Sprintf("type=local,dest=%s", dockerBuildCacheDir)
203203

204-
cmdArgs = append(cmdArgs, "--cache-from", cacheFrom, "--cache-to", cacheTo)
204+
cmdArgs = append(cmdArgs,
205+
"--cache-from", cacheFrom,
206+
"--cache-to", cacheTo,
207+
"--load", // Load the image into docker after build.
208+
)
209+
210+
explicitBuildx = true
205211
}
206212

207213
// Add build args if needed.
@@ -220,10 +226,18 @@ func (d *Deploy) buildServiceApp(ctx context.Context, app *config.ServiceApp, ev
220226

221227
cmdArgs = append(cmdArgs, ".")
222228

229+
if explicitBuildx {
230+
// Use buildx for explicit cache usage.
231+
cmdArgs = append([]string{"buildx", "build"}, cmdArgs...)
232+
} else {
233+
// Use normal build.
234+
cmdArgs = append([]string{"build"}, cmdArgs...)
235+
}
236+
223237
cmd, err := command.New(
224238
exec.Command("docker", cmdArgs...),
225239
command.WithDir(dockercontext),
226-
// command.WithEnv([]string{"DOCKER_BUILDKIT=1"}),
240+
command.WithEnv([]string{"DOCKER_BUILDKIT=1"}),
227241
)
228242
if err != nil {
229243
return merry.Errorf("error preparing build command for %s app: %s: %w", app.Type(), app.Name(), err)

0 commit comments

Comments
 (0)