github.com/YousefHaggyHeroku/pack@v1.5.5/internal/build/lifecycle_executor.go (about) 1 package build 2 3 import ( 4 "context" 5 "math/rand" 6 "time" 7 8 "github.com/buildpacks/imgutil" 9 "github.com/buildpacks/lifecycle/api" 10 "github.com/docker/docker/client" 11 "github.com/google/go-containerregistry/pkg/name" 12 13 "github.com/YousefHaggyHeroku/pack/internal/builder" 14 "github.com/YousefHaggyHeroku/pack/logging" 15 ) 16 17 var ( 18 // SupportedPlatformAPIVersions lists the Platform API versions pack supports listed from earliest to latest 19 SupportedPlatformAPIVersions = builder.APISet{ 20 api.MustParse("0.3"), 21 api.MustParse("0.4"), 22 } 23 ) 24 25 type Builder interface { 26 Name() string 27 UID() int 28 GID() int 29 LifecycleDescriptor() builder.LifecycleDescriptor 30 Stack() builder.StackMetadata 31 Image() imgutil.Image 32 } 33 34 type LifecycleExecutor struct { 35 logger logging.Logger 36 docker client.CommonAPIClient 37 } 38 39 type Cache interface { 40 Name() string 41 Clear(context.Context) error 42 } 43 44 func init() { 45 rand.Seed(time.Now().UTC().UnixNano()) 46 } 47 48 type LifecycleOptions struct { 49 AppPath string 50 Image name.Reference 51 Builder Builder 52 LifecycleImage string 53 RunImage string 54 ClearCache bool 55 Publish bool 56 TrustBuilder bool 57 UseCreator bool 58 HTTPProxy string 59 HTTPSProxy string 60 NoProxy string 61 Network string 62 Volumes []string 63 DefaultProcessType string 64 FileFilter func(string) bool 65 } 66 67 func NewLifecycleExecutor(logger logging.Logger, docker client.CommonAPIClient) *LifecycleExecutor { 68 return &LifecycleExecutor{logger: logger, docker: docker} 69 } 70 71 func (l *LifecycleExecutor) Execute(ctx context.Context, opts LifecycleOptions) error { 72 lifecycleExec, err := NewLifecycleExecution(l.logger, l.docker, opts) 73 if err != nil { 74 return err 75 } 76 defer lifecycleExec.Cleanup() 77 return lifecycleExec.Run(ctx, NewDefaultPhaseFactory) 78 }