forked from cnabio/duffle
-
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.
WIP: duffle relocate of thick bundles
Rough first cut - currently fails some unit tests. Fixes cnabio#705
- Loading branch information
Showing
19 changed files
with
842 additions
and
157 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
package imagestore | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
// Builder is a means of creating image stores. | ||
type Builder interface { | ||
// ArchiveDir creates a fresh Builder with the given archive directory. | ||
ArchiveDir(string) Builder | ||
|
||
// Logs creates a fresh builder with the given log stream. | ||
Logs(io.Writer) Builder | ||
|
||
// Build creates an image store. | ||
Build() (Store, error) | ||
} |
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,69 @@ | ||
package builder | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/deislabs/duffle/pkg/imagestore" | ||
"github.com/deislabs/duffle/pkg/imagestore/ocilayout" | ||
"github.com/deislabs/duffle/pkg/imagestore/remote" | ||
) | ||
|
||
// NewBuilder creates an image store builder which will, if necessary, create archive contents. | ||
func NewBuilder(remoteRepos bool) (imagestore.Builder, error) { | ||
// infer the concrete type of the image store from the input parameters | ||
if remoteRepos { | ||
return remote.NewRemoteBuilder(), nil | ||
} | ||
return ocilayout.NewOciLayout(), nil | ||
} | ||
|
||
// NewLocatingBuilder creates an image store builder which will, if necessary, find existing archive contents. | ||
func NewLocatingBuilder() imagestore.Builder { | ||
return &locatingBuilder{ | ||
archiveDir: "", | ||
logs: ioutil.Discard, | ||
} | ||
} | ||
|
||
type locatingBuilder struct { | ||
archiveDir string | ||
logs io.Writer | ||
} | ||
|
||
func (b *locatingBuilder) ArchiveDir(archiveDir string) imagestore.Builder { | ||
return &locatingBuilder{ | ||
archiveDir: archiveDir, | ||
logs: b.logs, | ||
} | ||
} | ||
|
||
func (b *locatingBuilder) Logs(logs io.Writer) imagestore.Builder { | ||
return &locatingBuilder{ | ||
archiveDir: b.archiveDir, | ||
logs: logs, | ||
} | ||
} | ||
|
||
func (b *locatingBuilder) Build() (imagestore.Store, error) { | ||
if thin(b.archiveDir) { | ||
return remote.NewRemoteBuilder().Build() | ||
} | ||
|
||
return ocilayout.LocateOciLayout(b.archiveDir) | ||
} | ||
|
||
func thin(archiveDir string) bool { | ||
// If there is no archive directory, the bundle is thin | ||
if archiveDir == "" { | ||
return true | ||
} | ||
|
||
// If there is an archive directory, the bundle is thin if and only if the archive directory has no artifacts/ | ||
// subdirectory | ||
layoutDir := filepath.Join(archiveDir, "artifacts") | ||
_, err := os.Stat(layoutDir) | ||
return os.IsNotExist(err) | ||
} |
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,27 @@ | ||
package imagestoremocks | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/deislabs/duffle/pkg/imagestore" | ||
) | ||
|
||
type MockBuilder struct { | ||
ArchiveDirStub func(string) | ||
LogsStub func(io.Writer) | ||
BuildStub func() (imagestore.Store, error) | ||
} | ||
|
||
func (b *MockBuilder) ArchiveDir(archiveDir string) imagestore.Builder { | ||
b.ArchiveDirStub(archiveDir) | ||
return b | ||
} | ||
|
||
func (b *MockBuilder) Logs(logs io.Writer) imagestore.Builder { | ||
b.LogsStub(logs) | ||
return b | ||
} | ||
|
||
func (b *MockBuilder) Build() (imagestore.Store, error) { | ||
return b.BuildStub() | ||
} |
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,16 @@ | ||
package imagestoremocks | ||
|
||
import "github.com/pivotal/image-relocation/pkg/image" | ||
|
||
type MockStore struct { | ||
AddStub func(im string) (string, error) | ||
PushStub func(image.Digest, image.Name, image.Name) error | ||
} | ||
|
||
func (i *MockStore) Add(im string) (string, error) { | ||
return i.AddStub(im) | ||
} | ||
|
||
func (i *MockStore) Push(dig image.Digest, src image.Name, dst image.Name) error { | ||
return i.PushStub(dig, src, dst) | ||
} |
Oops, something went wrong.