forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Eventually we will refactor all command to use this new abstraction Signed-off-by: Emily Casey <ecasey@pivotal.io> Signed-off-by: Dave Goddard <dave@goddard.id.au>
- Loading branch information
Showing
15 changed files
with
1,366 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package image | ||
|
||
import ( | ||
"context" | ||
"github.com/buildpack/lifecycle/img" | ||
"github.com/buildpack/pack/docker" | ||
"github.com/buildpack/pack/fs" | ||
"github.com/buildpack/packs" | ||
"github.com/docker/docker/api/types" | ||
"github.com/google/go-containerregistry/pkg/v1" | ||
"io" | ||
"log" | ||
"os" | ||
) | ||
|
||
type Image interface { | ||
Label(string) (string, error) | ||
Name() string | ||
Digest() (string, error) | ||
Rebase(string, Image) error | ||
SetLabel(string, string) error | ||
TopLayer() (string, error) | ||
Save() (string, error) | ||
} | ||
|
||
type Docker interface { | ||
PullImage(ref string) error | ||
ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) | ||
ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) | ||
ImageRemove(ctx context.Context, ref string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) | ||
} | ||
|
||
type Factory struct { | ||
Docker Docker | ||
Log *log.Logger | ||
Stdout io.Writer | ||
FS *fs.FS | ||
} | ||
|
||
func DefaultFactory() (*Factory, error) { | ||
f := &Factory{ | ||
Stdout: os.Stdout, | ||
Log: log.New(os.Stdout, "", log.LstdFlags), | ||
FS: &fs.FS{}, | ||
} | ||
|
||
var err error | ||
f.Docker, err = docker.New() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return f, nil | ||
} | ||
|
||
type Client struct{} | ||
|
||
func (c *Client) ReadImage(repoName string, useDaemon bool) (v1.Image, error) { | ||
repoStore, err := c.RepoStore(repoName, useDaemon) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
origImage, err := repoStore.Image() | ||
if err != nil { | ||
// Assume error is due to non-existent image | ||
return nil, nil | ||
} | ||
if _, err := origImage.RawManifest(); err != nil { | ||
// Assume error is due to non-existent image | ||
// This is necessary for registries | ||
return nil, nil | ||
} | ||
|
||
return origImage, nil | ||
} | ||
|
||
func (c *Client) RepoStore(repoName string, useDaemon bool) (img.Store, error) { | ||
newRepoStore := img.NewRegistry | ||
if useDaemon { | ||
newRepoStore = img.NewDaemon | ||
} | ||
repoStore, err := newRepoStore(repoName) | ||
if err != nil { | ||
return nil, packs.FailErr(err, "access", repoName) | ||
} | ||
return repoStore, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.