From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:700:3204::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id QB8XEaUJhmWSHgEAkFu2QA (envelope-from ) for ; Fri, 22 Dec 2023 23:11:49 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 6GDnC6UJhmVOmwAAe85BDQ (envelope-from ) for ; Fri, 22 Dec 2023 23:11:49 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=YuYjRw36; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1703283109; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=WIdghL2EFkaMIkV3uFgNz4YTc2irAtyxalC2c8RxhrI=; b=O5PjAr55QWV5rEwv/T+ccYfMfVwZfobEeb2jUVYvBKD3ld67Gv21PLxQGCjFB/5sr1hTEX Tq+D0Lw1wSdXbe+yoEST/XZOi44Nit/S6dYA9z+WXCwZB5sRcfesAaIbe9h9HFoiE9Dl1S kbMcpBGRJT6c9Qn8xKAnvITYsj3UqidzFwgxDcZ+YWJb305NCmVqBdifWlpSHD1dZ+tSar 6Be5VmZlD2e3RLAURP05mwb6v2Y5OIfSSVkcBb1TJk/5MYiyR8T/OxC2wj+8qNuKAwkQN+ 37LGcrnmlySexjPlerWP0xfH5VGrt9RvqpbQ06S5qHZzbYOmFqWUNiZI9RE/kw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=YuYjRw36; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1703283109; a=rsa-sha256; cv=none; b=GFh+DoNWpemyBE778j5qmIDqnij61VaT6uWKIew8xThog6pPYhVVEDAk/6GTLyundOZ+oK NiHgBVuWwYFdJkzVMb/GRG/mnN95GdTaMlruVLx+tdSisG/2GzWBudQ1SjVUaEV+kj8Yv6 T+0GSS0YLEvQ8kY1z3WT0AcnfaAtkmNOGq9Ldn2j6AUXz+0jssdjxsZzsUNwe4dxPbTPjO BSprWF0UGvbxgSP8kyTYEw3dmsfvllH1X4DNysPGkCHCcfSV0RmpDvOWQF29zT8rIBKprg eU4O9ENDdNLDBRzgcdATtZU3egKk8Ut+HQcIhAKBVqUkrlcRit/8rRH/6pjbzg== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CB264515D4 for ; Fri, 22 Dec 2023 23:11:48 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGnjX-000876-Rp; Fri, 22 Dec 2023 17:11:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGnjP-00086o-AY for guix-patches@gnu.org; Fri, 22 Dec 2023 17:11:00 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGnjN-00076M-PW for guix-patches@gnu.org; Fri, 22 Dec 2023 17:10:58 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rGnjS-00072D-H4 for guix-patches@gnu.org; Fri, 22 Dec 2023 17:11:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#62153] [PATCH v4 1/2] guix: docker: Build layered image. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 22 Dec 2023 22:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62153 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Oleg Pykhalov Cc: Greg Hogan , 62153@debbugs.gnu.org Received: via spool by 62153-submit@debbugs.gnu.org id=B62153.170328303827002 (code B ref 62153); Fri, 22 Dec 2023 22:11:02 +0000 Received: (at 62153) by debbugs.gnu.org; 22 Dec 2023 22:10:38 +0000 Received: from localhost ([127.0.0.1]:48006 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rGnj3-00071R-Lw for submit@debbugs.gnu.org; Fri, 22 Dec 2023 17:10:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44370) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rGnj0-000718-6r for 62153@debbugs.gnu.org; Fri, 22 Dec 2023 17:10:36 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGnip-0006zS-NT; Fri, 22 Dec 2023 17:10:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=WIdghL2EFkaMIkV3uFgNz4YTc2irAtyxalC2c8RxhrI=; b=YuYjRw36Aa+I7sW1cTkQ gNfW9G9ESk2EqZzrFSKgLf7m7Cis9gZcI2qDz3h/oPm5rqvV1+DfgX3iNAdbQImNDlw+289Uxhk+s 5nz6GZtJJDRhRxTUR6b5Njk+/nBGwOgkNgtx2BmDxGDMU6JdK914mfvGJE5aHbyvrzsy6MQJiu7WL oxcvM3AmdiWzCOKXorOQ5YScKizhwFWjtANS3kS7wu4hvnAJh8MXBLXLmloTuoxDXe1MXzdPgxFqE tGIgn0TJtGDWBWX6i8/yiDPh842ZiJsN3nfQKNHZurny+u9AsATVBuiZius7GUeyoZ/EyyhR4oHlg dhMDMoYCY0AcKQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <457c813653a44117e296deaa49e79fc701b90791.1685819700.git.go.wigust@gmail.com> (Oleg Pykhalov's message of "Sat, 3 Jun 2023 22:14:59 +0300") References: <87y1l0icq0.fsf_-_@gmail.com> <457c813653a44117e296deaa49e79fc701b90791.1685819700.git.go.wigust@gmail.com> Date: Fri, 22 Dec 2023 23:10:20 +0100 Message-ID: <878r5l99df.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -6.90 X-Spam-Score: -6.90 X-Migadu-Queue-Id: CB264515D4 X-TUID: mQzUql/zbVqS Oleg Pykhalov skribis: > * doc/guix.texi (Invoking guix pack): Document docker-layered format. > (image Reference): Same. > (image-type Reference): Document docker-layered-image-type. > * gnu/image.scm > (validate-image-format)[docker-layered]: New image format. > * gnu/system/image.scm > (docker-layered-image, docker-layered-image-type): New variables. > (system-docker-image)[layered-image?]: New argument. > (system-docker-layered-image): New procedure. > (image->root-file-system)[docker-layered]: New image format. > * gnu/tests/docker.scm (%test-docker-layered-system): New test. > * guix/docker.scm (%docker-image-max-layers): New variable. > (build-docker-image)[stream-layered-image, root-system]: New arguments. > * guix/scripts/pack.scm (stream-layered-image.py): New variable. > (docker-image)[layered-image?]: New argument. > (docker-layered-image): New procedure. > (%formats)[docker-layered]: New format. > (show-formats): Document this. > * guix/scripts/system.scm > (system-derivation-for-action)[docker-layered-image]: New action. > (show-help): Document this. > (actions)[docker-layered-image]: New action. > (process-action): Add this. > * tests/pack.scm: Add "docker-layered-image + localstatedir" test. [...] > + #:use-module (guix diagnostics) > + #:use-module (guix i18n) (guix docker) shouldn=E2=80=99t need these. > + #:use-module (ice-9 popen) > + #:use-module (ice-9 rdelim) > + #:use-module (ice-9 receive) For consistency, I=E2=80=99d recommend (srfi srfi-71) instead of (ice-9 receive). > +(define %docker-image-max-layers > + 100) I=E2=80=99d add a comment on the second line, like =E2=80=9C;; Maximum numb= er of layers allowed in a Docker image according to =E2=80=A6=E2=80=9D. > +(define (paths-split-sort paths) > + "Split list of PATHS at %DOCKER-IMAGE-MAX-LAYERS and sort by disk usag= e." Nitpick: maybe (define (size-sorted-store-items items) =E2=80=A6)? > + (let* ((paths-length (length paths)) > + (port (apply open-pipe* OPEN_READ > + (append '("du" "--summarize") paths))) > + (output (read-string port))) > + (close-port port) How about: (map (lambda (item) (cons item (file-size item))) items) ? See (guix build store-copy) for the definition of =E2=80=98file-size=E2=80= =99. That way we avoid the dependency on Coreutils and code that =E2=80=9Cparses= =E2=80=9D the output of =E2=80=98du=E2=80=99. > + (define layers-hashes A short comment explaining what the inputs and outputs of this procedure are would be great. > + (match-lambda > + (((head ...) (tail ...) id) > + (create-empty-tar "image.tar") > + (let* ((head-layers > + (map > + (lambda (file) > + (invoke "tar" "cf" "layer.tar" file) > + (let* ((file-hash (layer-diff-id "layer.tar")) > + (file-name (string-append file-hash "/layer.tar= "))) > + (mkdir file-hash) > + (rename-file "layer.tar" file-name) > + (invoke "tar" "-rf" "image.tar" file-name) > + (delete-file file-name) > + file-hash)) > + head)) > + (tail-layer > + (begin > + (create-empty-tar "layer.tar") > + (for-each (lambda (file) > + (invoke "tar" "-rf" "layer.tar" file)) > + tail) > + (let* ((file-hash (layer-diff-id "layer.tar")) > + (file-name (string-append file-hash "/layer.tar"= ))) > + (mkdir file-hash) > + (rename-file "layer.tar" file-name) > + (invoke "tar" "-rf" "image.tar" file-name) > + (delete-file file-name) > + file-hash))) > + (customization-layer > + (let* ((file-id (string-append id "/layer.tar")) > + (file-hash (layer-diff-id file-id)) > + (file-name (string-append file-hash "/layer.tar"))) > + (mkdir file-hash) > + (rename-file file-id file-name) > + (invoke "tar" "-rf" "image.tar" file-name) > + file-hash)) > + (all-layers > + (append head-layers (list tail-layer customization-layer)= ))) Maybe this can be factorized a bit with: (define (seal-layer) ;; Add 'layer.tar' to 'image.tar' under the right name. Return its has= h. (let* ((file-hash (layer-diff-id "layer.tar")) (file-name (string-append file-hash "/layer.tar"))) (mkdir file-hash) (rename-file "layer.tar" file-name) (invoke "tar" "-rf" "image.tar" file-name) (delete-file file-name) file-hash))) ? Apart from this stylistic issues, it looks great to me. Thanks, Ludo=E2=80=99.