| 340 | } |
| 341 | |
| 342 | func (m *monitor) Invoke(ctx context.Context, pid string, cfg *build.InvokeConfig, ioIn io.ReadCloser, ioOut io.WriteCloser, ioErr io.WriteCloser) error { |
| 343 | proc, ok := m.processes.Get(pid) |
| 344 | if !ok { |
| 345 | // Start a new process. |
| 346 | if m.rCtx == nil { |
| 347 | return errors.New("no build result is registered") |
| 348 | } |
| 349 | var err error |
| 350 | proc, err = m.processes.StartProcess(pid, m.rCtx, cfg) |
| 351 | if err != nil { |
| 352 | return err |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | // Attach containerIn to this process |
| 357 | ioCancelledCh := make(chan struct{}) |
| 358 | proc.ForwardIO(&ioset.In{Stdin: ioIn, Stdout: ioOut, Stderr: ioErr}, func(error) { close(ioCancelledCh) }) |
| 359 | |
| 360 | select { |
| 361 | case <-ioCancelledCh: |
| 362 | return errors.Errorf("io cancelled") |
| 363 | case err := <-proc.Done(): |
| 364 | return err |
| 365 | case <-ctx.Done(): |
| 366 | return context.Cause(ctx) |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | func (m *monitor) Rollback(ctx context.Context, cfg *build.InvokeConfig) string { |
| 371 | pid := identity.NewID() |