Skip to content

Commit

Permalink
Make sure image build always send an error build to outputChan (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun-m authored Jun 14, 2024
1 parent 9dfddf1 commit c2bfa06
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/abstractions/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
if opts.ExistingImageUri != "" {
err := b.handleCustomBaseImage(opts, outputChan)
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Unknown error occurred.\n"}
return err
}
}
Expand All @@ -121,6 +122,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
ExistingImageUri: opts.ExistingImageUri,
})
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Unknown error occurred.\n"}
return err
}

Expand Down Expand Up @@ -151,6 +153,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
PoolSelector: b.config.ImageService.BuildContainerPoolSelector,
})
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: err.Error() + "\n"}
return err
}

Expand All @@ -168,6 +171,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co

client, err := common.NewRunCClient(hostname, authInfo.Token.Key, conn)
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Failed to connect to build container.\n"}
return err
}

Expand All @@ -179,6 +183,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
for {
r, err := client.Status(containerId)
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Unknown error occurred.\n"}
return err
}

Expand All @@ -188,6 +193,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
}

if time.Since(start) > defaultContainerSpinupTimeout {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Timeout: container not running after 180 seconds.\n"}
return errors.New("timeout: container not running after 180 seconds")
}

Expand All @@ -196,6 +202,7 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co

imageId, err := b.GetImageId(opts)
if err != nil {
outputChan <- common.OutputMsg{Done: true, Success: false, Msg: "Unknown error occurred.\n"}
return err
}

Expand Down

0 comments on commit c2bfa06

Please sign in to comment.