From patchwork Wed May 29 21:38:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: paul X-Patchwork-Id: 64937 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3AA9827BBEA; Wed, 29 May 2024 22:40:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A3BEA27BBE9 for ; Wed, 29 May 2024 22:40:16 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCR1a-0000p1-V5; Wed, 29 May 2024 17:39:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCR1Z-0000oQ-GI for guix-patches@gnu.org; Wed, 29 May 2024 17:39:57 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCR1Z-0001os-7F; Wed, 29 May 2024 17:39:57 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sCR1i-0008E3-EZ; Wed, 29 May 2024 17:40:06 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71263] [PATCH 5/5] gnu: docker: Allow setting Shepherd actions in oci-container-configuration. Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 29 May 2024 21:40:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71263 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 71263@debbugs.gnu.org Cc: Giacomo Leidi , Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 71263-submit@debbugs.gnu.org id=B71263.171701877831477 (code B ref 71263); Wed, 29 May 2024 21:40:06 +0000 Received: (at 71263) by debbugs.gnu.org; 29 May 2024 21:39:38 +0000 Received: from localhost ([127.0.0.1]:55977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCR1F-0008BY-DC for submit@debbugs.gnu.org; Wed, 29 May 2024 17:39:37 -0400 Received: from confino.investici.org ([93.190.126.19]:27333) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCR19-0008Af-7y for 71263@debbugs.gnu.org; Wed, 29 May 2024 17:39:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1717018753; bh=dYNFlJvCIPj1IpiBTm/0Bkd4FI18jAmcFmPwVBTWp30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rUshopFwlaSCxA9ajS0wwwnuzUPjeYzVq6EmoFc5CKeTS1Qu0eMZ1fLZaAb8op+W2 3o/haFBFeftmOFEj2Pg8dBc17NVOJl7cM85ZbVLKib2sT51co2SuA1EpqaHlD0B/a8 sgRYgW4mmRWVJNiOfz39r84xS4SKp3zBxVFDfiWs= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4VqN7P2lB1z1117; Wed, 29 May 2024 21:39:13 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4VqN7P2C32z110x; Wed, 29 May 2024 21:39:13 +0000 (UTC) Date: Wed, 29 May 2024 23:38:56 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <31ff6a93a8c7b50e5152f75b091b28851d5c4cc8.1717018735.git.goodoldpaul@autistici.org> References: <31ff6a93a8c7b50e5152f75b091b28851d5c4cc8.1717018735.git.goodoldpaul@autistici.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches X-Patchwork-Original-From: Giacomo Leidi via Guix-patches via From: paul Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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