Update Image strings before writing them out

If the YAML file contains:
  - path: etc/linuxkit.yml
    metadata: yaml
in the fil section, the image was build with content trust,
then the linuxkit.yml file image contains fully qualified
image references (including the sha256).

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-10-04 17:59:02 +01:00
parent ad83cb8928
commit 1aee0c3d30
2 changed files with 27 additions and 0 deletions

View File

@ -388,6 +388,8 @@ func tarAppend(iw *tar.Writer, tr *tar.Reader) error {
// this allows inserting metadata into a file in the image
func metadata(m Moby, md string) ([]byte, error) {
// Make sure the Image strings are update to date with the refs
updateImages(&m)
switch md {
case "json":
return json.MarshalIndent(m, "", " ")

View File

@ -197,6 +197,31 @@ func extractReferences(m *Moby) error {
return nil
}
func updateImages(m *Moby) error {
if m.Kernel.ref != nil {
m.Kernel.Image = m.Kernel.ref.String()
}
for i, ii := range m.initRefs {
m.Init[i] = ii.String()
}
for _, image := range m.Onboot {
if image.ref != nil {
image.Image = image.ref.String()
}
}
for _, image := range m.Onshutdown {
if image.ref != nil {
image.Image = image.ref.String()
}
}
for _, image := range m.Services {
if image.ref != nil {
image.Image = image.ref.String()
}
}
return nil
}
// NewConfig parses a config file
func NewConfig(config []byte) (Moby, error) {
m := Moby{}