-
Notifications
You must be signed in to change notification settings - Fork 3
/
add-layer.go
47 lines (42 loc) · 1.21 KB
/
add-layer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"errors"
"code.cloudfoundry.org/hydrator/layermodifier"
directory "code.cloudfoundry.org/hydrator/oci-directory"
"github.com/urfave/cli"
)
var addLayerCommand = cli.Command{
Name: "add-layer",
Usage: "adds a layer to an existing image",
Description: `The add-layer command adds a layer to an existing OCI image.
Note that the OCI image must exist on disk and that the image will be modified
in place`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "ociImage",
Value: "",
Usage: "Path to the image where the layer will be added",
},
cli.StringFlag{
Name: "layer",
Value: "",
Usage: "Path to .tgz file containing the layer to be added to the image",
},
},
Action: func(context *cli.Context) error {
if err := checkArgs(context, 0, exactArgs); err != nil {
return err
}
layerPath := context.String("layer")
ociImagePath := context.String("ociImage")
if layerPath == "" {
return errors.New("ERROR: Missing option -layer")
}
if ociImagePath == "" {
return errors.New("ERROR: Missing option -ociImage")
}
ociDirectory := directory.NewHandler(ociImagePath)
layerModifier := layermodifier.New(ociDirectory)
return layerModifier.AddLayer(layerPath)
},
}