Handle ctrl-c in the middle of GetAllAuthConfigs()
@@ -156,18 +156,36 @@ func (l *localDaemon) ConfigFile(ctx context.Context, image string) (*v1.ConfigF
return cfg, nil
}
-// Build performs a docker build and returns the imageID.
-func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string, a *latest.DockerArtifact, ref string, mode config.RunMode) (string, error) {
- logrus.Debugf("Running docker build: context: %s, dockerfile: %s", workspace, a.DockerfilePath)
+func authConfig(ctx context.Context) map[string]types.AuthConfig {
+ auth := make(chan map[string]types.AuthConfig)
+ go func() {
// Like `docker build`, we ignore the errors
// See https://github.com/docker/cli/blob/75c1bb1f33d7cedbaf48404597d5bf9818199480/cli/command/image/build.go#L364
authConfigs, _ := DefaultAuthHelper.GetAllAuthConfigs()
+ auth <- authConfigs
+ }()
+
+ // Because this can take a long time, we make sure it can be interrupted by the user.
+ select {
+ case <-ctx.Done():
+ return nil
+ case r := <-auth:
+ return r
+ }
+}
+
+// Build performs a docker build and returns the imageID.
+func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string, a *latest.DockerArtifact, ref string, mode config.RunMode) (string, error) {
+ logrus.Debugf("Running docker build: context: %s, dockerfile: %s", workspace, a.DockerfilePath)
+
buildArgs, err := EvalBuildArgs(mode, workspace, a)
if err != nil {
return "", fmt.Errorf("unable to evaluate build args: %w", err)
}
+ authConfigs := authConfig(ctx)
+
buildCtx, buildCtxWriter := io.Pipe()
go func() {
err := CreateDockerTarContext(ctx, buildCtxWriter, workspace, a, l.insecureRegistries)
