Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ctrl-c in the middle of GetAllAuthConfigs() #4603

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we pass context into the function DefaultAuthHelper.GetAllAuthConfigs and handle it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that in another PR. The code is more complicated. But you are right that it makes more sense.

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