(log buildlog.Logger)
| 298 | } |
| 299 | |
| 300 | func DefaultLogImagePullFn(log buildlog.Logger) func(ImagePullEvent) error { |
| 301 | var ( |
| 302 | // Avoid spamming too frequently, the messages can come quickly |
| 303 | delayDur = time.Second * 2 |
| 304 | // We use a zero-value time.Time to start since we want to log |
| 305 | // the first event we get. |
| 306 | lastLog time.Time |
| 307 | ) |
| 308 | return func(e ImagePullEvent) error { |
| 309 | if e.Error != "" { |
| 310 | log.Errorf(e.Error) |
| 311 | return xerrors.Errorf("pull image: %s", e.Error) |
| 312 | } |
| 313 | |
| 314 | // Not enough time has transpired, return without logging. |
| 315 | if time.Since(lastLog) < delayDur { |
| 316 | return nil |
| 317 | } |
| 318 | |
| 319 | msg := e.Status |
| 320 | if e.Progress != "" { |
| 321 | msg = fmt.Sprintf("%s: %s", e.Status, e.Progress) |
| 322 | } |
| 323 | log.Info(msg) |
| 324 | lastLog = time.Now() |
| 325 | |
| 326 | return nil |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | func isTLSVerificationErr(err error) bool { |
| 331 | return err != nil && strings.Contains(err.Error(), "tls: failed to verify certificate: x509: certificate signed by unknown authority") |
no test coverage detected