MCPcopy
hub / github.com/argoproj/argo-workflows / saveArtifact

Function saveArtifact

cmd/argoexec/commands/emissary.go:327–359  ·  view source on GitHub ↗
(ctx context.Context, srcPath string)

Source from the content-addressed store, hash-verified

325}
326
327func 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
361func saveParameter(ctx context.Context, srcPath string) error {
362 logger := logging.RequireLoggerFromContext(ctx)

Callers 1

NewEmissaryCommandFunction · 0.85

Calls 10

RequireLoggerFromContextFunction · 0.92
FindOverlappingVolumeFunction · 0.92
TarGzToWriterFunction · 0.92
InfoMethod · 0.65
WithFieldMethod · 0.65
WarnMethod · 0.65
WithErrorMethod · 0.65
WithFieldsMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected