Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
lib: stop downloading images if the caller already has this manifest
Browse files Browse the repository at this point in the history
This commit allows a user of the library to provide a list of manifest
hashes, presumably generated from annotations left on images by prior
invocations of docker2aci, for images it already has. If docker2aci
fetches a manifest and the hash for it matches one of the elements in
the user provided list, docker2aci will stop working, and return with no
error and no produced ACIs.
  • Loading branch information
Derek Gonyeo committed Jan 25, 2017
1 parent bb692e3 commit 065228f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 10 additions & 4 deletions lib/docker2aci.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ import (
// CommonConfig represents the shared configuration options for converting
// Docker images.
type CommonConfig struct {
Squash bool // squash the layers in one file
OutputDir string // where to put the resulting ACI
TmpDir string // directory to use for temporary files
Compression common.Compression // which compression to use for the resulting file(s)
Squash bool // squash the layers in one file
OutputDir string // where to put the resulting ACI
TmpDir string // directory to use for temporary files
Compression common.Compression // which compression to use for the resulting file(s)
CurrentManifestHashes []string // any manifest hashes the caller already has

Info log.Logger
Debug log.Logger
Expand Down Expand Up @@ -145,6 +146,11 @@ func (c *converter) convert() ([]string, error) {
if err != nil {
return nil, err
}
for _, h := range c.config.CurrentManifestHashes {
if manhash == h {
return nil, nil
}
}

layersOutputDir := c.config.OutputDir
if c.config.Squash {
Expand Down
15 changes: 5 additions & 10 deletions lib/internal/backend/repository/repository2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package repository

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand All @@ -37,6 +35,7 @@ import (
"github.com/appc/docker2aci/lib/internal/util"
"github.com/appc/spec/schema"
"github.com/coreos/pkg/progressutil"
godigest "github.com/opencontainers/go-digest"
)

const (
Expand Down Expand Up @@ -334,9 +333,7 @@ func (rb *RepositoryBackend) getManifestV21(dockerURL *common.ParsedDockerURL, r
return nil, "", err
}

s := sha256.New()
s.Write(manblob)
manhash := hex.EncodeToString(s.Sum(nil))
manhash := godigest.FromBytes(manblob)

if manifest.Name != dockerURL.ImageName {
return nil, "", fmt.Errorf("name doesn't match what was requested, expected: %s, downloaded: %s", dockerURL.ImageName, manifest.Name)
Expand All @@ -363,7 +360,7 @@ func (rb *RepositoryBackend) getManifestV21(dockerURL *common.ParsedDockerURL, r

rb.imageManifests[*dockerURL] = *manifest

return layers, manhash, nil
return layers, string(manhash), nil
}

func (rb *RepositoryBackend) getManifestV22(dockerURL *common.ParsedDockerURL, res *http.Response) ([]string, string, error) {
Expand All @@ -379,9 +376,7 @@ func (rb *RepositoryBackend) getManifestV22(dockerURL *common.ParsedDockerURL, r
return nil, "", err
}

s := sha256.New()
s.Write(manblob)
manhash := hex.EncodeToString(s.Sum(nil))
manhash := godigest.FromBytes(manblob)

//TODO: verify signature here

Expand All @@ -398,7 +393,7 @@ func (rb *RepositoryBackend) getManifestV22(dockerURL *common.ParsedDockerURL, r

rb.imageV2Manifests[*dockerURL] = manifest

return layers, manhash, nil
return layers, string(manhash), nil
}

func (rb *RepositoryBackend) getConfigV22(dockerURL *common.ParsedDockerURL, configDigest string) error {
Expand Down

0 comments on commit 065228f

Please sign in to comment.