From patchwork Tue Dec 26 02:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleg Pykhalov X-Patchwork-Id: 58073 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C916327BBEA; Tue, 26 Dec 2023 02:21:04 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 75DA027BBE2 for ; Tue, 26 Dec 2023 02:21:03 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHx3z-0006zT-Vt; Mon, 25 Dec 2023 21:21:00 -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 1rHx3z-0006yr-2g for guix-patches@gnu.org; Mon, 25 Dec 2023 21:20:59 -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 1rHx3y-0007hr-Os; Mon, 25 Dec 2023 21:20:58 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rHx44-0000nE-HL; Mon, 25 Dec 2023 21:21:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#62153] [PATCH 5/5] scripts: system: Build layered images. Resent-From: Oleg Pykhalov Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 26 Dec 2023 02:21:04 +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: 62153@debbugs.gnu.org Cc: Oleg Pykhalov , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 62153-submit@debbugs.gnu.org id=B62153.17035572112939 (code B ref 62153); Tue, 26 Dec 2023 02:21:04 +0000 Received: (at 62153) by debbugs.gnu.org; 26 Dec 2023 02:20:11 +0000 Received: from localhost ([127.0.0.1]:55620 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rHx3C-0000lF-AN for submit@debbugs.gnu.org; Mon, 25 Dec 2023 21:20:10 -0500 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]:39940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rHx35-0000jr-Kd for 62153@debbugs.gnu.org; Mon, 25 Dec 2023 21:20:06 -0500 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ccb6ddf651so5292801fa.0 for <62153@debbugs.gnu.org>; Mon, 25 Dec 2023 18:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703557190; x=1704161990; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6Ln2kxpz4n9WOq6SK1nelI1pbUl1f4tnE9yQEyDFGgY=; b=YOGYfJItCrRAr3tfB58bHsKHB0WqUJuQxEi8yUN7wRCp21GgrUUXG2pYDNJWXJFcEt IX0mgeQ8bZPx2ybnSs9lRdR+Pmp8bvj7U5geV8ShqEMTGAg+NbIIsukYxmEqL/0GSXr2 EDKWVmhQ1svq1RGxUKFs9k4+NVryYQsBWzyF6y8WaLnsmQ1+xAq98zSLz1WWbgu7yXay qfD/GiYWc5V3gZzX2HDuiFmCZo35ku26fNQgKyvtfWQyfzppI0a80AeAgDcxWP3YiRQQ JjeMduWnu1lya9hp4NL7OQHWZUjghQLnpJlszR7pm3Uz3Ivw1ZIM8PSdMMflG7eMMURa j6fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703557190; x=1704161990; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6Ln2kxpz4n9WOq6SK1nelI1pbUl1f4tnE9yQEyDFGgY=; b=UYnwQeXYNOcyRuziqmwA0cV0lu8dBhu65uI3n4LDdBn9Uoq6oKkRncQ0e9wuXxKA1f eE6ZMo4FPjQxETi6JCOvrCDIGWFT6Nbroqp+EAjQH85iF5qPw6+u3t1qO5XDZzo4iDvm TnuWEcLaUFCgDCh3DchXF1JnFTy2EHaU9chPO8SmZ85eYV3qgi8nQOwqD5kjYvl+4vBM CUgWy6l0GVC55E7iSPQEbs/sGnsm5vSEpDxrXP1IPkeGynCv7jxc2jZNcfqF+Xjidh/K gsTBL8hHNLSGKr1+fVP9QejTVgbbnajwHl7vbgVJ4Bes1RSatJEJwSJXAYxgteXKqDEu FKkw== X-Gm-Message-State: AOJu0YxYxxvok8V1RDuwzFMdJKmRQX9jwLd0tpRSqQ35wbAKFlKwcD9j qUL4WTUHbRrDbUHLg7y6Elmi7F9oCm4= X-Google-Smtp-Source: AGHT+IG/rxMVlkCB9cE/GnGt/Uh6hI6Qx34yP2sHrosJXhsK6g98pVrfRXdpCjFgIhFS0Ophc2iXsw== X-Received: by 2002:a2e:88ce:0:b0:2cc:85a6:25a3 with SMTP id a14-20020a2e88ce000000b002cc85a625a3mr5202517ljk.2.1703557190516; Mon, 25 Dec 2023 18:19:50 -0800 (PST) Received: from guixsd.wugi.info ([88.201.161.72]) by smtp.gmail.com with ESMTPSA id e11-20020a05651c038b00b002cca609ef8bsm1633436ljp.111.2023.12.25.18.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 18:19:49 -0800 (PST) From: Oleg Pykhalov Date: Tue, 26 Dec 2023 05:18:57 +0300 Message-ID: <99155dabc366c37acb71f6624aa6e6025b3e571b.1703556298.git.go.wigust@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/system.scm (show-help, %docker-format-options, %options, %default-options, show-docker-format-options, show-docker-format-options/detailed, process-action): Handle '--max-layers' option. * gnu/system/image.scm (system-docker-image): Same. * gnu/image.scm ()[max-layers]: New record field. Change-Id: I2726655aefd6688b976057fd5a38e9972ebfc292 --- gnu/image.scm | 4 ++++ gnu/system/image.scm | 41 ++++++++++++++++++++++++++++------------- guix/scripts/system.scm | 28 ++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/gnu/image.scm b/gnu/image.scm index 523653dd77..7fb06dec10 100644 --- a/gnu/image.scm +++ b/gnu/image.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2020, 2022 Mathieu Othacehe +;;; Copyright © 2023 Oleg Pykhalov ;;; ;;; This file is part of GNU Guix. ;;; @@ -42,6 +43,7 @@ (define-module (gnu image) image-format image-platform image-size + image-max-layers image-operating-system image-partition-table-type image-partitions @@ -170,6 +172,8 @@ (define-record-type* (size image-size ;size in bytes as integer (default 'guess) (sanitize validate-size)) + (max-layers image-max-layers ;number of layers as integer + (default #false)) (operating-system image-operating-system) ; (partition-table-type image-partition-table-type ; 'mbr or 'gpt (default 'mbr) diff --git a/gnu/system/image.scm b/gnu/system/image.scm index b825892232..2cc1012893 100644 --- a/gnu/system/image.scm +++ b/gnu/system/image.scm @@ -5,6 +5,7 @@ ;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; Copyright © 2022 Alex Griffin ;;; Copyright © 2023 Efraim Flashner +;;; Copyright © 2023 Oleg Pykhalov ;;; ;;; This file is part of GNU Guix. ;;; @@ -686,7 +687,8 @@ (define (image-with-label base-image label) (define* (system-docker-image image #:key - (name "docker-image")) + (name "docker-image") + (archiver tar)) "Build a docker image for IMAGE. NAME is the base name to use for the output file." (define boot-program @@ -731,6 +733,7 @@ (define* (system-docker-image image (use-modules (guix docker) (guix build utils) (gnu build image) + (srfi srfi-1) (srfi srfi-19) (guix build store-copy) (guix store database)) @@ -754,18 +757,30 @@ (define* (system-docker-image image #:register-closures? #$register-closures? #:deduplicate? #f #:system-directory #$os) - (build-docker-image - #$output - (cons* image-root - (map store-info-item - (call-with-input-file #$graph - read-reference-graph))) - #$os - #: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 -> "")))))))) + (when #$(image-max-layers image) + (setenv "PATH" + (string-join (list #+(file-append archiver "/bin") + #+(file-append gzip "/bin")) + ":"))) + (apply build-docker-image + (append (list #$output + (append (if #$(image-max-layers image) + '() + (list image-root)) + (map store-info-item + (call-with-input-file #$graph + read-reference-graph))) + #$os + #: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 -> ""))) + (if #$(image-max-layers image) + (list #:root-system image-root + #:max-layers #$(image-max-layers image)) + '())))))))) (computed-file name builder ;; Allow offloading so that this I/O-intensive process diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index f85b663d64..a21ecd4d1e 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -58,6 +58,7 @@ (define-module (guix scripts system) #:use-module (guix scripts system reconfigure) #:use-module (guix build utils) #:use-module (guix progress) + #:use-module ((guix docker) #:select (%docker-image-max-layers)) #:use-module (gnu build image) #:use-module (gnu build install) #:autoload (gnu build file-systems) @@ -1053,6 +1054,8 @@ (define (show-help) (newline) (show-native-build-options-help) (newline) + (show-docker-format-options) + (newline) (display (G_ " -h, --help display this help and exit")) (display (G_ " @@ -1060,6 +1063,12 @@ (define (show-help) (newline) (show-bug-report-information)) +(define %docker-format-options + (list (option '("max-layers") #t #f + (lambda (opt name arg result) + (alist-cons 'max-layers (string->number* arg) + result))))) + (define %options ;; Specifications of the command-line options. (cons* (option '(#\h "help") #f #f @@ -1154,7 +1163,8 @@ (define %options (alist-cons 'list-installed (or arg "") result))) (append %standard-build-options %standard-cross-build-options - %standard-native-build-options))) + %standard-native-build-options + %docker-format-options))) (define %default-options ;; Alist of default option values. @@ -1175,7 +1185,8 @@ (define %default-options (label . #f) (volatile-image-root? . #f) (volatile-vm-root? . #t) - (graph-backend . "graphviz"))) + (graph-backend . "graphviz") + (max-layers . ,%docker-image-max-layers))) (define (verbosity-level opts) "Return the verbosity level based on OPTS, the alist of parsed options." @@ -1183,6 +1194,17 @@ (define (verbosity-level opts) (if (eq? (assoc-ref opts 'action) 'build) 3 1))) +(define (show-docker-format-options) + (display (G_ " + --help-docker-format list options specific to the docker image type."))) + +(define (show-docker-format-options/detailed) + (display (G_ " + --max-layers=N + Number of image layers")) + (newline) + (exit 0)) + ;;; ;;; Entry point. @@ -1245,6 +1267,7 @@ (define (process-action action args opts) ((docker-image) docker-image-type) (else image-type))) (image-size (assoc-ref opts 'image-size)) + (image-max-layers (assoc-ref opts 'max-layers)) (volatile? (assoc-ref opts 'volatile-image-root?)) (shared-network? @@ -1258,6 +1281,7 @@ (define (process-action action args opts) (image-with-label base-image label) base-image)) (size image-size) + (max-layers image-max-layers) (volatile-root? volatile?) (shared-network? shared-network?)))) (os (or (image-operating-system image)