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

Add message handling for when image build fails to pull and archive initial image #565

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/abstractions/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
return err
}

// Get the hostname of the build container
go b.checkForInitialImagePullError(containerId, outputChan)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can probably do this without an extra goroutine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally I check in the gateway to see if the image exists or not. But the packages that help do this require a shitton of other packages


hostname, err := b.containerRepo.GetWorkerAddress(containerId)
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Failed to connect to build container.\n"}
Expand Down Expand Up @@ -321,6 +324,32 @@ func (b *Builder) genContainerId() string {
return fmt.Sprintf("%s%s", types.BuildContainerPrefix, uuid.New().String()[:8])
}

func (b *Builder) checkForInitialImagePullError(containerId string, outputChan chan common.OutputMsg) {
// If the initial image pull of custom base image fails, the container will never receive
// a container address for the runc client to connect to.
// If it fails without a container address, we can still look up the exit code
// to terminate the build and notify the user.
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to pass the calling function's context and check to see if its done using a select{} in the for loop. Doing this should guarantee that if someone disconnects or hits Ctl-C, this will exit regardless whats happening in the build workers.

_, err := b.containerRepo.GetContainerAddress(containerId)
if err == nil {
return
}

_, err = b.containerRepo.GetContainerExitCode(containerId)
if err == nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Base image failed to load.\n"}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to check if the exit code is > 0 because it looks like terminateContainer() calls SetContainerExitCode(). We also pass a reference of the exit code to terminateContainer(), which can be set from s.runcHandle.Run().

return
}

_, err = b.containerRepo.GetContainerState(containerId)
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Unexpected error occurred: container no longer exists.\n"}
return
}
time.Sleep(1 * time.Second)
}
}

func (b *Builder) extractPackageName(pkg string) string {
// Handle Git URLs
if strings.HasPrefix(pkg, "git+") || strings.HasPrefix(pkg, "-e git+") {
Expand Down
Loading