From 1aee0c3d30424c4fffe2a39ce6e2599756d0bf41 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 4 Oct 2017 17:59:02 +0100 Subject: [PATCH] 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 --- src/moby/build.go | 2 ++ src/moby/config.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/moby/build.go b/src/moby/build.go index 9b5da1a9d..ef8e60ea7 100644 --- a/src/moby/build.go +++ b/src/moby/build.go @@ -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, "", " ") diff --git a/src/moby/config.go b/src/moby/config.go index 13a0cb0dc..49172574e 100644 --- a/src/moby/config.go +++ b/src/moby/config.go @@ -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{}