-
Notifications
You must be signed in to change notification settings - Fork 27
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
hostname, err := b.containerRepo.GetWorkerAddress(containerId) | ||
if err != nil { | ||
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Failed to connect to build container.\n"} | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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+") { | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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