github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/docker/initializer.go (about) 1 package docker 2 3 import ( 4 "context" 5 "embed" 6 "path/filepath" 7 8 "github.com/wawandco/ox/internal/source" 9 "github.com/wawandco/ox/plugins/base/new" 10 ) 11 12 var ( 13 //go:embed templates 14 templates embed.FS 15 ) 16 17 type Initializer struct{} 18 19 func (i Initializer) Name() string { 20 return "docker/initializer" 21 } 22 23 func (i *Initializer) Initialize(ctx context.Context, options new.Options) error { 24 files := []struct { 25 path string 26 template string 27 }{ 28 {filepath.Join(options.Folder, ".dockerignore"), "templates/dot-dockerignore.tmpl"}, 29 {filepath.Join(options.Folder, "Dockerfile"), "templates/Dockerfile.tmpl"}, 30 } 31 32 for _, f := range files { 33 content, err := templates.ReadFile(f.template) 34 if err != nil { 35 return err 36 } 37 38 err = source.Build(f.path, string(content), nil) 39 if err != nil { 40 return err 41 } 42 } 43 44 return nil 45 }