From patchwork Sat Oct 14 09:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Tempel?= X-Patchwork-Id: 54821 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 CEF1F27BBE2; Sat, 14 Oct 2023 10:41:58 +0100 (BST) 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_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED 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 AE99F27BBE9 for ; Sat, 14 Oct 2023 10:41:55 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrb9R-0006DA-Ci; Sat, 14 Oct 2023 05:41:41 -0400 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 1qrb9P-0006Cn-66 for guix-patches@gnu.org; Sat, 14 Oct 2023 05:41:39 -0400 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 1qrb9O-0000LA-UB for guix-patches@gnu.org; Sat, 14 Oct 2023 05:41:38 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qrb9l-0001LT-WF for guix-patches@gnu.org; Sat, 14 Oct 2023 05:42:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66296] [PATCH v2] pack: Allow setting a custom image tag for Docker images References: <20231001130615.18132-1-soeren@soeren-tempel.net> In-Reply-To: <20231001130615.18132-1-soeren@soeren-tempel.net> Resent-From: soeren@soeren-tempel.net Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 14 Oct 2023 09:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66296 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66296@debbugs.gnu.org Received: via spool by 66296-submit@debbugs.gnu.org id=B66296.16972764745107 (code B ref 66296); Sat, 14 Oct 2023 09:42:01 +0000 Received: (at 66296) by debbugs.gnu.org; 14 Oct 2023 09:41:14 +0000 Received: from localhost ([127.0.0.1]:47910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrb8z-0001KH-Tm for submit@debbugs.gnu.org; Sat, 14 Oct 2023 05:41:14 -0400 Received: from magnesium.8pit.net ([45.76.88.171]:20608) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrb8t-0001K2-Qi; Sat, 14 Oct 2023 05:41:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=Jtp9XJt4h3 21dIylP4F+Yla0H7ZPbtOaAkgIQzq86cY=; h=date:subject:to:from; d=soeren-tempel.net; b=J6QpODIUR+9uOaUm49x2CmkJq/09M1MNx8lUaAiPuDAsouB 6N8vPrsJpmJKeyB5rGkuRA7pCcFFvkCuOHGS2qkNiCnQWgZwETQ7Mq3GQO4uMBMGIbhnda vH9mqrraMuwxEM2tbir+n1Z9dEe5sAocwy0oRGZjwqDJh+t+eUpibQ= Received: from localhost (dynamic-2a02-3102-49da-001b-8819-7387-eed0-4220.310.pool.telefonica.de [2a02:3102:49da:1b:8819:7387:eed0:4220]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id d66855ea (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Sat, 14 Oct 2023 11:40:42 +0200 (CEST) From: soeren@soeren-tempel.net Date: Sat, 14 Oct 2023 11:38:56 +0200 Message-ID: <20231014094024.3993-3-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.42.0 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 From: Sören Tempel Previously, the image repository name was automatically computed from the packages in the manifest without allowing the user to set a custom one. As such, changing the packages in the manifest would result in a new image name. Thereby requiring updating documentation et cetera when using `docker load` directory on the resulting image. Inspired by `docker build -t`, this commit adds a new Docker-specific option to `guix pack` which allows setting a custom repository name for the resulting image. If this option is not specified, pack falls back to computing the name from the manifest. Therefore, this change is entirely backwards compatible. * guix/scripts/pack.scm (guix-pack): add --image-tag option * guix/scripts/pack.scm (%docker-format-options): new constant * guix/scripts/pack.scm (show-docker-format-options): new procedure * guix/scripts/pack.scm (show-docker-format-options/detailed): new procedure * guix/scripts/pack.scm (docker-image): allow setting a custom repository name for the created docker image via extra-options. * doc/guix.texi (Invoking guix pack)[docker]: Document --image-tag option Signed-off-by: Sören Tempel --- Changes since v1: Document the new --image-tag and --help-docker-format options in the Guix manual (Invoking guix pack). doc/guix.texi | 9 ++++-- guix/scripts/pack.scm | 66 ++++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8c5697589f..b9b45cfe9d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -7314,9 +7314,12 @@ specified binaries and symlinks. @item docker This produces a tarball that follows the @uref{https://github.com/docker/docker/blob/master/image/spec/v1.2.md, -Docker Image Specification}. The ``repository name'' as it appears in -the output of the @command{docker images} command is computed from -package names passed on the command line or in the manifest file. +Docker Image Specification}. By default, the ``repository name'' as it +appears in the output of the @command{docker images} command is computed +from package names passed on the command line or in the manifest file. +Alternatively, the ``repository name'' can also be configured via the +@option{--image-tag} option. Refer to @option{--help-docker-format} for +more information on such advanced options. @item squashfs This produces a SquashFS image containing all the specified binaries and diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index 01995c48b7..e7005e7bc6 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -507,7 +507,7 @@ (define* (docker-image name profile image is a tarball conforming to the Docker Image Specification, compressed with COMPRESSOR. It can be passed to 'docker load'. If TARGET is true, it must a be a GNU triplet and it is used to derive the architecture metadata in -the image." +the image. EXTRA-OPTIONS may contain the IMAGE-TAG keyword argument." (define database (and localstatedir? (file-append (store-database (list profile)) @@ -531,7 +531,7 @@ (define build (guix build utils) (guix profiles) (guix search-paths) (srfi srfi-1) (srfi srfi-19) - (ice-9 match)) + (ice-9 match) (ice-9 optargs)) #$(procedure-source manifest->friendly-name) @@ -560,23 +560,26 @@ (define directives (setenv "PATH" #+(file-append archiver "/bin")) - (build-docker-image #$output - (map store-info-item - (call-with-input-file "profile" - read-reference-graph)) - #$profile - #:repository (manifest->friendly-name - (profile-manifest #$profile)) - #:database #+database - #:system (or #$target %host-type) - #:environment environment - #:entry-point - #$(and entry-point - #~(list (string-append #$profile "/" - #$entry-point))) - #:extra-files directives - #:compressor #+(compressor-command compressor) - #:creation-time (make-time time-utc 0 1)))))) + (let-keywords '#$extra-options #f + ((image-tag #f)) + (build-docker-image #$output + (map store-info-item + (call-with-input-file "profile" + read-reference-graph)) + #$profile + #:repository (or image-tag + (manifest->friendly-name + (profile-manifest #$profile))) + #:database #+database + #:system (or #$target %host-type) + #:environment environment + #:entry-point + #$(and entry-point + #~(list (string-append #$profile "/" + #$entry-point))) + #:extra-files directives + #:compressor #+(compressor-command compressor) + #:creation-time (make-time time-utc 0 1))))))) (gexp->derivation (string-append name ".tar" (compressor-extension compressor)) @@ -1287,6 +1290,20 @@ (define (required-option symbol) (alist-cons symbol arg result) rest)))) +(define %docker-format-options + (list (required-option 'image-tag))) + +(define (show-docker-format-options) + (display (G_ " + --help-docker-format list options specific to the docker format"))) + +(define (show-docker-format-options/detailed) + (display (G_ " + --image-tag=NAME + Use the given NAME for the Docker image repository")) + (newline) + (exit 0)) + (define %deb-format-options (list (required-option 'control-file) (required-option 'postinst-file) @@ -1407,6 +1424,10 @@ (define %options (lambda (opt name arg result) (alist-cons 'bootstrap? #t result))) + (option '("help-docker-format") #f #f + (lambda args + (show-docker-format-options/detailed))) + (option '("help-deb-format") #f #f (lambda args (show-deb-format-options/detailed))) @@ -1415,7 +1436,8 @@ (define %options (lambda args (show-rpm-format-options/detailed))) - (append %deb-format-options + (append %docker-format-options + %deb-format-options %rpm-format-options %transformation-options %standard-build-options @@ -1433,6 +1455,7 @@ (define (show-help) (newline) (show-transformation-options-help) (newline) + (show-docker-format-options) (show-deb-format-options) (show-rpm-format-options) (newline) @@ -1586,6 +1609,9 @@ (define (process-file-arg opts name) manifest))) (pack-format (assoc-ref opts 'format)) (extra-options (match pack-format + ('docker + (list #:image-tag + (assoc-ref opts 'image-tag))) ('deb (list #:control-file (process-file-arg opts 'control-file)