MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / BuildImageWithProcessAndOptions

Method BuildImageWithProcessAndOptions

agent/utils/docker/docker.go:274–316  ·  view source on GitHub ↗
(task *task.Task, tar io.ReadCloser, options types.ImageBuildOptions)

Source from the content-addressed store, hash-verified

272}
273
274func (c Client) BuildImageWithProcessAndOptions(task *task.Task, tar io.ReadCloser, options types.ImageBuildOptions) error {
275 out, err := c.cli.ImageBuild(context.Background(), tar, options)
276 if err != nil {
277 return err
278 }
279 defer out.Body.Close()
280 decoder := json.NewDecoder(out.Body)
281 for {
282 var progress map[string]interface{}
283 if err = decoder.Decode(&progress); err != nil {
284 if err == io.EOF {
285 break
286 }
287 return err
288 }
289 if msg, ok := progress["errorDetail"]; ok {
290 return fmt.Errorf("image build failed, err: %v", msg)
291 }
292 if msg, ok := progress["error"]; ok {
293 return fmt.Errorf("image build failed, err: %v", msg)
294 }
295 status, _ := progress["status"].(string)
296 stream, _ := progress["stream"].(string)
297 if len(status) == 0 && len(stream) != 0 {
298 if stream != "\n" {
299 task.Log(stream)
300 }
301 continue
302 }
303 switch status {
304 case "Downloading", "Extracting":
305 logProcess(progress, task)
306 case "Pull complete", "Download complete", "Verifying Checksum":
307 id, _ := progress["id"].(string)
308 progressStr := fmt.Sprintf("%s %s", status, id)
309 _ = setLog(id, progressStr, task)
310 default:
311 progressStr, _ := json.Marshal(progress)
312 task.Log(string(progressStr))
313 }
314 }
315 return nil
316}
317
318func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
319 options := image.PullOptions{}

Callers 1

ImageBuildMethod · 0.80

Implementers 1

terminalAIClientagent/utils/terminal/ai/client.go

Calls 5

logProcessFunction · 0.85
setLogFunction · 0.85
ImageBuildMethod · 0.65
CloseMethod · 0.65
LogMethod · 0.45

Tested by

no test coverage detected