all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options
@ 2023-06-19 15:37 Graham James Addis
  2023-06-19 15:38 ` [bug#64173] [PATCH 1/1] " Graham James Addis
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Graham James Addis @ 2023-06-19 15:37 UTC (permalink / raw)
  To: 64171
  Cc: Graham James Addis, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

This patch adds an option to guix pack to allow multiple parameters to
be passed to the guix pack --format=docker command.

Currently the although the --entry-point option can be entered multiple
times, only the last entry is used as the docker ENTRYPOINT.

Using the new --docker-entry-point option will take multiple entries
and use them in the docker ENTRYPOINT exec form.

Using --docker-entry-point will override any setting of --entry-point.

The existing behaviour of --entry-point is retained if --docker-entry-point
is not specified.

Graham James Addis (1):
  guix: pack: docker add docker-entry-point options

 doc/guix.texi         |  16 +++++-
 guix/scripts/pack.scm | 113 ++++++++++++++++++++++++++++++++----------
 2 files changed, 103 insertions(+), 26 deletions(-)


base-commit: d884fc9e2efecfba09af4694f5a13ad7fc6f704f
-- 
2.39.2





^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64173] [PATCH 1/1] guix: pack: docker add docker-entry-point options
  2023-06-19 15:37 [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Graham James Addis
@ 2023-06-19 15:38 ` Graham James Addis
       [not found] ` <handler.64172.B.168718911211626.ack@debbugs.gnu.org>
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Graham James Addis @ 2023-06-19 15:38 UTC (permalink / raw)
  To: 64173
  Cc: Graham James Addis, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

* guix/scripts/pack.scm: add support for parameters in entry-point
(docker-entry-point-spec-option-parser): add function to parse --docker-entry-point
(docker-image): Add function (form_entry_point) to handle --entry-point
vs --docker-entry-point precedence
(docker-image): change call to (build-docker-image) to use (form-entry-point)
(%default-options): add dafault for --docker-entry-point option
(%docker-format-options): parser for --docker-entry-point
(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 extra options for docker
(guix.texi): add documentation
---
 doc/guix.texi         |  16 +++++-
 guix/scripts/pack.scm | 113 ++++++++++++++++++++++++++++++++----------
 2 files changed, 103 insertions(+), 26 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c961f706ec..8d8044f73c 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
@@ -7346,7 +7347,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)
@@ -7369,6 +7370,19 @@ Invoking guix pack
 docker run @var{image-id}
 @end example
 
+@cindex entry point, for Docker images
+@item --docker-entry-point=@var{command}
+Use @var{command} as the @dfn{entry point} of the resulting pack. This option
+overrides any value passed to @code{--entry-point} and can appear multiple
+times on the command line. The first instance of @var{command} is used as th
+@dfn{entry point} and subsequent values are used as the parameters.
+@var{command} must be relative to the profile contained in the
+pack.
+
+@example
+guix pack -f docker --docker-entry-point=bin/guile --docker-entry-point="--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..79739cb465 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Eric Bavier <bavier@posteo.net>
 ;;; Copyright © 2022 Alex Griffin <a@ajgrf.com>
+;;; Copyright © 2023 Graham James Addis <graham@addis.org.uk>
 ;;;
 ;;; 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 (docker-entry-point-spec-option-parser opt name arg result)
+  "A SRFI-37 opion parser for the --docker-entry-point option. The spec
+takes multiple occurances. The entries are used in the exec form for the
+docker entry-point. The first is used as the command and subsequent values
+are used as parameters."
+  (let ((docker-entry-point (assoc-ref result 'docker-entry-point)))
+    (alist-cons 'docker-entry-point
+                (append docker-entry-point (list arg))
+                (alist-delete 'docker-entry-point 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,50 @@ (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
+                     docker-entry-point
+                     prefix entry-point)
+              ;; construct entry-point parameter for build-docker-image
+              ;; overriding the legacy use of --entry-point from the command
+              ;; line when the --docker-entry-point options are used
+              (cond
+               ;; if CLI --docker-entry-point values are available use them
+               ((and docker-entry-point (not (null? docker-entry-point))
+                    (cons
+                     (string-append prefix "/" (car docker-entry-point))
+                     (cdr docker-entry-point))))
+               ;; legacy behaviour uses --entry-point and prefixes with #$profile
+               (entry-point (list (string-append prefix "/" entry-point)))
+               ('()))) ;empty list returned if no conditions are met
+
+            (let-keywords '#$extra-options #f ((docker-entry-point #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
+                                                 docker-entry-point
+                                                 #$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))))
 
 \f
 ;;;
@@ -1346,6 +1377,7 @@ (define %default-options
     (debug . 0)
     (verbosity . 1)
     (symlinks . ())
+    (docker-entry-point . ())
     (compressor . ,(first %compressors))))
 
 (define %formats
@@ -1428,6 +1460,29 @@ (define (show-rpm-format-options/detailed)
   (newline)
   (exit 0))
 
+
+(define %docker-format-options
+  (list (option '("docker-entry-point") #t #f
+                docker-entry-point-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_ "
+      --docker-entry-point=COMMAND/PARAMETER
+                         Value(s) to use for the Docker EntryPoint field.
+                         Multiple instances are accepted. The first use is
+                         supplied as the COMMAND in the Docker EntryPoint,
+                         subsequent uses are supplied as PARAMETERs in the
+                         Docker EntryPoint.
+                         This overrides any COMMAND provided in the
+                         --entry-point option."))
+  (newline)
+  (exit 0))
+
 (define %options
   ;; Specifications of the command-line options.
   (cons* (option '(#\h "help") #f #f
@@ -1508,8 +1563,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 +1588,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 +1757,8 @@ (define-command (guix-pack . args)
                                            (process-file-arg opts 'preun-file)
                                            #:postun-file
                                            (process-file-arg opts 'postun-file)))
+                                    ('docker
+                                     (list #:docker-entry-point (assoc-ref opts 'docker-entry-point)))
                                     (_ '())))
                    (target      (assoc-ref opts 'target))
                    (bootstrap?  (assoc-ref opts 'bootstrap?))
-- 
2.39.2





^ permalink raw reply related	[flat|nested] 13+ messages in thread

* bug#64172: Acknowledgement ([PATCH 0/1] ] guix: pack: docker add docker-entry-point options)
       [not found] ` <handler.64172.B.168718911211626.ack@debbugs.gnu.org>
