Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from dmcgowan/wip_provenance
WIP support manifest signature
- Loading branch information
Showing
9 changed files
with
184 additions
and
46 deletions.
There are no files selected for viewing
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
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,104 @@ | ||
package graph | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"path" | ||
|
||
"github.com/docker/docker/engine" | ||
"github.com/docker/docker/pkg/tarsum" | ||
"github.com/docker/docker/registry" | ||
"github.com/docker/docker/runconfig" | ||
) | ||
|
||
func (s *TagStore) CmdManifest(job *engine.Job) engine.Status { | ||
if len(job.Args) != 1 { | ||
return job.Errorf("usage: %s NAME", job.Name) | ||
} | ||
name := job.Args[0] | ||
tag := job.Getenv("tag") | ||
if tag == "" { | ||
tag = "latest" | ||
} | ||
|
||
// Resolve the Repository name from fqn to endpoint + name | ||
_, remoteName, err := registry.ResolveRepositoryName(name) | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
|
||
manifest := map[string]interface{}{ | ||
"name": remoteName, | ||
"tag": tag, | ||
} | ||
localRepo, exists := s.Repositories[name] | ||
if !exists { | ||
return job.Errorf("Repo does not exist: %s", name) | ||
} | ||
|
||
layerId, exists := localRepo[tag] | ||
if !exists { | ||
return job.Errorf("Tag does not exist for %s: %s", name, tag) | ||
} | ||
tarsums := make([]string, 0, 4) | ||
layersSeen := make(map[string]bool) | ||
|
||
layer, err := s.graph.Get(layerId) | ||
manifest["architecture"] = layer.Architecture | ||
var metadata runconfig.Config | ||
metadata = *layer.Config | ||
history := make(map[string]string) | ||
|
||
for ; layer != nil; layer, err = layer.GetParent() { | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
|
||
if layersSeen[layer.ID] { | ||
break | ||
} | ||
if layer.Config != nil && metadata.Image != layer.ID { | ||
err = runconfig.Merge(&metadata, layer.Config) | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
} | ||
archive, err := layer.TarLayer() | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
|
||
tarSum := &tarsum.TarSum{Reader: archive, DisableCompression: true} | ||
if _, err := io.Copy(ioutil.Discard, tarSum); err != nil { | ||
return job.Error(err) | ||
} | ||
|
||
layersSeen[layer.ID] = true | ||
tarId := tarSum.Sum(nil) | ||
tarsums = append(tarsums, tarId) | ||
|
||
jsonData, err := ioutil.ReadFile(path.Join(s.graph.Root, layer.ID, "json")) | ||
if err != nil { | ||
return job.Error(fmt.Errorf("Cannot retrieve the path for {%s}: %s", layer.ID, err)) | ||
} | ||
history[tarId] = string(jsonData) | ||
} | ||
|
||
manifest["tarsum"] = tarsums | ||
manifest["metadata"] = &metadata | ||
manifest["history"] = history | ||
|
||
manifestBytes, err := json.MarshalIndent(manifest, "", " ") | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
|
||
_, err = job.Stdout.Write(manifestBytes) | ||
if err != nil { | ||
return job.Error(err) | ||
} | ||
|
||
return engine.StatusOK | ||
} |
Oops, something went wrong.