...

Source file src/github.com/Microsoft/hcsshim/cmd/wclayer/export.go

Documentation: github.com/Microsoft/hcsshim/cmd/wclayer

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"compress/gzip"
     7  	"context"
     8  	"io"
     9  	"os"
    10  	"path/filepath"
    11  
    12  	winio "github.com/Microsoft/go-winio"
    13  	"github.com/Microsoft/hcsshim/internal/appargs"
    14  	"github.com/Microsoft/hcsshim/pkg/ociwclayer"
    15  	"github.com/urfave/cli"
    16  )
    17  
    18  var exportCommand = cli.Command{
    19  	Name:  "export",
    20  	Usage: "exports a layer to a tar file",
    21  	Flags: []cli.Flag{
    22  		cli.StringSliceFlag{
    23  			Name:  "layer, l",
    24  			Usage: "paths to the read-only parent layers",
    25  		},
    26  		cli.StringFlag{
    27  			Name:  "output, o",
    28  			Usage: "output layer tar (defaults to stdout)",
    29  		},
    30  		cli.BoolFlag{
    31  			Name:  "gzip, z",
    32  			Usage: "compress output with gzip compression",
    33  		},
    34  	},
    35  	ArgsUsage: "<layer path>",
    36  	Before:    appargs.Validate(appargs.NonEmptyString),
    37  	Action: func(cliContext *cli.Context) (err error) {
    38  		path, err := filepath.Abs(cliContext.Args().First())
    39  		if err != nil {
    40  			return err
    41  		}
    42  
    43  		layers, err := normalizeLayers(cliContext.StringSlice("layer"), false)
    44  		if err != nil {
    45  			return err
    46  		}
    47  
    48  		err = winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege})
    49  		if err != nil {
    50  			return err
    51  		}
    52  
    53  		fp := cliContext.String("output")
    54  		f := os.Stdout
    55  		if fp != "" {
    56  			f, err = os.Create(fp)
    57  			if err != nil {
    58  				return err
    59  			}
    60  			defer f.Close()
    61  		}
    62  		w := io.Writer(f)
    63  		if cliContext.Bool("gzip") {
    64  			w = gzip.NewWriter(w)
    65  		}
    66  
    67  		return ociwclayer.ExportLayerToTar(context.Background(), w, path, layers)
    68  	},
    69  }
    70  

View as plain text