@ 2023-06-19 15:49   ` Graham Addis
  0 siblings, 0 replies; 13+ messages in thread
From: Graham Addis @ 2023-06-19 15:49 UTC (permalink / raw)
  To: 64172-done

Accidently included an emacs backup file in the patch submission.

The correct bugs should be 64171 and 64173. This can be closed.

On Mon, 19 Jun 2023 at 16:39, GNU bug Tracking System
<help-debbugs@gnu.org> wrote:
>
> Thank you for filing a new bug report with debbugs.gnu.org.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> As you requested using X-Debbugs-CC, your message was also forwarded to
>   Christopher Baines <mail@cbaines.net>, Josselin Poiret <dev@jpoiret.xyz>, Ludovic Courtès <ludo@gnu.org>, Mathieu Othacehe <othacehe@gnu.org>, Ricardo Wurmus <rekado@elephly.net>, Simon Tournier <zimon.toutoune@gmail.com>, Tobias Geerinckx-Rice <me@tobias.gr>
> (after having been given a bug report number, if it did not have one).
>
> Your message has been sent to the package maintainer(s):
>  guix-patches@gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 64172@debbugs.gnu.org.
>
> Please do not send mail to help-debbugs@gnu.org unless you wish
> to report a problem with the Bug-tracking system.
>
> --
> 64172: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64172
> GNU Bug Tracking System
> Contact help-debbugs@gnu.org with problems




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options
  2023-06-19 15:37 [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Graham James Addis
  2023-06-19 15:38 ` [bug#64173] [PATCH 1/1] " Graham James Addis
       [not found] ` <handler.64172.B.168718911211626.ack@debbugs.gnu.org>
@ 2023-07-03  9:25 ` Ludovic Courtès
  2023-07-03 12:44   ` Graham Addis
  2023-07-12  8:17 ` [bug#64171] [PATCH 0/1 v2] guix: pack: docker add --entry-point-argument options Graham James Addis
  3 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2023-07-03  9:25 UTC (permalink / raw)
  To: Graham James Addis
  Cc: Graham James Addis, Josselin Poiret, Tobias Geerinckx-Rice,
	Simon Tournier, Mathieu Othacehe, Christopher Baines, 64171,
	Ricardo Wurmus

Hi,

Graham James Addis <grahamjamesaddis@gmail.com> skribis:

> This patch adds an option to guix pack to allow multiple parameters to
> be passed to the guix pack --format=docker command.
>
> Currently the although the --entry-point option can be entered multiple
> times, only the last entry is used as the docker ENTRYPOINT.
>
> Using the new --docker-entry-point option will take multiple entries
> and use them in the docker ENTRYPOINT exec form.

How about this alternative route: support multiple ‘--entry-point’
arguments.  The first one is passed to the backend as #:entry-point (as
is currently the case) and extra instances are passed as a list as
#:entry-point-arguments.

That way one could do:

  guix pack -f docker guile \
    --entry-point=bin/guile --entry-point=--version

Or, perhaps even better, introduce a new ‘--entry-point-argument’ (or
‘-A’) option.

The advantage compared to ‘--docker-entry-point’ is that it could be
supported by all the backends.

WDYT?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options
  2023-07-03  9:25 ` [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Ludovic Courtès
@ 2023-07-03 12:44   ` Graham Addis
  2023-07-03 16:40     ` Giovanni Biscuolo
  0 siblings, 1 reply; 13+ messages in thread
From: Graham Addis @ 2023-07-03 12:44 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Graham James Addis, Josselin Poiret, Tobias Geerinckx-Rice,
	Simon Tournier, Mathieu Othacehe, Christopher Baines, 64171,
	Ricardo Wurmus

Hi Ludo,

Happy to rework it either way. I can't think of any showstoppers off
the top of my head.

Which option would make the most sense?

Thanks,

Graham

On Mon, 3 Jul 2023 at 10:26, Ludovic Courtès <ludo@gnu.org> wrote:
>
> Hi,
>
> Graham James Addis <grahamjamesaddis@gmail.com> skribis:
>
> > This patch adds an option to guix pack to allow multiple parameters to
> > be passed to the guix pack --format=docker command.
> >
> > Currently the although the --entry-point option can be entered multiple
> > times, only the last entry is used as the docker ENTRYPOINT.
> >
> > Using the new --docker-entry-point option will take multiple entries
> > and use them in the docker ENTRYPOINT exec form.
>
> How about this alternative route: support multiple ‘--entry-point’
> arguments.  The first one is passed to the backend as #:entry-point (as
> is currently the case) and extra instances are passed as a list as
> #:entry-point-arguments.
>
> That way one could do:
>
>   guix pack -f docker guile \
>     --entry-point=bin/guile --entry-point=--version
>
> Or, perhaps even better, introduce a new ‘--entry-point-argument’ (or
> ‘-A’) option.
>
> The advantage compared to ‘--docker-entry-point’ is that it could be
> supported by all the backends.
>
> WDYT?
>
> Thanks,
> Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options
  2023-07-03 12:44   ` Graham Addis
@ 2023-07-03 16:40     ` Giovanni Biscuolo
  2023-07-08 16:08       ` Graham Addis
  0 siblings, 1 reply; 13+ messages in thread
From: Giovanni Biscuolo @ 2023-07-03 16:40 UTC (permalink / raw)
  To: Graham Addis, Ludovic Courtès; +Cc: 64171

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

Graham Addis <grahamjamesaddis@gmail.com> writes:

> Hi Ludo,
>
> Happy to rework it either way. I can't think of any showstoppers off
> the top of my head.
>
> Which option would make the most sense?

[...]

>> Or, perhaps even better, introduce a new ‘--entry-point-argument’ (or
>> ‘-A’) option.

IMO ‘--entry-point-argument’ is more semantic, its destination is clearer

[...]

Thanks a lot for this patch!

Happy hacking, Gio'

-- 
Giovanni Biscuolo

Xelera IT Infrastructures

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 849 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options
  2023-07-03 16:40     ` Giovanni Biscuolo
@ 2023-07-08 16:08       ` Graham Addis
  2023-07-09  8:31         ` Josselin Poiret via Guix-patches via
  0 siblings, 1 reply; 13+ messages in thread
From: Graham Addis @ 2023-07-08 16:08 UTC (permalink / raw)
  To: Giovanni Biscuolo; +Cc: Ludovic Courtès, 64171

One last question, as the proposed changes no longer reflect this bug
description, should I raise a new bug, or just add the replacement
patch to this one?

On Mon, 3 Jul 2023 at 17:40, Giovanni Biscuolo <g@xelera.eu> wrote:
>
> Graham Addis <grahamjamesaddis@gmail.com> writes:
>
> > Hi Ludo,
> >
> > Happy to rework it either way. I can't think of any showstoppers off
> > the top of my head.
> >
> > Which option would make the most sense?
>
> [...]
>
> >> Or, perhaps even better, introduce a new ‘--entry-point-argument’ (or
> >> ‘-A’) option.
>
> IMO ‘--entry-point-argument’ is more semantic, its destination is clearer
>
> [...]
>
> Thanks a lot for this patch!
>
> Happy hacking, Gio'
>
> --
> Giovanni Biscuolo
>
> Xelera IT Infrastructures




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options
  2023-07-08 16:08       ` Graham Addis
@ 2023-07-09  8:31         ` Josselin Poiret via Guix-patches via
  0 siblings, 0 replies; 13+ messages in thread
From: Josselin Poiret via Guix-patches via @ 2023-07-09  8:31 UTC (permalink / raw)
  To: Graham Addis, Giovanni Biscuolo; +Cc: Ludovic Courtès, 64171

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

Hi Graham,

Graham Addis <grahamjamesaddis@gmail.com> writes:

> One last question, as the proposed changes no longer reflect this bug
> description, should I raise a new bug, or just add the replacement
> patch to this one?

You can retitle bugs on debbugs, have a look at [1].

[1] https://debbugs.gnu.org/server-control.html

Best,
-- 
Josselin Poiret

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 682 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [PATCH 0/1 v2] guix: pack: docker add --entry-point-argument options
  2023-06-19 15:37 [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Graham James Addis
                   ` (2 preceding siblings ...)
  2023-07-03  9:25 ` [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Ludovic Courtès
@ 2023-07-12  8:17 ` Graham James Addis
  2023-08-17  9:42   ` [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option Ludovic Courtès
  3 siblings, 1 reply; 13+ messages in thread
From: Graham James Addis @ 2023-07-12  8:17 UTC (permalink / raw)
  To: 64171
  Cc: Graham James Addis, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

* 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(-)

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 <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Eric Bavier <bavier@posteo.net>
 ;;; Copyright © 2022 Alex Griffin <a@ajgrf.com>
+;;; Copyright © 2023 Graham James Addis <graham@addis.org.uk>
 ;;;
 ;;; 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))))
 
 \f
 ;;;
@@ -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?))

base-commit: 2426e51688d479042ea115a634c6be2d8b9f3b99
-- 
2.39.2





^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option
  2023-07-12  8:17 ` [bug#64171] [PATCH 0/1 v2] guix: pack: docker add --entry-point-argument options Graham James Addis
@ 2023-08-17  9:42   ` Ludovic Courtès
  2023-08-17 11:48     ` Simon Tournier
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2023-08-17  9:42 UTC (permalink / raw)
  To: Graham James Addis
  Cc: Graham James Addis, Josselin Poiret, Tobias Geerinckx-Rice, 64173,
	Simon Tournier, Mathieu Othacehe, Christopher Baines, 64171,
	Ricardo Wurmus

Hi Graham,

Apologies for the delay (holiday time!).

Graham James Addis <grahamjamesaddis@gmail.com> skribis:

> * 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

This is really a minor issue and I don’t mind fixing it for you, but
note that the ChangeLog style just needs to say what has been
changed/added/removed.  For example:

  (entry-point-argument-spec-option-parser): New procedure.

> (guix.texi): add documentation

And here:

  * doc/guix.texi (Inovking guix pack): Document it.

I like this new version.  Here are a few things that I think would need
to be changed before we can push:

> +@cindex entry point arguments, for docker images
> +@item --entry-point-argument=@var{command}
> +@itemx -A @var{command}

Maybe @var{argument} for consistency and clarity?

> +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.

Maybe add: “The example below shows illustrates that, passing
@option{--help} to the @command{guile} command:”

> +@example
> +guix pack -f docker --entry-point=bin/guile --entry-point-argument="--help" guile
> +@end example

[...]

> +(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?))))

