MCPcopy Index your code
hub / github.com/docker/cli / runBuild

Function runBuild

cli/command/image/build.go:185–398  ·  view source on GitHub ↗

nolint:gocyclo

(ctx context.Context, dockerCli command.Cli, options buildOptions)

Source from the content-addressed store, hash-verified

183
184//nolint:gocyclo
185func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) error {
186 var (
187 buildCtx io.ReadCloser
188 dockerfileCtx io.ReadCloser
189 contextDir string
190 relDockerfile string
191 progBuff io.Writer
192 buildBuff io.Writer
193 remote string
194 )
195
196 if options.platform != "" {
197 _, err := platforms.Parse(options.platform)
198 if err != nil {
199 return err
200 }
201 }
202
203 contextType, err := build.DetectContextType(options.context)
204 if err != nil {
205 return err
206 }
207
208 if options.dockerfileFromStdin() {
209 if contextType == build.ContextTypeStdin {
210 return errors.New("invalid argument: can't use stdin for both build context and dockerfile")
211 }
212 dockerfileCtx = dockerCli.In()
213 }
214
215 progBuff = dockerCli.Out()
216 buildBuff = dockerCli.Out()
217 if options.quiet {
218 progBuff = bytes.NewBuffer(nil)
219 buildBuff = bytes.NewBuffer(nil)
220 }
221 if options.imageIDFile != "" {
222 // Avoid leaving a stale file if we eventually fail
223 if err := os.Remove(options.imageIDFile); err != nil && !os.IsNotExist(err) {
224 return fmt.Errorf("removing image ID file: %w", err)
225 }
226 }
227
228 switch contextType {
229 case build.ContextTypeStdin:
230 // buildCtx is tar archive. if stdin was dockerfile then it is wrapped
231 buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)
232 if err != nil {
233 return fmt.Errorf("unable to prepare context from STDIN: %w", err)
234 }
235 case build.ContextTypeLocal:
236 contextDir, relDockerfile, err = build.GetContextFromLocalDir(options.context, options.dockerfileName)
237 if err != nil {
238 return fmt.Errorf("unable to prepare context: %s", err)
239 }
240 if strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
241 // Dockerfile is outside build-context; read the Dockerfile and pass it as dockerfileCtx
242 dockerfileCtx, err = os.Open(options.dockerfileName)

Calls 12

imageBuildOptionsFunction · 0.85
dockerfileFromStdinMethod · 0.80
GetAllCredentialsMethod · 0.80
ImageBuildMethod · 0.80
InMethod · 0.65
OutMethod · 0.65
RemoveMethod · 0.65
ErrMethod · 0.65
ConfigFileMethod · 0.65
ClientMethod · 0.65
CloseMethod · 0.45
IsTerminalMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…