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

Remove tar file representation of images in thick bundles #770

Merged
merged 7 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions cmd/duffle/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"io"

"github.com/pkg/errors"

"github.com/deislabs/duffle/pkg/duffle/home"
"github.com/deislabs/duffle/pkg/loader"
"github.com/deislabs/duffle/pkg/packager"
Expand All @@ -14,28 +12,19 @@ import (
)

const exportDesc = `
Packages a bundle, and by default any images referenced by the bundle, within
a single gzipped tarfile.

If neither --oci-layout nor --thin is specified, all images (incuding invocation
images) referenced by the bundle metadata are saved as tar files in the
artifacts/ directory along with an artifacts.json file which describes the
contents of the artifacts/ directory.
Packages a bundle, and by default any images referenced by the bundle, within a single gzipped tarfile.

If --oci-layout is specified, all images (incuding invocation images) referenced
by the bundle metadata are saved as an OCI image layout in the artifacts/layout/
directory.
Unless --thin is specified, a thick bundle is exported. A thick bundle contains the bundle manifest and all images
(including invocation images) referenced by the bundle metadata. Images are saved as an OCI image layout in the
artifacts/layout/ directory.

If --thin specified, only the bundle manifest is exported.

By default, this command will use the name and version information of
the bundle to create a compressed archive file called
<name>-<version>.tgz in the current directory. This destination can be
updated by specifying a file path to save the compressed bundle to using
the --output-file flag.
By default, this command will use the name and version information of the bundle to create a compressed archive file
called <name>-<version>.tgz in the current directory. This destination can be updated by specifying a file path to save
the compressed bundle to using the --output-file flag.

Pass in a path to a bundle file instead of a bundle in local storage by
using the --bundle-is-file flag like below:
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:
$ duffle export [PATH] --bundle-is-file
`

Expand All @@ -47,7 +36,6 @@ type exportCmd struct {
thin bool
verbose bool
bundleIsFile bool
ociLayout bool
}

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

return export.run()
},
}

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

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

func (ex *exportCmd) Export(bundlefile string, l loader.BundleLoader) error {
is, err := packager.NewImageStore(ex.thin, ex.ociLayout)
is, err := packager.NewImageStore(ex.thin)
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/packager/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,11 @@ type ImageStore interface {
add(img string) (contentDigest string, err error)
}

func NewImageStore(thin bool, ociLayout bool) (ImageStore, error) {
func NewImageStore(thin bool) (ImageStore, error) {
if thin {
return newNop(), nil
}
if ociLayout {
return newOciLayout(), nil
}
return newTarFiles()

return newOciLayout(), nil
}

// Export prepares an artifacts directory containing all of the necessary
Expand Down
42 changes: 1 addition & 41 deletions pkg/packager/import.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package packager

import (
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive"

"github.com/deislabs/duffle/pkg/loader"
Expand All @@ -24,7 +21,6 @@ var (
type Importer struct {
Source string
Destination string
Client *client.Client
Loader loader.BundleLoader
Verbose bool
}
Expand All @@ -35,16 +31,9 @@ type Importer struct {
// destination is the directory to unpack the contents.
// load is a loader.BundleLoader preconfigured for loading bundles.
func NewImporter(source, destination string, load loader.BundleLoader, verbose bool) (*Importer, error) {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return nil, err
}
cli.NegotiateAPIVersion(context.Background())

return &Importer{
Source: source,
Destination: destination,
Client: cli,
Loader: load,
Verbose: verbose,
}, nil
Expand Down Expand Up @@ -90,36 +79,7 @@ func (im *Importer) Import() error {
return fmt.Errorf("failed to load and validate bundle.%s: %s", ext, err)
}

artifactsDir := filepath.Join(dest, "artifacts")
_, err = os.Stat(artifactsDir)
if err == nil {
filepath.Walk(artifactsDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
out, err := im.Client.ImageLoad(context.Background(), file, false)
if err != nil {
return err
}
defer out.Body.Close()

if im.Verbose {
io.Copy(os.Stdout, out.Body)
}

return nil
})
}
// TODO: https://github.com/deislabs/duffle/issues/758

return nil
}
89 changes: 0 additions & 89 deletions pkg/packager/tarfiles.go

This file was deleted.