MCPcopy Create free account
hub / github.com/coder/envbuilder / run

Function run

envbuilder.go:120–975  ·  view source on GitHub ↗
(ctx context.Context, opts options.Options, execArgs *execArgsInfo)

Source from the content-addressed store, hash-verified

118}
119
120func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) error {
121 defer options.UnsetEnv()
122
123 workingDir := workingdir.At(opts.WorkingDirBase)
124
125 stageNumber := 0
126 startStage := func(format string, args ...any) func(format string, args ...any) {
127 now := time.Now()
128 stageNumber++
129 stageNum := stageNumber
130 opts.Logger(log.LevelInfo, "#%d: %s", stageNum, fmt.Sprintf(format, args...))
131
132 return func(format string, args ...any) {
133 opts.Logger(log.LevelInfo, "#%d: %s [%s]", stageNum, fmt.Sprintf(format, args...), time.Since(now))
134 }
135 }
136
137 if opts.GetCachedImage {
138 return fmt.Errorf("developer error: use RunCacheProbe instead")
139 }
140 if opts.CacheRepo == "" && opts.PushImage {
141 return fmt.Errorf("--cache-repo must be set when using --push-image")
142 }
143
144 // Default to the shell.
145 execArgs.InitCommand = opts.InitCommand
146 execArgs.InitArgs = []string{"-c", opts.InitScript}
147 if opts.InitArgs != "" {
148 var err error
149 execArgs.InitArgs, err = shellquote.Split(opts.InitArgs)
150 if err != nil {
151 return fmt.Errorf("parse init args: %w", err)
152 }
153 }
154
155 opts.Logger(log.LevelInfo, "%s %s - Build development environments from repositories in a container", newColor(color.Bold).Sprintf("envbuilder"), buildinfo.Version())
156
157 cleanupDockerConfigOverride, err := initDockerConfigOverride(opts.Filesystem, opts.Logger, workingDir, opts.DockerConfigBase64)
158 if err != nil {
159 return err
160 }
161 defer func() {
162 if err := cleanupDockerConfigOverride(); err != nil {
163 opts.Logger(log.LevelError, "failed to cleanup docker config override: %w", err)
164 }
165 }() // best effort
166
167 runtimeData := runtimeDataStore{
168 ContainerEnv: make(map[string]string),
169 RemoteEnv: make(map[string]string),
170 }
171 if fileExists(opts.Filesystem, workingDir.Image()) {
172 opts.Logger(log.LevelInfo, "Found magic image file at %s", workingDir.Image())
173 if err = parseMagicImageFile(opts.Filesystem, workingDir.Image(), &runtimeData); err != nil {
174 return fmt.Errorf("parse magic image file: %w", err)
175 }
176 runtimeData.Image = true
177

Callers 1

RunFunction · 0.85

Calls 15

HasImageMethod · 0.95
HasDockerfileMethod · 0.95
CompileMethod · 0.95
UnsetEnvFunction · 0.92
AtFunction · 0.92
VersionFunction · 0.92
WithEnvPrefixFunction · 0.92
CloneOptionsFromOptionsFunction · 0.92
ProgressWriterFunction · 0.92
CloneRepoFunction · 0.92
ShallowCloneRepoFunction · 0.92
ParseFunction · 0.92

Tested by

no test coverage detected