GNU bug report logs - #71263
Add additional fields to oci-container-configuration

Previous Next

Package: guix-patches;

Reported by: paul <goodoldpaul <at> autistici.org>

Date: Wed, 29 May 2024 21:38:02 UTC

Severity: normal

Done: Zheng Junjie <zhengjunjie <at> iscas.ac.cn>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Giacomo Leidi <goodoldpaul <at> autistici.org>
To: 71263 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul <at> autistici.org>, Florian Pelz <pelzflorian <at> pelzflorian.de>, Ludovic Courtès <ludo <at> gnu.org>, Matthew Trzcinski <matt <at> excalamus.com>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Subject: [bug#71263] [PATCH 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration.
Date: Wed, 29 May 2024 23:38:53 +0200
* gnu/services/docker.scm (oci-container-configuration)
[log-file]: New field;
(oci-container-shepherd-service): use it.

Change-Id: Icad29ac6342b6f5bafc0d9be13a93cee99674185
---
 doc/guix.texi           |  5 +++++
 gnu/services/docker.scm | 36 ++++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 8662586b46..954196b14c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40644,6 +40644,11 @@ Miscellaneous Services
 Set additional Shepherd services dependencies to the provisioned
 Shepherd service.
 
+@item @code{log-file} (default: @code{""}) (type: string)
+When @code{log-file} is set, it names the file to which the service's
+standard output and standard error are redirected.  @code{log-file} is created
+if it does not exist, otherwise it is appended to.
+
 @item @code{network} (default: @code{""}) (type: string)
 Set a Docker network for the spawned container.
 
diff --git a/gnu/services/docker.scm b/gnu/services/docker.scm
index 7aff8dcc5f..678e8b1139 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -74,6 +74,7 @@ (define-module (gnu services docker)
             oci-container-configuration-image
             oci-container-configuration-provision
             oci-container-configuration-requirement
+            oci-container-configuration-log-file
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -461,6 +462,11 @@ (define-configuration/no-serialization oci-container-configuration
    (list-of-symbols '())
    "Set additional Shepherd services dependencies to the provisioned Shepherd
 service.")
+  (log-file
+   (maybe-string)
+   "When @code{log-file} is set, it names the file to which the service’s
+standard output and standard error are redirected.  @code{log-file} is created
+if it does not exist, otherwise it is appended to.")
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -669,12 +675,16 @@ (define (oci-container-shepherd-service config)
          (host-environment
           (oci-container-configuration-host-environment config))
          (command (oci-container-configuration-command config))
+         (log-file (oci-container-configuration-log-file config))
          (provision (oci-container-configuration-provision config))
          (requirement (oci-container-configuration-requirement config))
          (image (oci-container-configuration-image config))
          (image-reference (oci-image-reference image))
          (options (oci-container-configuration->options config))
          (name (guess-name provision image))
+         (loader (if (oci-image? image)
+                     (%oci-image-loader name image image-reference)
+                     #f))
          (extra-arguments
           (oci-container-configuration-extra-arguments config)))
 
@@ -687,18 +697,20 @@ (define (oci-container-shepherd-service config)
                         (if (oci-image? image) name image) "."))
                       (start
                        #~(lambda ()
-                          (when #$(oci-image? image)
-                            (invoke #$(%oci-image-loader
-                                       name image image-reference)))
-                          (fork+exec-command
-                           ;; docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
-                           (list #$docker "run" "--rm" "--name" #$name
-                                 #$@options #$@extra-arguments
-                                 #$image-reference #$@command)
-                           #:user #$user
-                           #:group #$group
-                           #:environment-variables
-                           (list #$@host-environment))))
+                           (when #$(oci-image? image)
+                             (invoke #$loader))
+                           (fork+exec-command
+                            ;; docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
+                            (list #$docker "run" "--rm" "--name" #$name
+                                  #$@options #$@extra-arguments
+                                  #$image-reference #$@command)
+                            #:user #$user
+                            #:group #$group
+                            #$@(if (maybe-value-set? log-file)
+                                   (list #:log-file log-file)
+                                   '())
+                            #:environment-variables
+                            (list #$@host-environment))))
                       (stop
                        #~(lambda _
                            (invoke #$docker "rm" "-f" #$name)))
-- 
2.41.0





This bug report was last modified 319 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.