GNU bug report logs - #58576
[PATCH] system: image: Define correct docker image arch when cross building

Previous Next

Package: guix-patches;

Reported by: Thiago Jung Bauermann <bauermann <at> kolabnow.com>

Date: Mon, 17 Oct 2022 01:30:02 UTC

Severity: normal

Tags: moreinfo, patch

Done: Mathieu Othacehe <othacehe <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 58576 in the body.
You can then email your comments to 58576 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#58576; Package guix-patches. (Mon, 17 Oct 2022 01:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Thiago Jung Bauermann <bauermann <at> kolabnow.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Mon, 17 Oct 2022 01:30:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Thiago Jung Bauermann <bauermann <at> kolabnow.com>
To: guix-patches <at> gnu.org
Cc: Thiago Jung Bauermann <thiago.bauermann <at> linaro.org>
Subject: [PATCH] system: image: Define correct docker image arch when cross
 building
Date: Sun, 16 Oct 2022 22:28:43 -0300
From: Thiago Jung Bauermann <thiago.bauermann <at> linaro.org>

Cross-building a docker image with:

  $ guix system image --image-type=docker --target=aarch64-linux-gnu os.scm

results in an image where the architecture declared in its config.json is
the host architecture rather than the target one.  The binaries are
correctly cross-compiled, so the image can be loaded and used despite the
warning message shown by docker:

  $ docker load -i vcal7bvsqcijchifhqdvprpd1niqh8sk-docker-image.tar.gz
  Loaded image: guix:latest
  $ docker create guix:latest
  WARNING: The requested image's platform (linux/amd64) does not match the
  detected host platform (linux/arm64/v8) and no specific platform was
  requested
  40f06aa869ed690489c4a3824a7f7721bd4bf453b85f25ac7199266939fe2fba
  $ echo $?
  0

This is fixed by passing the correct triplet to the build-docker-image
function.

* gnu/system/image.scm (system-docker-image) Add ‘image-target’ variable.
[builder]: Pass ‘#:system’ argument to ‘build-docker-image’.
---
 gnu/system/image.scm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index 5fc0d55d9a14..c6d7d13f6daf 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -652,6 +652,9 @@ (define shared-network?
                shared-network?)
               (list boot-program)))
          (substitutable? (image-substitutable? image))
