Skip to content

Commit

Permalink
Refactor, breaking API changes
Browse files Browse the repository at this point in the history
Refactor api, DownloadImage is now DownloadAndUnpackImage and can specify
the prefered unpack method.
We should be now api stable for v0.x branch
  • Loading branch information
mudler committed Mar 5, 2019
1 parent 07562ce commit 6a693e9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
5 changes: 3 additions & 2 deletions api/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const defaultRegistryBase = "https://registry-1.docker.io"
type DownloadOpts struct {
RegistryBase string
KeepLayers bool
UnpackMode string
}

func DownloadImage(sourceImage, output string, opts *DownloadOpts) error {
func DownloadAndUnpackImage(sourceImage, output string, opts *DownloadOpts) error {

if opts.RegistryBase == "" {
opts.RegistryBase = defaultRegistryBase
Expand Down Expand Up @@ -113,7 +114,7 @@ func DownloadImage(sourceImage, output string, opts *DownloadOpts) error {

jww.INFO.Println("Unpacking...")

err = export.UnPackLayers(layers_sha, output)
err = export.UnPackLayers(layers_sha, output, opts.UnpackMode)
if err != nil {
jww.INFO.Fatal(err)
return err
Expand Down
12 changes: 3 additions & 9 deletions api/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@ type Export struct {
Path string
}

func (e *Export) ExtractLayers() error {
func (e *Export) ExtractLayers(unpackmode string) error {

jww.INFO.Println("Extracting layers...")

for _, entry := range e.Entries {
jww.INFO.Println(" - ", entry.LayerTarPath)
err := entry.ExtractLayerDir()
err := entry.ExtractLayerDir(unpackmode)
if err != nil {
return err
}
}
return nil
}

func (e *Export) UnPackLayers(order []string, layerDir string) error {

unpackmode := os.Getenv("UNPACK_MODE")
if unpackmode == "" {
unpackmode = "umoci"
}

func (e *Export) UnPackLayers(order []string, layerDir string, unpackmode string) error {
err := os.MkdirAll(layerDir, 0755)
if err != nil {
return err
Expand Down
6 changes: 1 addition & 5 deletions api/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ func (e *ExportedImage) RemoveLayerDir() error {
return os.RemoveAll(e.LayerDirPath)
}

func (e *ExportedImage) ExtractLayerDir() error {
func (e *ExportedImage) ExtractLayerDir(unpackmode string) error {
err := os.MkdirAll(e.LayerDirPath, 0755)
if err != nil {
return err
}
unpackmode := os.Getenv("UNPACK_MODE")
if unpackmode == "" {
unpackmode = "umoci"
}

if err := ExtractLayer(&ExtractOpts{
Source: e.LayerTarPath,
Expand Down
9 changes: 7 additions & 2 deletions download.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"os"

"github.com/codegangsta/cli"
"github.com/mudler/docker-companion/api"
)
Expand All @@ -15,6 +17,9 @@ func downloadImage(c *cli.Context) error {
} else {
return cli.NewExitError("This command requires to argument: source-image output-folder(absolute)", 86)
}

return api.DownloadImage(sourceImage, output, &api.DownloadOpts{KeepLayers: c.Bool("keep")})
unpackmode := os.Getenv("UNPACK_MODE")
if unpackmode == "" {
unpackmode = "umoci"
}
return api.DownloadAndUnpackImage(sourceImage, output, &api.DownloadOpts{KeepLayers: c.Bool("keep"), UnpackMode: unpackmode})
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// VERSION is the app version
const VERSION = "0.4.3"
const VERSION = "0.4.5"

func main() {
app := cli.NewApp()
Expand Down

0 comments on commit 6a693e9

Please sign in to comment.