MCPcopy Index your code
hub / github.com/jetify-com/devbox / CreateDockerfile

Method CreateDockerfile

internal/devbox/generate/devcontainer_util.go:91–120  ·  view source on GitHub ↗

CreateDockerfile creates a Dockerfile in path.

(
	ctx context.Context,
	opts CreateDockerfileOptions,
)

Source from the content-addressed store, hash-verified

89
90// CreateDockerfile creates a Dockerfile in path.
91func (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
123func (g *Options) CreateDevcontainer(ctx context.Context) error {

Callers 2

GenerateDevcontainerMethod · 0.95
GenerateDockerfileMethod · 0.95

Calls 4

EndMethod · 0.80
TypeMethod · 0.80
ExecuteMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected