Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit 4550d72

Browse files
glynjeremyrickard
authored andcommitted
Remove tar file representation of images in thick bundles (#770)
* duffle export should no longer store images in tar files Thus the --oci-layout flag is no longer needed. Also improve the wording of the help text. Ref #767 * duffle import should no longer load images from tar files Support for loading invocation images from the OCI image layout is deferred to https://github.com/deislabs/duffle/issues/758. Ref #767 * Delete dead code for exporting images in tar files Ref #767 * Delete dead code for loading images from tar files Fixes #767
1 parent 0ce61af commit 4550d72

File tree

4 files changed

+13
-162
lines changed

4 files changed

+13
-162
lines changed

cmd/duffle/export.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"io"
66

7-
"github.com/pkg/errors"
8-
97
"github.com/deislabs/duffle/pkg/duffle/home"
108
"github.com/deislabs/duffle/pkg/loader"
119
"github.com/deislabs/duffle/pkg/packager"
@@ -14,28 +12,19 @@ import (
1412
)
1513

1614
const exportDesc = `
17-
Packages a bundle, and by default any images referenced by the bundle, within
18-
a single gzipped tarfile.
19-
20-
If neither --oci-layout nor --thin is specified, all images (incuding invocation
21-
images) referenced by the bundle metadata are saved as tar files in the
22-
artifacts/ directory along with an artifacts.json file which describes the
23-
contents of the artifacts/ directory.
15+
Packages a bundle, and by default any images referenced by the bundle, within a single gzipped tarfile.
2416
25-
If --oci-layout is specified, all images (incuding invocation images) referenced
26-
by the bundle metadata are saved as an OCI image layout in the artifacts/layout/
27-
directory.
17+
Unless --thin is specified, a thick bundle is exported. A thick bundle contains the bundle manifest and all images
18+
(including invocation images) referenced by the bundle metadata. Images are saved as an OCI image layout in the
19+
artifacts/layout/ directory.
2820
2921
If --thin specified, only the bundle manifest is exported.
3022
31-
By default, this command will use the name and version information of
32-
the bundle to create a compressed archive file called
33-
<name>-<version>.tgz in the current directory. This destination can be
34-
updated by specifying a file path to save the compressed bundle to using
35-
the --output-file flag.
23+
By default, this command will use the name and version information of the bundle to create a compressed archive file
24+
called <name>-<version>.tgz in the current directory. This destination can be updated by specifying a file path to save
25+
the compressed bundle to using the --output-file flag.
3626
37-
Pass in a path to a bundle file instead of a bundle in local storage by
38-
using the --bundle-is-file flag like below:
27+
A path to a bundle file may be passed in instead of a bundle in local storage by using the --bundle-is-file flag, thus:
3928
$ duffle export [PATH] --bundle-is-file
4029
`
4130

@@ -47,7 +36,6 @@ type exportCmd struct {
4736
thin bool
4837
verbose bool
4938
bundleIsFile bool
50-
ociLayout bool
5139
}
5240

5341
func newExportCmd(w io.Writer) *cobra.Command {
@@ -61,18 +49,14 @@ func newExportCmd(w io.Writer) *cobra.Command {
6149
RunE: func(cmd *cobra.Command, args []string) error {
6250
export.home = home.Home(homePath())
6351
export.bundle = args[0]
64-
if export.thin && export.ociLayout {
65-
return errors.New("--thin and --oci-layout must not both be specified")
66-
}
6752

6853
return export.run()
6954
},
7055
}
7156

7257
f := cmd.Flags()
7358
f.StringVarP(&export.dest, "output-file", "o", "", "Save exported bundle to file path")
74-
f.BoolVarP(&export.bundleIsFile, "bundle-is-file", "f", false, "Indicates that the bundle source is a file path")
75-
f.BoolVarP(&export.ociLayout, "oci-layout", "l", false, "Export images as an OCI image layout")
59+
f.BoolVarP(&export.bundleIsFile, "bundle-is-file", "f", false, "Interpret the bundle source as a file path")
7660
f.BoolVarP(&export.thin, "thin", "t", false, "Export only the bundle manifest")
7761
f.BoolVarP(&export.verbose, "verbose", "v", false, "Verbose output")
7862

@@ -92,7 +76,7 @@ func (ex *exportCmd) run() error {
9276
}
9377

9478
func (ex *exportCmd) Export(bundlefile string, l loader.BundleLoader) error {
95-
is, err := packager.NewImageStore(ex.thin, ex.ociLayout)
79+
is, err := packager.NewImageStore(ex.thin)
9680
if err != nil {
9781
return err
9882
}

pkg/packager/export.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@ type ImageStore interface {
4242
add(img string) (contentDigest string, err error)
4343
}
4444

45-
func NewImageStore(thin bool, ociLayout bool) (ImageStore, error) {
45+
func NewImageStore(thin bool) (ImageStore, error) {
4646
if thin {
4747
return newNop(), nil
4848
}
49-
if ociLayout {
50-
return newOciLayout(), nil
51-
}
52-
return newTarFiles()
53-
49+
return newOciLayout(), nil
5450
}
5551

5652
// Export prepares an artifacts directory containing all of the necessary

pkg/packager/import.go

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package packager
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
7-
"io"
86
"os"
97
"path/filepath"
108
"strings"
119

12-
"github.com/docker/docker/client"
1310
"github.com/docker/docker/pkg/archive"
1411

1512
"github.com/deislabs/duffle/pkg/loader"
@@ -24,7 +21,6 @@ var (
2421
type Importer struct {
2522
Source string
2623
Destination string
27-
Client *client.Client
2824
Loader loader.BundleLoader
2925
Verbose bool
3026
}
@@ -35,16 +31,9 @@ type Importer struct {
3531
// destination is the directory to unpack the contents.
3632
// load is a loader.BundleLoader preconfigured for loading bundles.
3733
func NewImporter(source, destination string, load loader.BundleLoader, verbose bool) (*Importer, error) {
38-
cli, err := client.NewClientWithOpts(client.FromEnv)
39-
if err != nil {
40-
return nil, err
41-
}
42-
cli.NegotiateAPIVersion(context.Background())
43-
4434
return &Importer{
4535
Source: source,
4636
Destination: destination,
47-
Client: cli,
4837
Loader: load,
4938
Verbose: verbose,
5039
}, nil
@@ -90,36 +79,7 @@ func (im *Importer) Import() error {
9079
return fmt.Errorf("failed to load and validate bundle.%s: %s", ext, err)
9180
}
9281

93-
artifactsDir := filepath.Join(dest, "artifacts")
94-
_, err = os.Stat(artifactsDir)
95-
if err == nil {
96-
filepath.Walk(artifactsDir, func(path string, info os.FileInfo, err error) error {
97-
if err != nil {
98-
return err
99-
}
100-
101-
if info.IsDir() {
102-
return nil
103-
}
104-
105-
file, err := os.Open(path)
106-
if err != nil {
107-
return err
108-
}
109-
defer file.Close()
110-
out, err := im.Client.ImageLoad(context.Background(), file, false)
111-
if err != nil {
112-
return err
113-
}
114-
defer out.Body.Close()
115-
116-
if im.Verbose {
117-
io.Copy(os.Stdout, out.Body)
118-
}
119-
120-
return nil
121-
})
122-
}
82+
// TODO: https://github.com/deislabs/duffle/issues/758
12383

12484
return nil
12585
}

pkg/packager/tarfiles.go

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)