Jelajahi Sumber

Dockerbuilder: use the arch info from base image

Currently we hardcode the architecture to the `runtime.GOARCH` when
building a docker image, this will result in a confusing info if the
arch in the base image is different from the one on the host.

This PR takes use of the arch data from the base image during the build
process, thus we can get consistent arch info between the base image
and the finally built image.

Signed-off-by: Dennis Chen <dennis.chen@arm.com>
Dennis Chen 7 tahun lalu
induk
melakukan
92b17b10ba
1 mengubah file dengan 10 tambahan dan 1 penghapusan
  1. 10 1
      image/image.go

+ 10 - 1
image/image.go

@@ -96,6 +96,15 @@ func (img *Image) RunConfig() *container.Config {
 	return img.Config
 }
 
+// BaseImgArch returns the image's architecture. If not populated, defaults to the host runtime arch.
+func (img *Image) BaseImgArch() string {
+	arch := img.Architecture
+	if arch == "" {
+		arch = runtime.GOARCH
+	}
+	return arch
+}
+
 // OperatingSystem returns the image's operating system. If not populated, defaults to the host runtime OS.
 func (img *Image) OperatingSystem() string {
 	os := img.OS
@@ -157,7 +166,7 @@ func NewChildImage(img *Image, child ChildConfig, platform string) *Image {
 		V1Image: V1Image{
 			DockerVersion:   dockerversion.Version,
 			Config:          child.Config,
-			Architecture:    runtime.GOARCH,
+			Architecture:    img.BaseImgArch(),
 			OS:              platform,
 			Container:       child.ContainerID,
 			ContainerConfig: *child.ContainerConfig,