From patchwork Tue Jan 7 00:28:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 36695 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 6C8F727BBEA; Tue, 7 Jan 2025 00:30:21 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable 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 C704F27BBE2 for ; Tue, 7 Jan 2025 00:30:20 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUxU2-0002PA-42; Mon, 06 Jan 2025 19:30:10 -0500 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 1tUxU0-0002OV-AO for guix-patches@gnu.org; Mon, 06 Jan 2025 19:30:08 -0500 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 1tUxTy-00056b-Dv; Mon, 06 Jan 2025 19:30:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=SNm2sZ2qIGjuzk1vbimER/IVv5o9pFgJIM3SNvl/Mes=; b=o30i+q8MRv60fifnQfFflF0z+BiAcm5Ufg5vLNmi6fe6602bpS2hWvaNMiZrnTAWXzln4FDXMcg6MeCngskpb6tQc2p/Y7KA92Y9Dg268iSqR38DnPeTTdWckRUwYKDIRF1qvONZiEkcTNhK13po2eXisZVKrpLDdnkKSUFdaz0/rllUpVUyADGzK26qz/gSynJuVDR1Fo1/chz8YW6co1/2h8k7hbxaUhw6FJM+2p70ddCtTkvQBJMnotVaWa4Q+fdGMGPaRWGQcnL9iCDIWURGJWUv1MhUPFaPLvg6Gx6XHCesgMs/gYvfW6hEauyPN8KRRXSnS7s2baBRtXNJ3g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tUxTu-00043w-OW; Mon, 06 Jan 2025 19:30:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75414] [PATCH 2/2] deploy: Add roll-back action. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: arunisaac@systemreboot.net, guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, maxim.cournoyer@gmail.com, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 07 Jan 2025 00:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75414 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75414@debbugs.gnu.org Cc: Arun Isaac , Arun Isaac , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Arun Isaac , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 75414-submit@debbugs.gnu.org id=B75414.173620974415514 (code B ref 75414); Tue, 07 Jan 2025 00:30:02 +0000 Received: (at 75414) by debbugs.gnu.org; 7 Jan 2025 00:29:04 +0000 Received: from localhost ([127.0.0.1]:41048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tUxSy-000429-5p for submit@debbugs.gnu.org; Mon, 06 Jan 2025 19:29:04 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:50610) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tUxSu-00040q-PC for 75414@debbugs.gnu.org; Mon, 06 Jan 2025 19:29:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systemreboot.net; s=default; t=1736209734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LitUQhQBPxqsOjhPgEiWuvKtbleA5haieRyDQkfxRvs=; b=LJPrLMMEZOok0tLT8WXy+YOsey1Q6a4rVLtw2ElPiXhP+lm+gBRFItRkaToPztkPO2OpLJ MJ1wCGmZAstP8aTcG1U0z+nK2Z73OxpkDxqQyVh+HK5SBRT9cYHHV6OT9jP9LlWoG2me9O sUWYE4o3cfash9LUY5IgimrC6vBIkEDSkdKW9ETW+VHhHIMtkYNmvP7uNhTABFnKuA4249 kak2bVdJ+L1L+cqWWBIEvLchWQP2nOuJrYkBFor5cVG3CGOKlcMwoPPhFAote++ZX2RdC1 YeXcK6N0StOsrWCTd+TJD1EWgMDzvGe3owt4cfGyZKAsUlkTC3HPhUt2ZmXg5w== Received: from localhost.localdomain ( [192.168.2.1]) by mugam.systemreboot.net (OpenSMTPD) with ESMTPSA id 9a4feff6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Jan 2025 00:28:53 +0000 (UTC) From: Arun Isaac Date: Tue, 7 Jan 2025 00:28:31 +0000 Message-ID: <48a1e0e70b6e9aef50c847e5882fd996c0a5476d.1736208948.git.arunisaac@systemreboot.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: 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: , 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 * guix/scripts/deploy.scm (guix-deploy): Add the roll-back action. (show-what-to-deploy): Optionally support the roll-back action. (roll-back-machine*): New function. (show-help): Document the roll-back action. * doc/guix.texi (Invoking guix deploy): Document the roll-back action. Change-Id: Ic5084f287aefb2d1d28380ca4ba1c6971cb913e7 --- doc/guix.texi | 7 ++++ guix/scripts/deploy.scm | 90 +++++++++++++++++++++++++++++++++-------- 2 files changed, 80 insertions(+), 17 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index b2bcab8791..c08c2c70ef 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -44354,6 +44354,13 @@ Invoking guix deploy The @command{guix deploy -x} command returns zero if and only if the command succeeded on all the machines. +You may also wish to roll back configurations on machines to a previous +generation. You can do that using + +@example +guix deploy roll-back @var{file} +@end example + @c FIXME/TODO: Separate the API doc from the CLI doc. Below are the data types you need to know about when writing a diff --git a/guix/scripts/deploy.scm b/guix/scripts/deploy.scm index 941ee199f0..3f1b8b27a7 100644 --- a/guix/scripts/deploy.scm +++ b/guix/scripts/deploy.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2019 Jakob L. Kreuze ;;; Copyright © 2020-2022 Ludovic Courtès ;;; Copyright © 2024 Richard Sent +;;; Copyright © 2025 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -50,8 +51,13 @@ (define-module (guix scripts deploy) (define (show-help) - (display (G_ "Usage: guix deploy [OPTION] FILE... -Perform the deployment specified by FILE.\n")) + (display (G_ "Usage: guix deploy [OPTION] [ACTION] FILE... +Perform the deployment specified by FILE. +Optionally, perform ACTION.\n\n")) + (display (G_ "The valid values for ACTION are:\n")) + (newline) + (display (G_ "\ + roll-back switch to the previous operating system configuration\n")) (show-build-options-help) (newline) (display (G_ " @@ -118,20 +124,32 @@ (define (load-source-file file) environment-modules)))) (load* file module))) -(define* (show-what-to-deploy machines #:key (dry-run? #f)) - "Show the list of machines to deploy, MACHINES." +(define* (show-what-to-deploy machines #:key (dry-run? #f) (roll-back? #f)) + "Show the list of machines in MACHINES to deploy or roll back." (let ((count (length machines))) (if dry-run? - (format (current-error-port) - (N_ "The following ~d machine would be deployed:~%" - "The following ~d machines would be deployed:~%" + (if roll-back? + (format (current-error-port) + (N_ "The following ~d machine would be rolled back:~%" + "The following ~d machines would be rolled back:~%" count) count) - (format (current-error-port) - (N_ "The following ~d machine will be deployed:~%" - "The following ~d machines will be deployed:~%" + (format (current-error-port) + (N_ "The following ~d machine would be deployed:~%" + "The following ~d machines would be deployed:~%" + count) + count)) + (if roll-back? + (format (current-error-port) + (N_ "The following ~d machine will be rolled back:~%" + "The following ~d machines will be rolled back:~%" + count) count) - count)) + (format (current-error-port) + (N_ "The following ~d machine will be deployed:~%" + "The following ~d machines will be deployed:~%" + count) + count))) (display (indented-string (fill-paragraph (string-join (map machine-display-name machines) ", ") @@ -175,6 +193,35 @@ (define (deploy-machine* store machine) (info (G_ "successfully deployed ~a~%") (machine-display-name machine)))) +(define (roll-back-machine* store machine) + "Roll back MACHINE, taking care of error handling." + (info (G_ "rolling back ~a...~%") + (machine-display-name machine)) + + (guard* (c + ;; On Guile 3.0, exceptions such as 'unbound-variable' are compound + ;; and include a '&message'. However, that message only contains + ;; the format string. Thus, special-case it here to avoid + ;; displaying a bare format string. + (((exception-predicate &exception-with-kind-and-args) c) + (raise c)) + + ((message-condition? c) + (leave (G_ "failed to roll back ~a: ~a~%") + (machine-display-name machine) + (condition-message c))) + ((formatted-message? c) + (leave (G_ "failed to roll back ~a: ~a~%") + (machine-display-name machine) + (apply format #f + (gettext (formatted-message-string c) + %gettext-domain) + (formatted-message-arguments c))))) + (run-with-store store (roll-back-machine machine))) + + (info (G_ "successfully rolled back ~a~%") + (machine-display-name machine))) + (define (invoke-command store machine command) "Invoke COMMAND, a list of strings, on MACHINE. Display its output (if any) and its error code if it's non-zero. Return true if COMMAND succeeded, false @@ -291,9 +338,18 @@ (define-command (guix-deploy . args) machines))) (_ (leave (G_ "'-x' specified but no command given~%")))) - (begin - (show-what-to-deploy machines #:dry-run? dry-run?) - (unless dry-run? - (map/accumulate-builds store - (cut deploy-machine* store <>) - machines))))))))))) + (match args + (("roll-back" _ ...) + (show-what-to-deploy machines + #:dry-run? dry-run? + #:roll-back? #t) + (unless dry-run? + (map/accumulate-builds store + (cut roll-back-machine* store <>) + machines))) + (_ + (show-what-to-deploy machines #:dry-run? dry-run?) + (unless dry-run? + (map/accumulate-builds store + (cut deploy-machine* store <>) + machines))))))))))))