From 1713f59e4fb1841b5c815415885d79ccfbbd2573 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 4 Oct 2017 17:07:06 +0100 Subject: [PATCH] Turn Images into references We want to modify some of the content of the Image structure and thus have to pass them by reference. Signed-off-by: Rolf Neugebauer --- src/moby/build.go | 2 +- src/moby/config.go | 10 +++++----- src/moby/config_test.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/moby/build.go b/src/moby/build.go index e19fd8de9..b94ef68ca 100644 --- a/src/moby/build.go +++ b/src/moby/build.go @@ -121,7 +121,7 @@ func enforceContentTrust(fullImageName string, config *TrustConfig) bool { return false } -func outputImage(image Image, section string, prefix string, m Moby, idMap map[string]uint32, dupMap map[string]string, pull bool, iw *tar.Writer) error { +func outputImage(image *Image, section string, prefix string, m Moby, idMap map[string]uint32, dupMap map[string]string, pull bool, iw *tar.Writer) error { log.Infof(" Create OCI config for %s", image.Image) useTrust := enforceContentTrust(image.Image, &m.Trust) oci, runtime, err := ConfigToOCI(image, useTrust, idMap) diff --git a/src/moby/config.go b/src/moby/config.go index 33ab46fa3..a7d8921dc 100644 --- a/src/moby/config.go +++ b/src/moby/config.go @@ -20,9 +20,9 @@ import ( type Moby struct { Kernel KernelConfig `kernel:"cmdline" json:"kernel,omitempty"` Init []string `init:"cmdline" json:"init"` - Onboot []Image `yaml:"onboot" json:"onboot"` - Onshutdown []Image `yaml:"onshutdown" json:"onshutdown"` - Services []Image `yaml:"services" json:"services"` + Onboot []*Image `yaml:"onboot" json:"onboot"` + Onshutdown []*Image `yaml:"onshutdown" json:"onshutdown"` + Services []*Image `yaml:"services" json:"services"` Trust TrustConfig `yaml:"trust" json:"trust,omitempty"` Files []File `yaml:"files" json:"files"` } @@ -290,7 +290,7 @@ func NewImage(config []byte) (Image, error) { } // ConfigToOCI converts a config specification to an OCI config file and a runtime config -func ConfigToOCI(image Image, trust bool, idMap map[string]uint32) (specs.Spec, Runtime, error) { +func ConfigToOCI(image *Image, trust bool, idMap map[string]uint32) (specs.Spec, Runtime, error) { // TODO pass through same docker client to all functions cli, err := dockerClient() @@ -649,7 +649,7 @@ func idNumeric(v interface{}, idMap map[string]uint32) (uint32, error) { } // ConfigInspectToOCI converts a config and the output of image inspect to an OCI config -func ConfigInspectToOCI(yaml Image, inspect types.ImageInspect, idMap map[string]uint32) (specs.Spec, Runtime, error) { +func ConfigInspectToOCI(yaml *Image, inspect types.ImageInspect, idMap map[string]uint32) (specs.Spec, Runtime, error) { oci := specs.Spec{} runtime := Runtime{} diff --git a/src/moby/config_test.go b/src/moby/config_test.go index 4aa27878f..ebecb1fab 100644 --- a/src/moby/config_test.go +++ b/src/moby/config_test.go @@ -44,7 +44,7 @@ func TestOverrides(t *testing.T) { inspect := setupInspect(t, label) - oci, _, err := ConfigInspectToOCI(yaml, inspect, idMap) + oci, _, err := ConfigInspectToOCI(&yaml, inspect, idMap) if err != nil { t.Error(err) } @@ -72,7 +72,7 @@ func TestInvalidCap(t *testing.T) { inspect := setupInspect(t, label) - _, _, err := ConfigInspectToOCI(yaml, inspect, idMap) + _, _, err := ConfigInspectToOCI(&yaml, inspect, idMap) if err == nil { t.Error("expected error, got valid OCI config") } @@ -95,7 +95,7 @@ func TestIdMap(t *testing.T) { inspect := setupInspect(t, label) - oci, _, err := ConfigInspectToOCI(yaml, inspect, idMap) + oci, _, err := ConfigInspectToOCI(&yaml, inspect, idMap) if err != nil { t.Error(err) }