@@ -30,7 +30,6 @@ import (
3030 "github.com/cyphar/umoci/image/cas"
3131 "github.com/cyphar/umoci/image/generator"
3232 "github.com/cyphar/umoci/image/layer"
33- "github.com/cyphar/umoci/pkg/idtools"
3433 "github.com/opencontainers/image-spec/specs-go/v1"
3534 "github.com/urfave/cli"
3635 "github.com/vbatts/go-mtree"
@@ -40,11 +39,10 @@ import (
4039var repackCommand = cli.Command {
4140 Name : "repack" ,
4241 Usage : "repacks an OCI runtime bundle into a reference" ,
43- ArgsUsage : `--image <image-path> --from <reference> -- bundle <bundle-path>
42+ ArgsUsage : `--image <image-path> --bundle <bundle-path>
4443
45- Where "<image-path>" is the path to the OCI image, "<reference>" is the name of
46- the reference descriptor which was used to generate the original runtime bundle
47- and "<bundle-path>" is the destination to repack the image to.
44+ Where "<image-path>" is the path to the OCI image, and "<bundle-path>" is the
45+ bundle from which to generate the required layers.
4846
4947It should be noted that this is not the same as oci-create-layer because it
5048uses go-mtree to create diff layers from runtime bundles unpacked with
@@ -57,10 +55,6 @@ manifest and configuration information uses the new diff atop the old manifest.`
5755 Name : "image" ,
5856 Usage : "path to OCI image bundle" ,
5957 },
60- cli.StringFlag {
61- Name : "from" ,
62- Usage : "reference descriptor name to repack" ,
63- },
6458 cli.StringFlag {
6559 Name : "bundle" ,
6660 Usage : "destination bundle path" ,
@@ -69,18 +63,6 @@ manifest and configuration information uses the new diff atop the old manifest.`
6963 Name : "tag" ,
7064 Usage : "tag name for repacked image" ,
7165 },
72- cli.StringSliceFlag {
73- Name : "uid-map" ,
74- Usage : "specifies a uid mapping to use when repacking" ,
75- },
76- cli.StringSliceFlag {
77- Name : "gid-map" ,
78- Usage : "specifies a gid mapping to use when repacking" ,
79- },
80- cli.BoolFlag {
81- Name : "rootless" ,
82- Usage : "enable rootless unpacking support" ,
83- },
8466 },
8567
8668 Action : repack ,
@@ -96,48 +78,23 @@ func repack(ctx *cli.Context) error {
9678 if bundlePath == "" {
9779 return fmt .Errorf ("bundle path cannot be empty" )
9880 }
99- fromName := ctx .String ("from" )
100- if fromName == "" {
101- return fmt .Errorf ("reference name cannot be empty" )
102- }
10381
104- // Parse map options.
105- mapOptions := layer.MapOptions {
106- Rootless : ctx .Bool ("rootless" ),
107- }
108- // We need to set mappings if we're in rootless mode.
109- if mapOptions .Rootless {
110- if ! ctx .IsSet ("uid-map" ) {
111- ctx .Set ("uid-map" , fmt .Sprintf ("%d:0:1" , os .Geteuid ()))
112- logrus .WithFields (logrus.Fields {
113- "map.uid" : ctx .StringSlice ("uid-map" ),
114- }).Info ("setting default rootless --uid-map option" )
115- }
116- if ! ctx .IsSet ("gid-map" ) {
117- ctx .Set ("gid-map" , fmt .Sprintf ("%d:0:1" , os .Getegid ()))
118- logrus .WithFields (logrus.Fields {
119- "map.gid" : ctx .StringSlice ("gid-map" ),
120- }).Info ("setting default rootless --gid-map option" )
121- }
122- }
123- for _ , uidmap := range ctx .StringSlice ("uid-map" ) {
124- idMap , err := idtools .ParseMapping (uidmap )
125- if err != nil {
126- return fmt .Errorf ("failure parsing --uid-map %s: %s" , uidmap , err )
127- }
128- mapOptions .UIDMappings = append (mapOptions .UIDMappings , idMap )
129- }
130- for _ , gidmap := range ctx .StringSlice ("gid-map" ) {
131- idMap , err := idtools .ParseMapping (gidmap )
132- if err != nil {
133- return fmt .Errorf ("failure parsing --gid-map %s: %s" , gidmap , err )
134- }
135- mapOptions .GIDMappings = append (mapOptions .GIDMappings , idMap )
82+ // Read the metadata first.
83+ meta , err := ReadBundleMeta (bundlePath )
84+ if err != nil {
85+ return fmt .Errorf ("error reading umoci.json metadata: %s" , err )
13686 }
87+
13788 logrus .WithFields (logrus.Fields {
138- "map.uid" : mapOptions .UIDMappings ,
139- "map.gid" : mapOptions .GIDMappings ,
140- }).Infof ("parsed mappings" )
89+ "version" : meta .Version ,
90+ "from" : meta .From ,
91+ "map_options" : meta .MapOptions ,
92+ }).Debugf ("umoci: loaded UmociMeta metadata" )
93+
94+ // FIXME: Implement support for manifest lists.
95+ if meta .From .MediaType != v1 .MediaTypeImageManifest {
96+ return fmt .Errorf ("--from descriptor does not point to v1.MediaTypeImageManifest: not implemented: %s" , meta .From .MediaType )
97+ }
14198
14299 // Get a reference to the CAS.
143100 engine , err := cas .Open (imagePath )
@@ -146,24 +103,13 @@ func repack(ctx *cli.Context) error {
146103 }
147104 defer engine .Close ()
148105
149- fromDescriptor , err := engine .GetReference (context .TODO (), fromName )
150- if err != nil {
151- return err
152- }
153-
154- // FIXME: Implement support for manifest lists.
155- if fromDescriptor .MediaType != v1 .MediaTypeImageManifest {
156- return fmt .Errorf ("--from descriptor does not point to v1.MediaTypeImageManifest: not implemented: %s" , fromDescriptor .MediaType )
157- }
158-
159- mtreeName := strings .Replace (fromDescriptor .Digest , "sha256:" , "sha256_" , 1 )
106+ mtreeName := strings .Replace (meta .From .Digest , "sha256:" , "sha256_" , 1 )
160107 mtreePath := filepath .Join (bundlePath , mtreeName + ".mtree" )
161108 fullRootfsPath := filepath .Join (bundlePath , layer .RootfsName )
162109
163110 logrus .WithFields (logrus.Fields {
164111 "image" : imagePath ,
165112 "bundle" : bundlePath ,
166- "ref" : fromName ,
167113 "rootfs" : layer .RootfsName ,
168114 "mtree" : mtreePath ,
169115 }).Debugf ("umoci: repacking OCI image" )
@@ -185,7 +131,7 @@ func repack(ctx *cli.Context) error {
185131 "keywords" : keywords ,
186132 }).Debugf ("umoci: parsed mtree spec" )
187133
188- diffs , err := mtree .Check (fullRootfsPath , spec , keywords , mapOptions .Rootless )
134+ diffs , err := mtree .Check (fullRootfsPath , spec , keywords , meta . MapOptions .Rootless )
189135 if err != nil {
190136 return err
191137 }
@@ -194,7 +140,7 @@ func repack(ctx *cli.Context) error {
194140 "ndiff" : len (diffs ),
195141 }).Debugf ("umoci: checked mtree spec" )
196142
197- reader , err := layer .GenerateLayer (fullRootfsPath , diffs , & mapOptions )
143+ reader , err := layer .GenerateLayer (fullRootfsPath , diffs , & meta . MapOptions )
198144 if err != nil {
199145 return err
200146 }
@@ -250,7 +196,7 @@ func repack(ctx *cli.Context) error {
250196 "size" : layerSize ,
251197 }).Debugf ("umoci: generated new diff layer" )
252198
253- manifestBlob , err := cas .FromDescriptor (context .TODO (), engine , fromDescriptor )
199+ manifestBlob , err := cas .FromDescriptor (context .TODO (), engine , & meta . From )
254200 if err != nil {
255201 return err
256202 }
@@ -331,6 +277,7 @@ func repack(ctx *cli.Context) error {
331277 "size" : newDescriptor .Size ,
332278 }).Infof ("created new image" )
333279
280+ // FIXME: This should be mandatory.
334281 tagName := ctx .String ("tag" )
335282 if tagName == "" {
336283 return nil
0 commit comments