unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#71263] Add additional fields to oci-container-configuration
@ 2024-05-29 21:37 paul via Guix-patches via
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: paul via Guix-patches via @ 2024-05-29 21:37 UTC (permalink / raw)
  To: 71263

Hello Guixers,

I'm sending a patch series to add some fields to the 
oci-container-configuration .

Thank you for your work

giacomo





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

* [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation.
  2024-05-29 21:37 [bug#71263] Add additional fields to oci-container-configuration paul via Guix-patches via
@ 2024-05-29 21:38 ` Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
                     ` (3 more replies)
  2024-06-11 20:01 ` [bug#71263] [PATCH v2] Add additional fields to oci-container-configuration - Rebase on current master paul via Guix-patches via
  2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2 siblings, 4 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-05-29 21:38 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* doc/guix.texi: Clarify the example and remove reduntant escapes.

Change-Id: I38f5517ae46b391ba21ae5a94c6dcc272e245036
---
 doc/guix.texi | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c1ff049f03..8662586b46 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40547,6 +40547,7 @@ Miscellaneous Services
 (service oci-container-service-type
          (list
           (oci-container-configuration
+           (network "host")
            (image
             (oci-image
              (repository "guile")
@@ -40559,20 +40560,17 @@ Miscellaneous Services
             '("-c" "(display \"hello!\n\")")))
           (oci-container-configuration
            (image "prom/prometheus")
-           (network "host")
            (ports
              '(("9000" . "9000")
                ("9090" . "9090"))))
           (oci-container-configuration
            (image "grafana/grafana:10.0.1")
            (network "host")
-           (ports
-             '(("3000" . "3000")))
            (volumes
              '("/var/lib/grafana:/var/lib/grafana")))))
 @end lisp
 
-In this example two different Shepherd services are going be added to the
+In this example three different Shepherd services are going be added to the
 system.  Each @code{oci-container-configuration} record translates to a
 @code{docker run} invocation and its fields directly map to options.  You can
 refer to the
@@ -40580,8 +40578,8 @@ Miscellaneous Services
 documentation for the semantics of each value.  If the images are not found they
 will be
 @url{https://docs.docker.com/engine/reference/commandline/pull/,pulled}.  The
-spawned services are going to be attached to the host network and are supposed
-to behave like other processes.
+services with @code{(network "host")} are going to be attached to the host network
+and are supposed to behave like native processes with regard to networking.
 
 @end defvar
 
@@ -40613,8 +40611,8 @@ Miscellaneous Services
 value can be a list of pairs or strings, even mixed:
 
 @lisp
-(list '(\"LANGUAGE\" . \"eo:ca:eu\")
-      \"JAVA_HOME=/opt/java\")
+(list '("LANGUAGE\" . "eo:ca:eu")
+      "JAVA_HOME=/opt/java")
 @end lisp
 
 Pair members can be strings, gexps or file-like objects. Strings are passed

base-commit: 6f72ad465c1e2df965e8d73b209497b4ef456527
-- 
2.41.0





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

* [bug#71263] [PATCH 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration.
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
@ 2024-05-29 21:38   ` Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 3/5] gnu: docker: Allow setting Shepherd auto-start? " Giacomo Leidi via Guix-patches via
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-05-29 21:38 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* 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





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

* [bug#71263] [PATCH 3/5] gnu: docker: Allow setting Shepherd auto-start? in oci-container-configuration.
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
@ 2024-05-29 21:38   ` Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 4/5] gnu: docker: Allow setting Shepherd respawn? " Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 5/5] gnu: docker: Allow setting Shepherd actions " Giacomo Leidi via Guix-patches via
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-05-29 21:38 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[auto-start?]: New field;
(oci-container-shepherd-service): use it.

Change-Id: Id093d93effbbec3e1be757f8be83cf5f62eaeda7
---
 doc/guix.texi           | 4 ++++
 gnu/services/docker.scm | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 954196b14c..dfc4d65349 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40649,6 +40649,10 @@ Miscellaneous Services
 standard output and standard error are redirected.  @code{log-file} is created
 if it does not exist, otherwise it is appended to.
 
+@item @code{auto-start?} (default: @code{#t}) (type: boolean)
+Whether this service should be started automatically by the Shepherd.  If it
+is @code{#f} the service has to be started manually with @command{herd start}.
+
 @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 678e8b1139..712ca14cba 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -75,6 +75,7 @@ (define-module (gnu services docker)
             oci-container-configuration-provision
             oci-container-configuration-requirement
             oci-container-configuration-log-file
+            oci-container-configuration-auto-start?
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -467,6 +468,10 @@ (define-configuration/no-serialization oci-container-configuration
    "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.")
+  (auto-start?
+   (boolean #t)
+   "Whether this service should be started automatically by the Shepherd.  If it
+is @code{#f} the service has to be started manually with @command{herd start}.")
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -670,6 +675,8 @@ (define (oci-container-shepherd-service config)
                             (oci-image-repository image))))))
 
   (let* ((docker (file-append docker-cli "/bin/docker"))
+         (auto-start?
+          (oci-container-configuration-auto-start? config))
          (user (oci-container-configuration-user config))
          (group (oci-container-configuration-group config))
          (host-environment
@@ -691,6 +698,7 @@ (define (oci-container-shepherd-service config)
     (shepherd-service (provision `(,(string->symbol name)))
                       (requirement `(dockerd user-processes ,@requirement))
                       (respawn? #f)
+                      (auto-start? auto-start?)
                       (documentation
                        (string-append
                         "Docker backed Shepherd service for "
-- 
2.41.0





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

* [bug#71263] [PATCH 4/5] gnu: docker: Allow setting Shepherd respawn? in oci-container-configuration.
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 3/5] gnu: docker: Allow setting Shepherd auto-start? " Giacomo Leidi via Guix-patches via
@ 2024-05-29 21:38   ` Giacomo Leidi via Guix-patches via
  2024-05-29 21:38   ` [bug#71263] [PATCH 5/5] gnu: docker: Allow setting Shepherd actions " Giacomo Leidi via Guix-patches via
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-05-29 21:38 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[respawn?]: New field;
(oci-container-shepherd-service): use it.

Change-Id: I0d6367607fd0fd41f90a54b33d80bf4d4f43dd8b
---
 doc/guix.texi           | 4 ++++
 gnu/services/docker.scm | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index dfc4d65349..9abdc77869 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40653,6 +40653,10 @@ Miscellaneous Services
 Whether this service should be started automatically by the Shepherd.  If it
 is @code{#f} the service has to be started manually with @command{herd start}.
 
+@item @code{respawn?} (default: @code{#f}) (type: boolean)
+Whether to have Shepherd restart the service when it stops, for instance when
+the underlying process dies.
+
 @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 712ca14cba..bc566e6316 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -76,6 +76,7 @@ (define-module (gnu services docker)
             oci-container-configuration-requirement
             oci-container-configuration-log-file
             oci-container-configuration-auto-start?
+            oci-container-configuration-respawn?
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -472,6 +473,10 @@ (define-configuration/no-serialization oci-container-configuration
    (boolean #t)
    "Whether this service should be started automatically by the Shepherd.  If it
 is @code{#f} the service has to be started manually with @command{herd start}.")
+  (respawn?
+   (boolean #f)
+   "Whether to restart the service when it stops, for instance when the
+underlying process dies.")
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -685,6 +690,8 @@ (define (oci-container-shepherd-service config)
          (log-file (oci-container-configuration-log-file config))
          (provision (oci-container-configuration-provision config))
          (requirement (oci-container-configuration-requirement config))
+         (respawn?
+          (oci-container-configuration-respawn? config))
          (image (oci-container-configuration-image config))
          (image-reference (oci-image-reference image))
          (options (oci-container-configuration->options config))
@@ -697,7 +704,7 @@ (define (oci-container-shepherd-service config)
 
     (shepherd-service (provision `(,(string->symbol name)))
                       (requirement `(dockerd user-processes ,@requirement))
-                      (respawn? #f)
+                      (respawn? respawn?)
                       (auto-start? auto-start?)
                       (documentation
                        (string-append
-- 
2.41.0





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

* [bug#71263] [PATCH 5/5] gnu: docker: Allow setting Shepherd actions in oci-container-configuration.
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
                     ` (2 preceding siblings ...)
  2024-05-29 21:38   ` [bug#71263] [PATCH 4/5] gnu: docker: Allow setting Shepherd respawn? " Giacomo Leidi via Guix-patches via
@ 2024-05-29 21:38   ` Giacomo Leidi via Guix-patches via
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-05-29 21:38 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[shepherd-actions]: New field;
(sanitize-shepherd-actions): sanitize it;
(oci-container-shepherd-service): use it.

Change-Id: I0ca9826542be7cb8ca280a07a9bff1a262c2a8a7
---
 doc/guix.texi           |  4 ++++
 gnu/services/docker.scm | 38 +++++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 9abdc77869..4c137ee31e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40657,6 +40657,10 @@ Miscellaneous Services
 Whether to have Shepherd restart the service when it stops, for instance when
 the underlying process dies.
 
+@item @code{shepherd-actions} (default: @code{'()}) (type: list-of-symbols)
+This is a list of @code{shepherd-action} records defining actions supported
+by the service.
+
 @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 bc566e6316..78d7e2f04e 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -77,6 +77,7 @@ (define-module (gnu services docker)
             oci-container-configuration-log-file
             oci-container-configuration-auto-start?
             oci-container-configuration-respawn?
+            oci-container-configuration-shepherd-actions
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -328,6 +329,17 @@ (define (oci-sanitize-volumes value)
   ;; '(("/mnt/dir" . "/dir") "/run/current-system/profile:/java")
   (oci-sanitize-mixed-list "volumes" value ":"))
 
+(define (oci-sanitize-shepherd-actions value)
+  (map
+   (lambda (el)
+     (if (shepherd-action? el)
+         el
+         (raise
+          (formatted-message
+           (G_ "shepherd-actions may only be shepherd-action records
+but ~a was found") el))))
+   value))
+
 (define (oci-sanitize-extra-arguments value)
   (define (valid? member)
     (or (string? member)
@@ -477,6 +489,11 @@ (define-configuration/no-serialization oci-container-configuration
    (boolean #f)
    "Whether to restart the service when it stops, for instance when the
 underlying process dies.")
+  (shepherd-actions
+   (list '())
+   "This is a list of @code{shepherd-action} records defining actions supported
+by the service."
+   (sanitizer oci-sanitize-shepherd-actions))
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -680,6 +697,7 @@ (define (oci-container-shepherd-service config)
                             (oci-image-repository image))))))
 
   (let* ((docker (file-append docker-cli "/bin/docker"))
+         (actions (oci-container-configuration-shepherd-actions config))
          (auto-start?
           (oci-container-configuration-auto-start? config))
          (user (oci-container-configuration-user config))
@@ -732,15 +750,17 @@ (define (oci-container-shepherd-service config)
                       (actions
                        (if (oci-image? image)
                            '()
-                           (list
-                            (shepherd-action
-                             (name 'pull)
-                             (documentation
-                              (format #f "Pull ~a's image (~a)."
-                                      name image))
-                             (procedure
-                              #~(lambda _
-                                  (invoke #$docker "pull" #$image))))))))))
+                           (append
+                            (list
+                             (shepherd-action
+                              (name 'pull)
+                              (documentation
+                               (format #f "Pull ~a's image (~a)."
+                                       name image))
+                              (procedure
+                               #~(lambda _
+                                   (invoke #$docker "pull" #$image)))))
+                            actions))))))
 
 (define %oci-container-accounts
   (list (user-account
-- 
2.41.0





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

* [bug#71263] [PATCH v2] Add additional fields to oci-container-configuration - Rebase on current master
  2024-05-29 21:37 [bug#71263] Add additional fields to oci-container-configuration paul via Guix-patches via
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
@ 2024-06-11 20:01 ` paul via Guix-patches via
  2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2 siblings, 0 replies; 12+ messages in thread
From: paul via Guix-patches via @ 2024-06-11 20:01 UTC (permalink / raw)
  To: 71263; +Cc: Ludovic Courtès, maxim.cournoyer, pelzflorian, matt

Hello Guixers,

I'm sending an updated patchset, rebased on current master.

Thank you for your work,


giacomo





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

* [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation.
  2024-05-29 21:37 [bug#71263] Add additional fields to oci-container-configuration paul via Guix-patches via
  2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2024-06-11 20:01 ` [bug#71263] [PATCH v2] Add additional fields to oci-container-configuration - Rebase on current master paul via Guix-patches via
@ 2024-06-11 20:04 ` Giacomo Leidi via Guix-patches via
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
                     ` (3 more replies)
  2 siblings, 4 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-06-11 20:04 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* doc/guix.texi: Clarify the example and remove reduntant escapes.

Change-Id: I38f5517ae46b391ba21ae5a94c6dcc272e245036
---
 doc/guix.texi | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 769ca1399f..5a06d7cdc5 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40601,6 +40601,7 @@ Miscellaneous Services
 (service oci-container-service-type
          (list
           (oci-container-configuration
+           (network "host")
            (image
             (oci-image
              (repository "guile")
@@ -40613,20 +40614,17 @@ Miscellaneous Services
             '("-c" "(display \"hello!\n\")")))
           (oci-container-configuration
            (image "prom/prometheus")
-           (network "host")
            (ports
              '(("9000" . "9000")
                ("9090" . "9090"))))
           (oci-container-configuration
            (image "grafana/grafana:10.0.1")
            (network "host")
-           (ports
-             '(("3000" . "3000")))
            (volumes
              '("/var/lib/grafana:/var/lib/grafana")))))
 @end lisp
 
-In this example two different Shepherd services are going be added to the
+In this example three different Shepherd services are going be added to the
 system.  Each @code{oci-container-configuration} record translates to a
 @code{docker run} invocation and its fields directly map to options.  You can
 refer to the
@@ -40634,8 +40632,8 @@ Miscellaneous Services
 documentation for the semantics of each value.  If the images are not found they
 will be
 @url{https://docs.docker.com/engine/reference/commandline/pull/,pulled}.  The
-spawned services are going to be attached to the host network and are supposed
-to behave like other processes.
+services with @code{(network "host")} are going to be attached to the host network
+and are supposed to behave like native processes with regard to networking.
 
 @end defvar
 
@@ -40667,8 +40665,8 @@ Miscellaneous Services
 value can be a list of pairs or strings, even mixed:
 
 @lisp
-(list '(\"LANGUAGE\" . \"eo:ca:eu\")
-      \"JAVA_HOME=/opt/java\")
+(list '("LANGUAGE\" . "eo:ca:eu")
+      "JAVA_HOME=/opt/java")
 @end lisp
 
 Pair members can be strings, gexps or file-like objects. Strings are passed

base-commit: df5648daa1a5d097a430131bbff353b865b476b6
-- 
2.45.1





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

* [bug#71263] [PATCH v2 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration.
  2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
@ 2024-06-11 20:04   ` Giacomo Leidi via Guix-patches via
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 3/5] gnu: docker: Allow setting Shepherd auto-start? " Giacomo Leidi via Guix-patches via
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-06-11 20:04 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[log-file]: New field;
(oci-container-shepherd-service): use it.

* doc/guix.texi: Document it.

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

diff --git a/doc/guix.texi b/doc/guix.texi
index 5a06d7cdc5..40296fcd5f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40698,6 +40698,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 cc1201508c..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,10 +697,8 @@ (define (oci-container-shepherd-service config)
                         (if (oci-image? image) name image) "."))
                       (start
                        #~(lambda ()
-                           #$@(if (oci-image? image)
-                                  #~((invoke #$(%oci-image-loader
-                                                name image image-reference)))
-                                  #~())
+                           (when #$(oci-image? image)
+                             (invoke #$loader))
                            (fork+exec-command
                             ;; docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
                             (list #$docker "run" "--rm" "--name" #$name
@@ -698,6 +706,9 @@ (define (oci-container-shepherd-service config)
                                   #$image-reference #$@command)
                             #:user #$user
                             #:group #$group
+                            #$@(if (maybe-value-set? log-file)
+                                   (list #:log-file log-file)
+                                   '())
                             #:environment-variables
                             (list #$@host-environment))))
                       (stop
-- 
2.45.1





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

* [bug#71263] [PATCH v2 3/5] gnu: docker: Allow setting Shepherd auto-start? in oci-container-configuration.
  2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
@ 2024-06-11 20:04   ` Giacomo Leidi via Guix-patches via
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 4/5] gnu: docker: Allow setting Shepherd respawn? " Giacomo Leidi via Guix-patches via
  2024-06-11 20:05   ` [bug#71263] [PATCH v2 5/5] gnu: docker: Allow setting Shepherd actions " Giacomo Leidi via Guix-patches via
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-06-11 20:04 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[auto-start?]: New field;
(oci-container-shepherd-service): use it.

* doc/guix.texi: Document it.

Change-Id: Id093d93effbbec3e1be757f8be83cf5f62eaeda7
---
 doc/guix.texi           | 4 ++++
 gnu/services/docker.scm | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 40296fcd5f..cc3847eadb 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40703,6 +40703,10 @@ Miscellaneous Services
 standard output and standard error are redirected.  @code{log-file} is created
 if it does not exist, otherwise it is appended to.
 
+@item @code{auto-start?} (default: @code{#t}) (type: boolean)
+Whether this service should be started automatically by the Shepherd.  If it
+is @code{#f} the service has to be started manually with @command{herd start}.
+
 @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 678e8b1139..712ca14cba 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -75,6 +75,7 @@ (define-module (gnu services docker)
             oci-container-configuration-provision
             oci-container-configuration-requirement
             oci-container-configuration-log-file
+            oci-container-configuration-auto-start?
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -467,6 +468,10 @@ (define-configuration/no-serialization oci-container-configuration
    "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.")
+  (auto-start?
+   (boolean #t)
+   "Whether this service should be started automatically by the Shepherd.  If it
+is @code{#f} the service has to be started manually with @command{herd start}.")
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -670,6 +675,8 @@ (define (oci-container-shepherd-service config)
                             (oci-image-repository image))))))
 
   (let* ((docker (file-append docker-cli "/bin/docker"))
+         (auto-start?
+          (oci-container-configuration-auto-start? config))
          (user (oci-container-configuration-user config))
          (group (oci-container-configuration-group config))
          (host-environment
@@ -691,6 +698,7 @@ (define (oci-container-shepherd-service config)
     (shepherd-service (provision `(,(string->symbol name)))
                       (requirement `(dockerd user-processes ,@requirement))
                       (respawn? #f)
+                      (auto-start? auto-start?)
                       (documentation
                        (string-append
                         "Docker backed Shepherd service for "
-- 
2.45.1





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

* [bug#71263] [PATCH v2 4/5] gnu: docker: Allow setting Shepherd respawn? in oci-container-configuration.
  2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 3/5] gnu: docker: Allow setting Shepherd auto-start? " Giacomo Leidi via Guix-patches via
@ 2024-06-11 20:04   ` Giacomo Leidi via Guix-patches via
  2024-06-11 20:05   ` [bug#71263] [PATCH v2 5/5] gnu: docker: Allow setting Shepherd actions " Giacomo Leidi via Guix-patches via
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-06-11 20:04 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[respawn?]: New field;
(oci-container-shepherd-service): use it.

* doc/guix.texi: Document it.

Change-Id: I0d6367607fd0fd41f90a54b33d80bf4d4f43dd8b
---
 doc/guix.texi           | 4 ++++
 gnu/services/docker.scm | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index cc3847eadb..6dae5939d5 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40707,6 +40707,10 @@ Miscellaneous Services
 Whether this service should be started automatically by the Shepherd.  If it
 is @code{#f} the service has to be started manually with @command{herd start}.
 
+@item @code{respawn?} (default: @code{#f}) (type: boolean)
+Whether to have Shepherd restart the service when it stops, for instance when
+the underlying process dies.
+
 @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 712ca14cba..bc566e6316 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -76,6 +76,7 @@ (define-module (gnu services docker)
             oci-container-configuration-requirement
             oci-container-configuration-log-file
             oci-container-configuration-auto-start?
+            oci-container-configuration-respawn?
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -472,6 +473,10 @@ (define-configuration/no-serialization oci-container-configuration
    (boolean #t)
    "Whether this service should be started automatically by the Shepherd.  If it
 is @code{#f} the service has to be started manually with @command{herd start}.")
+  (respawn?
+   (boolean #f)
+   "Whether to restart the service when it stops, for instance when the
+underlying process dies.")
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -685,6 +690,8 @@ (define (oci-container-shepherd-service config)
          (log-file (oci-container-configuration-log-file config))
          (provision (oci-container-configuration-provision config))
          (requirement (oci-container-configuration-requirement config))
+         (respawn?
+          (oci-container-configuration-respawn? config))
          (image (oci-container-configuration-image config))
          (image-reference (oci-image-reference image))
          (options (oci-container-configuration->options config))
@@ -697,7 +704,7 @@ (define (oci-container-shepherd-service config)
 
     (shepherd-service (provision `(,(string->symbol name)))
                       (requirement `(dockerd user-processes ,@requirement))
-                      (respawn? #f)
+                      (respawn? respawn?)
                       (auto-start? auto-start?)
                       (documentation
                        (string-append
-- 
2.45.1





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

* [bug#71263] [PATCH v2 5/5] gnu: docker: Allow setting Shepherd actions in oci-container-configuration.
  2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
                     ` (2 preceding siblings ...)
  2024-06-11 20:04   ` [bug#71263] [PATCH v2 4/5] gnu: docker: Allow setting Shepherd respawn? " Giacomo Leidi via Guix-patches via
@ 2024-06-11 20:05   ` Giacomo Leidi via Guix-patches via
  3 siblings, 0 replies; 12+ messages in thread
From: Giacomo Leidi via Guix-patches via @ 2024-06-11 20:05 UTC (permalink / raw)
  To: 71263
  Cc: Giacomo Leidi, Florian Pelz, Ludovic Courtès,
	Matthew Trzcinski, Maxim Cournoyer

* gnu/services/docker.scm (oci-container-configuration)
[shepherd-actions]: New field;
(sanitize-shepherd-actions): sanitize it;
(oci-container-shepherd-service): use it.

* doc/guix.texi: Document it.

Change-Id: I0ca9826542be7cb8ca280a07a9bff1a262c2a8a7
---
 doc/guix.texi           |  4 ++++
 gnu/services/docker.scm | 38 +++++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6dae5939d5..fd49ab860e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40711,6 +40711,10 @@ Miscellaneous Services
 Whether to have Shepherd restart the service when it stops, for instance when
 the underlying process dies.
 
+@item @code{shepherd-actions} (default: @code{'()}) (type: list-of-symbols)
+This is a list of @code{shepherd-action} records defining actions supported
+by the service.
+
 @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 bc566e6316..78d7e2f04e 100644
--- a/gnu/services/docker.scm
+++ b/gnu/services/docker.scm
@@ -77,6 +77,7 @@ (define-module (gnu services docker)
             oci-container-configuration-log-file
             oci-container-configuration-auto-start?
             oci-container-configuration-respawn?
+            oci-container-configuration-shepherd-actions
             oci-container-configuration-network
             oci-container-configuration-ports
             oci-container-configuration-volumes
@@ -328,6 +329,17 @@ (define (oci-sanitize-volumes value)
   ;; '(("/mnt/dir" . "/dir") "/run/current-system/profile:/java")
   (oci-sanitize-mixed-list "volumes" value ":"))
 
+(define (oci-sanitize-shepherd-actions value)
+  (map
+   (lambda (el)
+     (if (shepherd-action? el)
+         el
+         (raise
+          (formatted-message
+           (G_ "shepherd-actions may only be shepherd-action records
+but ~a was found") el))))
+   value))
+
 (define (oci-sanitize-extra-arguments value)
   (define (valid? member)
     (or (string? member)
@@ -477,6 +489,11 @@ (define-configuration/no-serialization oci-container-configuration
    (boolean #f)
    "Whether to restart the service when it stops, for instance when the
 underlying process dies.")
+  (shepherd-actions
+   (list '())
+   "This is a list of @code{shepherd-action} records defining actions supported
+by the service."
+   (sanitizer oci-sanitize-shepherd-actions))
   (network
    (maybe-string)
    "Set a Docker network for the spawned container.")
@@ -680,6 +697,7 @@ (define (oci-container-shepherd-service config)
                             (oci-image-repository image))))))
 
   (let* ((docker (file-append docker-cli "/bin/docker"))
+         (actions (oci-container-configuration-shepherd-actions config))
          (auto-start?
           (oci-container-configuration-auto-start? config))
          (user (oci-container-configuration-user config))
@@ -732,15 +750,17 @@ (define (oci-container-shepherd-service config)
                       (actions
                        (if (oci-image? image)
                            '()
-                           (list
-                            (shepherd-action
-                             (name 'pull)
-                             (documentation
-                              (format #f "Pull ~a's image (~a)."
-                                      name image))
-                             (procedure
-                              #~(lambda _
-                                  (invoke #$docker "pull" #$image))))))))))
+                           (append
+                            (list
+                             (shepherd-action
+                              (name 'pull)
+                              (documentation
+                               (format #f "Pull ~a's image (~a)."
+                                       name image))
+                              (procedure
+                               #~(lambda _
+                                   (invoke #$docker "pull" #$image)))))
+                            actions))))))
 
 (define %oci-container-accounts
   (list (user-account
-- 
2.45.1





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

end of thread, other threads:[~2024-06-11 20:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-29 21:37 [bug#71263] Add additional fields to oci-container-configuration paul via Guix-patches via
2024-05-29 21:38 ` [bug#71263] [PATCH 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
2024-05-29 21:38   ` [bug#71263] [PATCH 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
2024-05-29 21:38   ` [bug#71263] [PATCH 3/5] gnu: docker: Allow setting Shepherd auto-start? " Giacomo Leidi via Guix-patches via
2024-05-29 21:38   ` [bug#71263] [PATCH 4/5] gnu: docker: Allow setting Shepherd respawn? " Giacomo Leidi via Guix-patches via
2024-05-29 21:38   ` [bug#71263] [PATCH 5/5] gnu: docker: Allow setting Shepherd actions " Giacomo Leidi via Guix-patches via
2024-06-11 20:01 ` [bug#71263] [PATCH v2] Add additional fields to oci-container-configuration - Rebase on current master paul via Guix-patches via
2024-06-11 20:04 ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Giacomo Leidi via Guix-patches via
2024-06-11 20:04   ` [bug#71263] [PATCH v2 2/5] gnu: docker: Allow setting Shepherd log-file in oci-container-configuration Giacomo Leidi via Guix-patches via
2024-06-11 20:04   ` [bug#71263] [PATCH v2 3/5] gnu: docker: Allow setting Shepherd auto-start? " Giacomo Leidi via Guix-patches via
2024-06-11 20:04   ` [bug#71263] [PATCH v2 4/5] gnu: docker: Allow setting Shepherd respawn? " Giacomo Leidi via Guix-patches via
2024-06-11 20:05   ` [bug#71263] [PATCH v2 5/5] gnu: docker: Allow setting Shepherd actions " Giacomo Leidi via Guix-patches via

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).