all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Giacomo Leidi via Guix-patches via <guix-patches@gnu.org>
To: 71263@debbugs.gnu.org
Cc: "Giacomo Leidi" <goodoldpaul@autistici.org>,
	"Florian Pelz" <pelzflorian@pelzflorian.de>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Matthew Trzcinski" <matt@excalamus.com>,
	"Maxim Cournoyer" <maxim.cournoyer@gmail.com>
Subject: [bug#71263] [PATCH v2 5/5] gnu: docker: Allow setting Shepherd actions in oci-container-configuration.
Date: Tue, 11 Jun 2024 22:05:00 +0200	[thread overview]
Message-ID: <fe85fac13179f2ea71781de31fa6b9e4faab072b.1718136300.git.goodoldpaul@autistici.org> (raw)
In-Reply-To: <bb976d4b2da5054cf182816b7070574bee1e1e45.1718136300.git.goodoldpaul@autistici.org>

* 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





  parent reply	other threads:[~2024-06-11 20:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-07-05  7:35     ` Zheng Junjie
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   ` Giacomo Leidi via Guix-patches via [this message]
2024-07-05  7:41   ` [bug#71263] [PATCH v2 1/5] doc: Minor changes to the OCI-backed Services documentation Zheng Junjie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe85fac13179f2ea71781de31fa6b9e4faab072b.1718136300.git.goodoldpaul@autistici.org \
    --to=guix-patches@gnu.org \
    --cc=71263@debbugs.gnu.org \
    --cc=goodoldpaul@autistici.org \
    --cc=ludo@gnu.org \
    --cc=matt@excalamus.com \
    --cc=maxim.cournoyer@gmail.com \
    --cc=pelzflorian@pelzflorian.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.