...

Source file src/github.com/Microsoft/hcsshim/computestorage/export.go

Documentation: github.com/Microsoft/hcsshim/computestorage

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

View as plain text