export.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //go:build windows
  2. package computestorage
  3. import (
  4. "context"
  5. "encoding/json"
  6. "github.com/Microsoft/hcsshim/internal/oc"
  7. "github.com/pkg/errors"
  8. "go.opencensus.io/trace"
  9. )
  10. // ExportLayer exports a container layer.
  11. //
  12. // `layerPath` is a path to a directory containing the layer to export.
  13. //
  14. // `exportFolderPath` is a pre-existing folder to export the layer to.
  15. //
  16. // `layerData` is the parent layer data.
  17. //
  18. // `options` are the export options applied to the exported layer.
  19. func ExportLayer(ctx context.Context, layerPath, exportFolderPath string, layerData LayerData, options ExportLayerOptions) (err error) {
  20. title := "hcsshim::ExportLayer"
  21. ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
  22. defer span.End()
  23. defer func() { oc.SetSpanStatus(span, err) }()
  24. span.AddAttributes(
  25. trace.StringAttribute("layerPath", layerPath),
  26. trace.StringAttribute("exportFolderPath", exportFolderPath),
  27. )
  28. ldBytes, err := json.Marshal(layerData)
  29. if err != nil {
  30. return err
  31. }
  32. oBytes, err := json.Marshal(options)
  33. if err != nil {
  34. return err
  35. }
  36. err = hcsExportLayer(layerPath, exportFolderPath, string(ldBytes), string(oBytes))
  37. if err != nil {
  38. return errors.Wrap(err, "failed to export layer")
  39. }
  40. return nil
  41. }