diff options
author | John Starks <jostarks@microsoft.com> | 2016-05-25 19:11:51 -0700 |
---|---|---|
committer | John Starks <jostarks@microsoft.com> | 2016-05-25 19:23:02 -0700 |
commit | 05bd04350b8348b3c3bbe3156420257313e4e804 (patch) | |
tree | 74e506e9aa917ebeaca35511e05e11cab26173b7 /layer/filestore.go | |
parent | 9c902364fb97faeca8257ed683bdef27615d9f1f (diff) | |
download | docker-05bd04350b8348b3c3bbe3156420257313e4e804.tar.gz |
Support layers from external URLs
This is used to support downloading Windows base images from Microsoft
servers.
Signed-off-by: John Starks <jostarks@microsoft.com>
Diffstat (limited to 'layer/filestore.go')
-rw-r--r-- | layer/filestore.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/layer/filestore.go b/layer/filestore.go index a0044b3663..6e11ca9a37 100644 --- a/layer/filestore.go +++ b/layer/filestore.go @@ -2,6 +2,7 @@ package layer import ( "compress/gzip" + "encoding/json" "errors" "fmt" "io" @@ -13,6 +14,7 @@ import ( "strings" "github.com/Sirupsen/logrus" + "github.com/docker/distribution" "github.com/docker/distribution/digest" "github.com/docker/docker/pkg/ioutils" ) @@ -24,6 +26,9 @@ var ( // digest.SHA384, // Currently not used // digest.SHA512, // Currently not used } + + // ErrNoForeignSource is returned when no foreign source is set for a layer. + ErrNoForeignSource = errors.New("layer does not have a foreign source") ) type fileMetadataStore struct { @@ -98,6 +103,14 @@ func (fm *fileMetadataTransaction) SetCacheID(cacheID string) error { return ioutil.WriteFile(filepath.Join(fm.root, "cache-id"), []byte(cacheID), 0644) } +func (fm *fileMetadataTransaction) SetForeignSource(ref distribution.Descriptor) error { + jsonRef, err := json.Marshal(ref) + if err != nil { + return err + } + return ioutil.WriteFile(filepath.Join(fm.root, "descriptor.json"), jsonRef, 0644) +} + func (fm *fileMetadataTransaction) TarSplitWriter(compressInput bool) (io.WriteCloser, error) { f, err := os.OpenFile(filepath.Join(fm.root, "tar-split.json.gz"), os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { @@ -191,6 +204,23 @@ func (fms *fileMetadataStore) GetCacheID(layer ChainID) (string, error) { return content, nil } +func (fms *fileMetadataStore) GetForeignSource(layer ChainID) (distribution.Descriptor, error) { + content, err := ioutil.ReadFile(fms.getLayerFilename(layer, "descriptor.json")) + if err != nil { + if os.IsNotExist(err) { + return distribution.Descriptor{}, ErrNoForeignSource + } + return distribution.Descriptor{}, err + } + + var ref distribution.Descriptor + err = json.Unmarshal(content, &ref) + if err != nil { + return distribution.Descriptor{}, err + } + return ref, err +} + func (fms *fileMetadataStore) TarSplitReader(layer ChainID) (io.ReadCloser, error) { fz, err := os.Open(fms.getLayerFilename(layer, "tar-split.json.gz")) if err != nil { |