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 Jul 31, 2020
1 parent 750455e commit 311c9c4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,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
}()

// Before 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) (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 := EvaluateBuildArgs(a.BuildArgs)
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 311c9c4

Please sign in to comment.