github.com/octohelm/wagon@v0.0.0-20240308040401-88662650dc0b/pkg/engine/plan/task/container_pull.go (about) 1 package task 2 3 import ( 4 "dagger.io/dagger" 5 "github.com/octohelm/wagon/pkg/engine/daggerutil" 6 "github.com/octohelm/wagon/pkg/engine/plan" 7 "github.com/octohelm/wagon/pkg/engine/plan/task/core" 8 "github.com/pkg/errors" 9 "golang.org/x/net/context" 10 ) 11 12 func init() { 13 core.DefaultFactory.Register(&Pull{}) 14 } 15 16 type Pull struct { 17 core.Task 18 19 Source string `json:"source"` 20 Platform string `json:"platform,omitempty" wagon:"generated,name=platform"` 21 Auth *core.Auth `json:"auth,omitempty"` 22 23 Config core.ImageConfig `json:"-" wagon:"generated,name=config"` 24 Output core.FS `json:"-" wagon:"generated,name=output"` 25 26 ResolveMode string `json:"resolveMode,omitempty" wagon:"deprecated"` 27 } 28 29 func (input *Pull) Do(ctx context.Context) error { 30 return daggerutil.Do(ctx, func(c *dagger.Client) error { 31 ct := c.Container(dagger.ContainerOpts{ 32 Platform: core.DefaultPlatform(input.Platform), 33 }) 34 35 ct = plan.RegistryAuthStoreContext.From(ctx).ApplyTo(ctx, ct) 36 if a := input.Auth; a != nil { 37 ct = a.ApplyTo(ctx, ct, input.Source) 38 } 39 40 ct = ct.From(core.ImagePullPrefixierFromContext(ctx).ImagePullPrefix(input.Source)) 41 42 id, err := ct.ID(ctx) 43 if err != nil { 44 return errors.Wrapf(err, "Pull %s failed.", input.Source) 45 } 46 47 platform, err := ct.Platform(ctx) 48 if err != nil { 49 return errors.Wrapf(err, "Resolve Platform %s failed.", input.Source) 50 } 51 52 if err := input.Config.Resolve(ctx, c, id); err != nil { 53 return err 54 } 55 56 input.Platform = string(platform) 57 return input.Output.SetDirectoryIDBy(ctx, ct.Rootfs()) 58 }) 59 }