(ctx context.Context, srcPath string)
| 325 | } |
| 326 | |
| 327 | func saveArtifact(ctx context.Context, srcPath string) error { |
| 328 | logger := logging.RequireLoggerFromContext(ctx) |
| 329 | |
| 330 | if common.FindOverlappingVolume(template, srcPath) != nil { |
| 331 | logger.WithField("srcPath", srcPath).Info(ctx, "no need to save artifact - on overlapping volume") |
| 332 | return nil |
| 333 | } |
| 334 | if _, err := os.Stat(srcPath); os.IsNotExist(err) { // might be optional, so we ignore |
| 335 | logger.WithField("srcPath", srcPath).WithError(err).Warn(ctx, "cannot save artifact") |
| 336 | return nil |
| 337 | } |
| 338 | dstPath := filepath.Join(varRunArgo, "/outputs/artifacts/", strings.TrimSuffix(srcPath, "/")+".tgz") |
| 339 | logger.WithFields(logging.Fields{ |
| 340 | "src": srcPath, |
| 341 | "dst": dstPath, |
| 342 | }).Info(ctx, "saving artifact") |
| 343 | z := filepath.Dir(dstPath) |
| 344 | if err := os.MkdirAll(z, 0o755); err != nil { // chmod rwxr-xr-x |
| 345 | return fmt.Errorf("failed to create directory %s: %w", z, err) |
| 346 | } |
| 347 | dst, err := os.Create(dstPath) |
| 348 | if err != nil { |
| 349 | return fmt.Errorf("failed to create destination %s: %w", dstPath, err) |
| 350 | } |
| 351 | defer func() { _ = dst.Close() }() |
| 352 | if err = archive.TarGzToWriter(ctx, srcPath, gzip.DefaultCompression, dst); err != nil { |
| 353 | return fmt.Errorf("failed to tarball the output %s to %s: %w", srcPath, dstPath, err) |
| 354 | } |
| 355 | if err = dst.Close(); err != nil { |
| 356 | return fmt.Errorf("failed to close %s: %w", dstPath, err) |
| 357 | } |
| 358 | return nil |
| 359 | } |
| 360 | |
| 361 | func saveParameter(ctx context.Context, srcPath string) error { |
| 362 | logger := logging.RequireLoggerFromContext(ctx) |
no test coverage detected