Merge pull request #207 from dagger/pipeline-fix-panic

pipeline: Fix panic for empty pipelines
This commit is contained in:
Andrea Luzzardi 2021-03-22 17:06:03 -07:00 committed by GitHub
commit 3792a716ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,8 +49,11 @@ func (p *Pipeline) State() llb.State {
return p.state return p.state
} }
func (p *Pipeline) Result() bkgw.Reference { func (p *Pipeline) Result() (llb.State, error) {
return p.result if p.result == nil {
return llb.Scratch(), nil
}
return p.result.ToState()
} }
func (p *Pipeline) FS() fs.FS { func (p *Pipeline) FS() fs.FS {
@ -134,7 +137,8 @@ func (p *Pipeline) Do(ctx context.Context, code ...*compiler.Value) error {
if err != nil { if err != nil {
return err return err
} }
// 2. Execute each operation in sequence
// Execute each operation in sequence
for idx, op := range ops { for idx, op := range ops {
// If op not concrete, interrupt without error. // If op not concrete, interrupt without error.
// This allows gradual resolution: // This allows gradual resolution:
@ -161,6 +165,7 @@ func (p *Pipeline) Do(ctx context.Context, code ...*compiler.Value) error {
return err return err
} }
} }
return nil return nil
} }
@ -241,7 +246,7 @@ func (p *Pipeline) Copy(ctx context.Context, op *compiler.Value, st llb.State) (
if err := from.Do(ctx, op.Get("from")); err != nil { if err := from.Do(ctx, op.Get("from")); err != nil {
return st, err return st, err
} }
fromResult, err := from.Result().ToState() fromResult, err := from.Result()
if err != nil { if err != nil {
return st, err return st, err
} }
@ -441,7 +446,7 @@ func (p *Pipeline) mount(ctx context.Context, dest string, mnt *compiler.Value)
if err := from.Do(ctx, mnt.Get("from")); err != nil { if err := from.Do(ctx, mnt.Get("from")); err != nil {
return nil, err return nil, err
} }
fromResult, err := from.Result().ToState() fromResult, err := from.Result()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -545,7 +550,7 @@ func (p *Pipeline) Load(ctx context.Context, op *compiler.Value, st llb.State) (
if err := from.Do(ctx, op.Get("from")); err != nil { if err := from.Do(ctx, op.Get("from")); err != nil {
return st, err return st, err
} }
return from.Result().ToState() return from.Result()
} }
func (p *Pipeline) FetchContainer(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) { func (p *Pipeline) FetchContainer(ctx context.Context, op *compiler.Value, st llb.State) (llb.State, error) {
@ -612,7 +617,7 @@ func (p *Pipeline) PushContainer(ctx context.Context, op *compiler.Value, st llb
// Add the default tag "latest" to a reference if it only has a repo name. // Add the default tag "latest" to a reference if it only has a repo name.
ref = reference.TagNameOnly(ref) ref = reference.TagNameOnly(ref)
pushSt, err := p.Result().ToState() pushSt, err := p.Result()
if err != nil { if err != nil {
return st, err return st, err
} }
@ -678,7 +683,7 @@ func (p *Pipeline) DockerBuild(ctx context.Context, op *compiler.Value, st llb.S
if err := from.Do(ctx, context); err != nil { if err := from.Do(ctx, context); err != nil {
return st, err return st, err
} }
fromResult, err := from.Result().ToState() fromResult, err := from.Result()
if err != nil { if err != nil {
return st, err return st, err
} }