I would just keep a regular option parser that does:

  (alist-cons 'entry-point-argument arg result)

Later on, we’d collect all these arguments:

  (reverse
   (filter-map (match-lambda
                (('entry-point-argument . arg) arg)
                (_ #f))
               opts))

I think this would be a bit clearer; this is what ‘guix repl’ does, for
instance.

> +            (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)
> +		)

I’d avoid this extra procedure.

> +	       ('()))) ;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)

How about keeping it similar to what it looks like currently:

                  #:entry-point
                  #$(and entry-point
                         #~(cons (string-append #$profile "/"
                                                #$entry-point)
                                 '#$(or (assoc-ref extra-options
                                                   #:entry-point-arguments)
                                        '())))


?

> @@ -1346,6 +1375,7 @@ (define %default-options
>      (debug . 0)
>      (verbosity . 1)
>      (symlinks . ())
> +    (entry-point-argument . ())

This can be omitted if you take the approach suggested above, with one
‘entry-point-argument’ pair per argument.

> +(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
> @@ -1528,6 +1582,7 @@ (define (show-help)
>    (newline)
>    (show-deb-format-options)
>    (show-rpm-format-options)
> +  (show-docker-format-options)

Leftover, can be removed.

> @@ -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)))

This would become #:entry-point-arguments (plural), with the
‘filter-map’ trick shown above.

Also, it should be possible to make it work for the Singularity backend,
right?  We can keep it for a subsequent commit if you prefer, but then
please add a TODO comment.

Could you send an updated patch?

Thanks in advance!

Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option
  2023-08-17  9:42   ` [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option Ludovic Courtès
@ 2023-08-17 11:48     ` Simon Tournier
  2023-08-18 14:00       ` [bug#64171] " Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Tournier @ 2023-08-17 11:48 UTC (permalink / raw)
  To: Ludovic Courtès, Graham James Addis
  Cc: Graham James Addis, Josselin Poiret, Christopher Baines, 64173,
	Mathieu Othacehe, Tobias Geerinckx-Rice, 64171, Ricardo Wurmus

Hi,

On Thu, 17 Aug 2023 at 11:42, Ludovic Courtès <ludo@gnu.org> wrote:

>> +(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?))))
>
> I would just keep a regular option parser that does:
>
>   (alist-cons 'entry-point-argument arg result)
>
> Later on, we’d collect all these arguments:
>
>   (reverse
>    (filter-map (match-lambda
>                 (('entry-point-argument . arg) arg)
>                 (_ #f))
>                opts))
>
> I think this would be a bit clearer; this is what ‘guix repl’ does, for
> instance.

[...]

> This can be omitted if you take the approach suggested above, with one
> ‘entry-point-argument’ pair per argument.

[...]

> This would become #:entry-point-arguments (plural), with the
> ‘filter-map’ trick shown above.

Just to be sure to understand, the command-line could list several
--entry-point-argument options, right?

Well, since the order of the various command-line arguments might
matter, and since a ’reverse’ is suggested, and since all the Guix
command-lines do not behave the same way – for instance “guix package”
processes command-line argument from right to left; see #43585 or #50473
[1,2]; anyway :-) – I would suggest to add a sentence in the
documentation (manual) that the command-line arguments are parsed from
left to right.


1: https://issues.guix.gnu.org/issue/43585
2: https://issues.guix.gnu.org/issue/50473


Cheers,
simon




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64171] [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option
  2023-08-17 11:48     ` Simon Tournier
@ 2023-08-18 14:00       ` Ludovic Courtès
  2023-08-18 14:15         ` Simon Tournier
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2023-08-18 14:00 UTC (permalink / raw)
  To: Simon Tournier
  Cc: Graham James Addis, Josselin Poiret, Christopher Baines, 64173,
	Mathieu Othacehe, Graham James Addis, Tobias Geerinckx-Rice,
	64171, Ricardo Wurmus

Hi,

Simon Tournier <zimon.toutoune@gmail.com> skribis:

> Just to be sure to understand, the command-line could list several
> --entry-point-argument options, right?

Yes.

> Well, since the order of the various command-line arguments might
> matter, and since a ’reverse’ is suggested, and since all the Guix
> command-lines do not behave the same way – for instance “guix package”
> processes command-line argument from right to left; see #43585 or #50473
> [1,2]; anyway :-) – I would suggest to add a sentence in the
> documentation (manual) that the command-line arguments are parsed from
> left to right.

No: the ‘reverse’ puts them back in the right order (because
‘args-fold*’ traverses the option list from left to right and thus
conses the result in reverse order.)

HTH!

Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option
  2023-08-18 14:00       ` [bug#64171] " Ludovic Courtès
@ 2023-08-18 14:15         ` Simon Tournier
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Tournier @ 2023-08-18 14:15 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Graham James Addis, Josselin Poiret, Christopher Baines, 64173,
	Mathieu Othacehe, Graham James Addis, Tobias Geerinckx-Rice,
	64171, Ricardo Wurmus

Hi,

On Fri, 18 Aug 2023 at 16:00, Ludovic Courtès <ludo@gnu.org> wrote:

> > Well, since the order of the various command-line arguments might
> > matter, and since a ’reverse’ is suggested, and since all the Guix
> > command-lines do not behave the same way – for instance “guix package”
> > processes command-line argument from right to left; see #43585 or #50473
> > [1,2]; anyway :-) – I would suggest to add a sentence in the
> > documentation (manual) that the command-line arguments are parsed from
> > left to right.
>
> No: the ‘reverse’ puts them back in the right order (because
> ‘args-fold*’ traverses the option list from left to right and thus
> conses the result in reverse order.)

Is "no" for not adding a sentence in the documentation? :-)

BTW, what means the "right order"? :-)
I point that "guix package" and "guix show" process the command-line
option in different order -- from right to left vs from left to right
respectively.  Thus, this "right order" you are assuming can be
confusing, IMHO.

Therefore, applying POLA, it appears to me worth to add under the
option description of this new "--entry-point-argument" in the manual:
"The @code{--entry-point-arguement} option is applied from left to
right."  Or something along this line.

My 2 cents.

Cheers,
simon




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-08-18 14:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-19 15:37 [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Graham James Addis
2023-06-19 15:38 ` [bug#64173] [PATCH 1/1] " Graham James Addis
     [not found] ` <handler.64172.B.168718911211626.ack@debbugs.gnu.org>
2023-06-19 15:49   ` bug#64172: Acknowledgement ([PATCH 0/1] ] guix: pack: docker add docker-entry-point options) Graham Addis
2023-07-03  9:25 ` [bug#64171] [PATCH 0/1] guix: pack: docker add docker-entry-point options Ludovic Courtès
2023-07-03 12:44   ` Graham Addis
2023-07-03 16:40     ` Giovanni Biscuolo
2023-07-08 16:08       ` Graham Addis
2023-07-09  8:31         ` Josselin Poiret via Guix-patches via
2023-07-12  8:17 ` [bug#64171] [PATCH 0/1 v2] guix: pack: docker add --entry-point-argument options Graham James Addis
2023-08-17  9:42   ` [bug#64173] [PATCH 0/1] guix: pack: add --entry-point-argument option Ludovic Courtès
2023-08-17 11:48     ` Simon Tournier
2023-08-18 14:00       ` [bug#64171] " Ludovic Courtès
2023-08-18 14:15         ` Simon Tournier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.