Add DockerCacheName to be able to use it from templates

- like the following to get golang:latest and the cache name of its parent
   ```console
   $ bashbrew cat --format '{{ range .Entries }}{{ $.DockerCacheName . }}{{ range .Tags }}{{"\n"}}{{ join ":" $.RepoName . }}{{end}}{{"\n"}}{{end}}' golang:latest
   ```
This commit is contained in:
Joe Ferguson 2016-07-06 13:27:39 -07:00
parent e1b855bce7
commit a712a5d847
2 changed files with 9 additions and 3 deletions

View File

@ -65,13 +65,11 @@ func cmdBuild(c *cli.Context) error {
}
}
cacheHash, err := r.dockerCacheHash(&entry)
cacheTag, err := r.DockerCacheName(&entry)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed calculating "cache hash" for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
}
cacheTag := "bashbrew/cache:" + cacheHash
// check whether we've already built this artifact
_, err = dockerInspect("{{.Id}}", cacheTag)
if err != nil {

View File

@ -82,6 +82,14 @@ func dockerfileFrom(dockerfile io.Reader) (string, error) {
return "", nil
}
func (r Repo) DockerCacheName(entry *manifest.Manifest2822Entry) (string, error) {
cacheHash, err := r.dockerCacheHash(entry)
if err != nil {
return "", err
}
return "bashbrew/cache:" + cacheHash, err
}
func (r Repo) dockerCacheHash(entry *manifest.Manifest2822Entry) (string, error) {
uniqueBits, err := r.dockerBuildUniqueBits(entry)
if err != nil {