Skip to content

Commit

Permalink
Handle ctrl-c in the middle of GetAllAuthConfigs()
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Aug 31, 2020
1 parent 8d8379d commit 48a4471
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,36 @@ func (l *localDaemon) ConfigFile(ctx context.Context, image string) (*v1.ConfigF
return cfg, nil
}

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)

// Like `docker build`, we ignore the errors
// See https://github.com/docker/cli/blob/75c1bb1f33d7cedbaf48404597d5bf9818199480/cli/command/image/build.go#L364
authConfigs, _ := DefaultAuthHelper.GetAllAuthConfigs()
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)
Expand Down

0 comments on commit 48a4471

Please sign in to comment.