export.go 1.2 KB

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