CreateDockerfile creates a Dockerfile in path.
( ctx context.Context, opts CreateDockerfileOptions, )
| 89 | |
| 90 | // CreateDockerfile creates a Dockerfile in path. |
| 91 | func (g *Options) CreateDockerfile( |
| 92 | ctx context.Context, |
| 93 | opts CreateDockerfileOptions, |
| 94 | ) error { |
| 95 | defer trace.StartRegion(ctx, "createDockerfile").End() |
| 96 | |
| 97 | if err := opts.validate(); err != nil { |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | // create dockerfile |
| 102 | file, err := os.Create(filepath.Join(g.Path, "Dockerfile")) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | defer file.Close() |
| 107 | path := fmt.Sprintf("tmpl/%s.Dockerfile.tmpl", opts.Type()) |
| 108 | t := template.Must(template.ParseFS(tmplFS, path)) |
| 109 | // write content into file |
| 110 | return t.Execute(file, map[string]any{ |
| 111 | "IsDevcontainer": g.IsDevcontainer, |
| 112 | "RootUser": g.RootUser, |
| 113 | "LocalFlakeDirs": g.LocalFlakeDirs, |
| 114 | |
| 115 | // The following are only used for prod Dockerfile |
| 116 | "DevboxRunInstall": lo.Ternary(opts.HasInstall, "devbox run install", "echo 'No install script found, skipping'"), |
| 117 | "DevboxRunBuild": lo.Ternary(opts.HasBuild, "devbox run build", "echo 'No build script found, skipping'"), |
| 118 | "Cmd": fmt.Sprintf("%q, %q, %q", "devbox", "run", "start"), |
| 119 | }) |
| 120 | } |
| 121 | |
| 122 | // CreateDevcontainer creates a devcontainer.json in path and writes getDevcontainerContent's output into it |
| 123 | func (g *Options) CreateDevcontainer(ctx context.Context) error { |
no test coverage detected