+         (image-target (or (%current-target-system)
+                           (and=> (image-platform image) platform-target)
+                           (nix-system->gnu-triplet)))
          (register-closures? (has-guix-service-type? os))
          (schema (and register-closures?
                       (local-file (search-path %load-path
@@ -705,6 +708,7 @@ (define builder
                  #:entry-point '(#$boot-program #$os)
                  #:compressor '(#+(file-append gzip "/bin/gzip") "-9n")
                  #:creation-time (make-time time-utc 0 1)
+                 #:system #$image-target
                  #:transformations `((,image-root -> ""))))))))
 
     (computed-file name builder




Information forwarded to guix-patches <at> gnu.org:
bug#58576; Package guix-patches. (Mon, 17 Oct 2022 07:56:01 GMT) Full text and rfc822 format available.

Message #8 received at 58576 <at> debbugs.gnu.org (full text, mbox):

From: Mathieu Othacehe <othacehe <at> gnu.org>
To: Thiago Jung Bauermann <bauermann <at> kolabnow.com>
Cc: Thiago Jung Bauermann <thiago.bauermann <at> linaro.org>, 58576 <at> debbugs.gnu.org
Subject: Re: bug#58576: [PATCH] system: image: Define correct docker image
 arch when cross building
Date: Mon, 17 Oct 2022 09:54:51 +0200
Hello Thiago,

Thanks for this patch!

> +         (image-target (or (%current-target-system)
> +                           (and=> (image-platform image) platform-target)
> +                           (nix-system->gnu-triplet)))

There's the following snippet in "system-image" that is trying to do the
right thing (and it is not easy) with the "target" value.

--8<---------------cut here---------------start------------->8---
  ;; The image platform definition may provide the appropriate "system"
  ;; architecture for the image.  If we are already running on this system,
  ;; the image can be built natively.  If we are running on a different
  ;; system, then we need to cross-compile, using the "target" provided by the
  ;; image definition.
  (define system (and=> platform platform-system))
  (define target (cond
                  ;; No defined platform, let's use the user defined
                  ;; system/target parameters.
                  ((not platform)
                   (%current-target-system))
                  ;; The current system is the same as the platform system, no
                  ;; need to cross-compile.
                  ((and system
                        (string=? system (%current-system)))
                   #f)
                  ;; If there is a user defined target let's override the
                  ;; platform target. Otherwise, we can cross-compile to the
                  ;; platform target.
                  (else
                   (or (%current-target-system)
                       (and=> platform platform-target)))))
--8<---------------cut here---------------end--------------->8---

The rationale is that the user supplied %current-target-system is always
overriding the image platform field. Then, %current-target-system is set
to the "target" value defined above.

It makes me think that you could use %current-target-system directly as
the "image-target" value. WDYT?

Mathieu




Information forwarded to guix-patches <at> gnu.org:
bug#58576; Package guix-patches. (Thu, 27 Oct 2022 00:03:01 GMT) Full text and rfc822 format available.

Message #11 received at 58576 <at> debbugs.gnu.org (full text, mbox):

From: Thiago Jung Bauermann <bauermann <at> kolabnow.com>
To: Mathieu Othacehe <othacehe <at> gnu.org>
Cc: Thiago Jung Bauermann <thiago.bauermann <at> linaro.org>, 58576 <at> debbugs.gnu.org
Subject: Re: bug#58576: [PATCH] system: image: Define correct docker image
 arch when cross building
Date: Wed, 26 Oct 2022 20:47:15 -0300
Hello Mathieu,

Thank you for reviewing my patch! Sorry for the delay, I've been
traveling.

Mathieu Othacehe <othacehe <at> gnu.org> writes:

> Hello Thiago,
>
> Thanks for this patch!
>
>> +         (image-target (or (%current-target-system)
>> +                           (and=> (image-platform image) platform-target)
>> +                           (nix-system->gnu-triplet)))
>
> There's the following snippet in "system-image" that is trying to do the
> right thing (and it is not easy) with the "target" value.
>
>   ;; The image platform definition may provide the appropriate "system"
>   ;; architecture for the image.  If we are already running on this system,
>   ;; the image can be built natively.  If we are running on a different
>   ;; system, then we need to cross-compile, using the "target" provided by the
>   ;; image definition.
>   (define system (and=> platform platform-system))
>   (define target (cond
>                   ;; No defined platform, let's use the user defined
>                   ;; system/target parameters.
>                   ((not platform)
>                    (%current-target-system))
>                   ;; The current system is the same as the platform system, no
>                   ;; need to cross-compile.
>                   ((and system
>                         (string=? system (%current-system)))
>                    #f)
>                   ;; If there is a user defined target let's override the
>                   ;; platform target. Otherwise, we can cross-compile to the
>                   ;; platform target.
>                   (else
>                    (or (%current-target-system)
>                        (and=> platform platform-target)))))
>
> The rationale is that the user supplied %current-target-system is always
> overriding the image platform field. Then, %current-target-system is set
> to the "target" value defined above.
>
> It makes me think that you could use %current-target-system directly as
> the "image-target" value. WDYT?

I don't think “%current-target-system” can be used directly as the
“image-target” value because for native builds it will be #f and my
understanding is that “build-docker-image” would throw an error when
receiving #f for the “#:system” argument.

So I still need the or expression above, but I can drop the middle
expression that calls “platform-target” because it's redundant with the
snippet you posted above. Thank you for pointing it out.

I'll send a v2 with the change.

-- 
Thanks
Thiago




Added tag(s) moreinfo. Request was from Christopher Baines <mail <at> cbaines.net> to control <at> debbugs.gnu.org. (Thu, 03 Nov 2022 16:11:02 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#58576; Package guix-patches. (Fri, 04 Nov 2022 01:56:02 GMT) Full text and rfc822 format available.

Message #16 received at 58576 <at> debbugs.gnu.org (full text, mbox):

From: Thiago Jung Bauermann <bauermann <at> kolabnow.com>
To: 58576 <at> debbugs.gnu.org
Cc: Mathieu Othacehe <othacehe <at> gnu.org>,
 Thiago Jung Bauermann <bauermann <at> kolabnow.com>
Subject: [PATCH v2] system: image: Define correct docker image arch when cross
 building
Date: Thu,  3 Nov 2022 22:54:56 -0300
Cross-building a docker image with:

  $ guix system image --image-type=docker --target=aarch64-linux-gnu os.scm

results in an image where the architecture declared in its config.json is
the host architecture rather than the target one.  The binaries are
correctly cross-compiled, so the image can be loaded and used despite the
warning message shown by docker:

  $ docker load -i vcal7bvsqcijchifhqdvprpd1niqh8sk-docker-image.tar.gz
  Loaded image: guix:latest
  $ docker create guix:latest
  WARNING: The requested image's platform (linux/amd64) does not match the
  detected host platform (linux/arm64/v8) and no specific platform was
  requested
  40f06aa869ed690489c4a3824a7f7721bd4bf453b85f25ac7199266939fe2fba
  $ echo $?
  0

This is fixed by passing the correct triplet to the build-docker-image
function.

* gnu/system/image.scm (system-docker-image) Add ‘image-target’ variable.
[builder]: Pass ‘#:system’ argument to ‘build-docker-image’.
---

Hello,

This is v2 of the patch. The only difference is that the expression
defining ‘image-target’ doesn't try to get the target from the image's
platform field, since its caller ‘system-image’ already does that (thanks
to Mathieu for pointing it out).

 gnu/system/image.scm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index 5fc0d55d9a14..f07a4a52174f 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -652,6 +652,8 @@ (define shared-network?
                shared-network?)
               (list boot-program)))
          (substitutable? (image-substitutable? image))
+         (image-target (or (%current-target-system)
+                           (nix-system->gnu-triplet)))
          (register-closures? (has-guix-service-type? os))
          (schema (and register-closures?
                       (local-file (search-path %load-path
@@ -705,6 +707,7 @@ (define builder
                  #:entry-point '(#$boot-program #$os)
                  #:compressor '(#+(file-append gzip "/bin/gzip") "-9n")
                  #:creation-time (make-time time-utc 0 1)
+                 #:system #$image-target
                  #:transformations `((,image-root -> ""))))))))
 
     (computed-file name builder




Reply sent to Mathieu Othacehe <othacehe <at> gnu.org>:
You have taken responsibility. (Fri, 04 Nov 2022 07:48:01 GMT) Full text and rfc822 format available.

Notification sent to Thiago Jung Bauermann <bauermann <at> kolabnow.com>:
bug acknowledged by developer. (Fri, 04 Nov 2022 07:48:01 GMT) Full text and rfc822 format available.

Message #21 received at 58576-done <at> debbugs.gnu.org (full text, mbox):

From: Mathieu Othacehe <othacehe <at> gnu.org>
To: Thiago Jung Bauermann <bauermann <at> kolabnow.com>
Cc: 58576-done <at> debbugs.gnu.org
Subject: Re: [PATCH v2] system: image: Define correct docker image arch when
 cross building
Date: Fri, 04 Nov 2022 08:46:52 +0100
Hello Thiago,

> * gnu/system/image.scm (system-docker-image) Add ‘image-target’ variable.
> [builder]: Pass ‘#:system’ argument to ‘build-docker-image’.

Applied as a75deb884468db0ce2c35e23a61f1a14c9be958e.

Thanks,

Mathieu




Information forwarded to guix-patches <at> gnu.org:
bug#58576; Package guix-patches. (Sat, 05 Nov 2022 03:06:01 GMT) Full text and rfc822 format available.

Message #24 received at 58576-done <at> debbugs.gnu.org (full text, mbox):

From: Thiago Jung Bauermann <bauermann <at> kolabnow.com>
To: Mathieu Othacehe <othacehe <at> gnu.org>
Cc: 58576-done <at> debbugs.gnu.org
Subject: Re: [PATCH v2] system: image: Define correct docker image arch when
 cross building
Date: Sat, 05 Nov 2022 00:04:32 -0300
Hello Mathieu,

Mathieu Othacehe <othacehe <at> gnu.org> writes:

>> * gnu/system/image.scm (system-docker-image) Add ‘image-target’ variable.
>> [builder]: Pass ‘#:system’ argument to ‘build-docker-image’.
>
> Applied as a75deb884468db0ce2c35e23a61f1a14c9be958e.

Thank you!

-- 
Thanks
Thiago




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 03 Dec 2022 12:24:15 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 202 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.