From patchwork Wed Jul 12 08:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Graham James Addis X-Patchwork-Id: 51682 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 1174427BBE9; Wed, 12 Jul 2023 09:21:31 +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_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 E3C6127BBE2 for ; Wed, 12 Jul 2023 09:21:29 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJV60-0006hQ-Py; Wed, 12 Jul 2023 04:21:12 -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 1qJV5y-0006PP-PG for guix-patches@gnu.org; Wed, 12 Jul 2023 04:21:10 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJV5x-0004Oy-Pq; Wed, 12 Jul 2023 04:21:09 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qJV5p-0005Mf-K2; Wed, 12 Jul 2023 04:21:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64171] [PATCH 0/1 v2] guix: pack: docker add --entry-point-argument options References: In-Reply-To: Resent-From: Graham James Addis Original-Sender: "Debbugs-submit" Resent-CC: mail@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: Wed, 12 Jul 2023 08:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64171 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64171@debbugs.gnu.org Cc: Graham James Addis , 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 64171-submit@debbugs.gnu.org id=B64171.168915002920571 (code B ref 64171); Wed, 12 Jul 2023 08:21:01 +0000 Received: (at 64171) by debbugs.gnu.org; 12 Jul 2023 08:20:29 +0000 Received: from localhost ([127.0.0.1]:51669 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJV53-0005LT-Vk for submit@debbugs.gnu.org; Wed, 12 Jul 2023 04:20:28 -0400 Received: from mail-wr1-f52.google.com ([209.85.221.52]:42119) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJV4p-0005Ke-BK for 64171@debbugs.gnu.org; Wed, 12 Jul 2023 04:20:12 -0400 Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-31297125334so267593f8f.0 for <64171@debbugs.gnu.org>; Wed, 12 Jul 2023 01:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689149993; x=1691741993; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6DvfRgU6D1RFgcOYW1czGv18FOcvyTmIi94uKKh8lsk=; b=ASkIcXDbzkNN/hofLOUl0+4hbKBy1GaW/VIuXHeSTc/H/5O6cQxoztJId06Gs5IUb/ Dd44I/v6AArQKVdMK+fCmovyLW0gFaMpZe9NwUSl52gKr6BmwvHI/f8WDNhiRGXbW7bB y0pB7lKMjUNYfPrfYmSS7ONOEvb+E1luDzXR7unGi9J3p66RFUSvdsk5VoJcPGEUpeML rSam7IUZsjjnTjfj+U7PZD9M4EQ2GKu2dJYHKSYsq8dtlrrAU2cArMYGt7mQgTyay2SY 5Z2XUnyawWhZbpiceu7d3E8GrPpJxSorrxgSTnrGBAK8yOFa8eJlwGw6hZcC9tm5FIBh dpdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689149993; x=1691741993; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6DvfRgU6D1RFgcOYW1czGv18FOcvyTmIi94uKKh8lsk=; b=jZSXW3HFgYOU6eH2yjEhpCMS9/+67KiEV3h+On/bpfu/eJYrln7gHAdNxyhTFdJ6ma GyU6+ZT5J3ATe91hqROD0+NVQ56wWATYVDWGZWbg8/9PlShTuA4mWDNj+6q+D0namOWf qx1sLMnRKq7hBhXWwNss62dYgqQj/R11kS8AEn8s197RwNmMWP/004pZ8vSuAAu/gti6 evra036VKe/ugSo38r0wJ8SvX0cV8MEr8LVVIYZkesGJV2BSoiOxEwxp5Jn6cj0sClz0 5e6wJUF3kzjWp1kddcADv3pIoF8auD89UY3Vk4W03bFghEpiEOd2dolX6qJxRlWesbKM J4SQ== X-Gm-Message-State: ABy/qLY0EFzPrRaJKr/IFJ1YFAwWggf2nDbBA2dfYHaQKsUtQ1ekZKKY pWM4sCAWj3+v9u43pJkXj2z7FrMuv9I= X-Google-Smtp-Source: APBJJlHy096H++8hNajgX2CJPB73t6L+5KhTv4WNGX6f1QdRrzAWDfm+p4vVyz+KePV7zwMiG+X+vA== X-Received: by 2002:a05:6000:180f:b0:311:b18:9ca4 with SMTP id m15-20020a056000180f00b003110b189ca4mr1017156wrh.17.1689149992966; Wed, 12 Jul 2023 01:19:52 -0700 (PDT) Received: from guix-test.home ([2a00:23c7:59a9:c901:41c8:db68:b8b1:9808]) by smtp.gmail.com with ESMTPSA id 24-20020a05600c22d800b003fbaade072dsm4422283wmg.23.2023.07.12.01.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 01:19:52 -0700 (PDT) From: Graham James Addis X-Google-Original-From: Graham James Addis Date: Wed, 12 Jul 2023 09:17:13 +0100 Message-Id: <53f0c51cabbd317469721fb7f47b47af50d42177.1689149161.git.graham@addis.org.uk> X-Mailer: git-send-email 2.40.1 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/pack.scm: add support for parameters in entry-point (entry-point-argument-spec-option-parser): add function to parse --entry-point-argument (docker-image): Add function (form_entry_point) to handle --entry-point vs --entry-point-argument merging (docker-image): change call to (build-docker-image) to use (form-entry-point) (%default-options): add dafault for --entry-point-argument option (%docker-format-options): parser for --entry-point-argument (show-docker-format-options): help for --docker-format-options (show-docker-format-options/detailed): detailed help for --docker-format-options (%options): add flag for --help-docker-format and add parser for --docker-format-options (extra-options): add entry-point-argument option (guix.texi): add documentation --- doc/guix.texi | 14 +++++- guix/scripts/pack.scm | 107 ++++++++++++++++++++++++++++++++---------- 2 files changed, 95 insertions(+), 26 deletions(-) base-commit: 2426e51688d479042ea115a634c6be2d8b9f3b99 diff --git a/doc/guix.texi b/doc/guix.texi index 4e7faf8aea..10d220c7b9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -116,6 +116,7 @@ Copyright @copyright{} 2023 Karl Hallsby@* Copyright @copyright{} 2023 Nathaniel Nicandro@* Copyright @copyright{} 2023 Tanguy Le Carrour@* +Copyright @copyright{} 2023 Graham James Addis@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -7410,7 +7411,7 @@ Invoking guix pack @env{GUIX_EXECUTION_ENGINE} environment variable accordingly. @end quotation -@cindex entry point, for Docker images +@cindex entry point, for Docker and Singularity images @item --entry-point=@var{command} Use @var{command} as the @dfn{entry point} of the resulting pack, if the pack format supports it---currently @code{docker} and @code{squashfs} (Singularity) @@ -7433,6 +7434,17 @@ Invoking guix pack docker run @var{image-id} @end example +@cindex entry point arguments, for docker images +@item --entry-point-argument=@var{command} +@itemx -A @var{command} +Use @var{command} as an argument to @dfn{entry point} of the resulting pack. +This option is only valid in conjunction with @code{--entry-point} and can +appear multiple times on the command line. + +@example +guix pack -f docker --entry-point=bin/guile --entry-point-argument="--help" guile +@end example + @item --expression=@var{expr} @itemx -e @var{expr} Consider the package @var{expr} evaluates to. diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index 0dc9979194..c620eb9dc0 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer ;;; Copyright © 2020 Eric Bavier ;;; Copyright © 2022 Alex Griffin +;;; Copyright © 2023 Graham James Addis ;;; ;;; This file is part of GNU Guix. ;;; @@ -193,6 +194,16 @@ (define (symlink-spec-option-parser opt name arg result) (leave (G_ "~a: invalid symlink specification~%") arg)))) +(define (entry-point-argument-spec-option-parser opt name arg result) + "A SRFI-37 opion parser for the --entry-point-argument option. The spec +takes multiple occurances. The entries are used in the exec form for the +docker entry-point. The values are used as parameters in conjunction with +the --entry-point option which is used as the first value in the exec form." + (let ((entry-point-argument (assoc-ref result 'entry-point-argument))) + (alist-cons 'entry-point-argument + (append entry-point-argument (list arg)) + (alist-delete 'entry-point-argument result eq?)))) + (define (set-utf8-locale profile) "Configure the environment to use the \"en_US.utf8\" locale provided by the GLIBC-UT8-LOCALES package." @@ -626,6 +637,7 @@ (define* (docker-image name profile (guix build utils) (guix profiles) (guix search-paths) (srfi srfi-1) (srfi srfi-19) + (ice-9 optargs) (ice-9 match)) #$(procedure-source manifest->friendly-name) @@ -653,31 +665,48 @@ (define* (docker-image name profile `((directory "/tmp" ,(getuid) ,(getgid) #o1777) ,@(append-map symlink->directives '#$symlinks))) - (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)))))) - - (gexp->derivation (string-append name ".tar" - (compressor-extension compressor)) - build - #:target target - #:references-graphs `(("profile" ,profile)))) + (define (form-entry-point + prefix entry-point + entry-point-argument) + ;; construct entry-point parameter for build-docker-image + ;; the first entry is constructed by prefixing the entry-point + ;; with the supplied index subsequent entries are taken from + ;; the --entry-point-argument options + (cond + (entry-point + (cons* + (string-append prefix "/" entry-point) + entry-point-argument) + ) + ('()))) ;empty list returned if no conditions are met + + (let-keywords '#$extra-options #f ((entry-point-argument #f)) + + (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 (form-entry-point + #$profile + #$entry-point + entry-point-argument) + #:extra-files directives + #:compressor #+(compressor-command compressor) + #:creation-time (make-time time-utc 0 1))))))) + + (gexp->derivation (string-append name ".tar" + (compressor-extension compressor)) + build + #:target target + #:references-graphs `(("profile" ,profile)))) ;;; @@ -1346,6 +1375,7 @@ (define %default-options (debug . 0) (verbosity . 1) (symlinks . ()) + (entry-point-argument . ()) (compressor . ,(first %compressors)))) (define %formats @@ -1428,6 +1458,25 @@ (define (show-rpm-format-options/detailed) (newline) (exit 0)) + +(define %docker-format-options + (list (option '(#\A "entry-point-argument") #t #f + entry-point-argument-spec-option-parser))) + +(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_ " + -A, --entry-point-argument=COMMAND/PARAMETER + Value(s) to use for the Docker EntryPoint arguments. + Multiple instances are accepted. This is only valid + in conjunction with the --entry-point option.")) + (newline) + (exit 0)) + (define %options ;; Specifications of the command-line options. (cons* (option '(#\h "help") #f #f @@ -1508,8 +1557,13 @@ (define %options (lambda args (show-rpm-format-options/detailed))) + (option '("help-docker-format") #f #f + (lambda args + (show-docker-format-options/detailed))) + (append %deb-format-options %rpm-format-options + %docker-format-options %transformation-options %standard-build-options %standard-cross-build-options @@ -1528,6 +1582,7 @@ (define (show-help) (newline) (show-deb-format-options) (show-rpm-format-options) + (show-docker-format-options) (newline) (display (G_ " -f, --format=FORMAT build a pack in the given FORMAT")) @@ -1696,6 +1751,8 @@ (define-command (guix-pack . args) (process-file-arg opts 'preun-file) #:postun-file (process-file-arg opts 'postun-file))) + ('docker + (list #:entry-point-argument (assoc-ref opts 'entry-point-argument))) (_ '()))) (target (assoc-ref opts 'target)) (bootstrap? (assoc-ref opts 'bootstrap?))