mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-04 15:58:39 +00:00
Support downloading remote tarball contexts in builder jobs.
Signed-off-by: Moysés Borges <moysesb@gmail.com>
This commit is contained in:
@@ -632,6 +632,10 @@ type FakeContext struct {
|
||||
}
|
||||
|
||||
func (f *FakeContext) Add(file, content string) error {
|
||||
return f.addFile(file, []byte(content))
|
||||
}
|
||||
|
||||
func (f *FakeContext) addFile(file string, content []byte) error {
|
||||
filepath := path.Join(f.Dir, file)
|
||||
dirpath := path.Dir(filepath)
|
||||
if dirpath != "." {
|
||||
@@ -639,7 +643,8 @@ func (f *FakeContext) Add(file, content string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return ioutil.WriteFile(filepath, []byte(content), 0644)
|
||||
return ioutil.WriteFile(filepath, content, 0644)
|
||||
|
||||
}
|
||||
|
||||
func (f *FakeContext) Delete(file string) error {
|
||||
@@ -651,11 +656,7 @@ func (f *FakeContext) Close() error {
|
||||
return os.RemoveAll(f.Dir)
|
||||
}
|
||||
|
||||
func fakeContextFromDir(dir string) *FakeContext {
|
||||
return &FakeContext{dir}
|
||||
}
|
||||
|
||||
func fakeContextWithFiles(files map[string]string) (*FakeContext, error) {
|
||||
func fakeContextFromNewTempDir() (*FakeContext, error) {
|
||||
tmp, err := ioutil.TempDir("", "fake-context")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -663,8 +664,18 @@ func fakeContextWithFiles(files map[string]string) (*FakeContext, error) {
|
||||
if err := os.Chmod(tmp, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fakeContextFromDir(tmp), nil
|
||||
}
|
||||
|
||||
ctx := fakeContextFromDir(tmp)
|
||||
func fakeContextFromDir(dir string) *FakeContext {
|
||||
return &FakeContext{dir}
|
||||
}
|
||||
|
||||
func fakeContextWithFiles(files map[string]string) (*FakeContext, error) {
|
||||
ctx, err := fakeContextFromNewTempDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for file, content := range files {
|
||||
if err := ctx.Add(file, content); err != nil {
|
||||
ctx.Close()
|
||||
@@ -701,6 +712,19 @@ type FakeStorage interface {
|
||||
CtxDir() string
|
||||
}
|
||||
|
||||
func fakeBinaryStorage(archives map[string]*bytes.Buffer) (FakeStorage, error) {
|
||||
ctx, err := fakeContextFromNewTempDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for name, content := range archives {
|
||||
if err := ctx.addFile(name, content.Bytes()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return fakeStorageWithContext(ctx)
|
||||
}
|
||||
|
||||
// fakeStorage returns either a local or remote (at daemon machine) file server
|
||||
func fakeStorage(files map[string]string) (FakeStorage, error) {
|
||||
ctx, err := fakeContextWithFiles(files)
|
||||
|
||||
Reference in New Issue
Block a user