branch: main
commit b07538f0f2194f8dabaa85cd2181802ba3a17144
Author: Ludovic Courtès <[email protected]>
AuthorDate: Fri Mar 21 22:58:23 2025 +0100
examples: Add Shepherd configuration file.
* examples/shepherd.scm: New file.
* Makefile.am (EXTRA_DIST): Add it.
* README (Database connection): Document it.
* build-aux/guix/cuirass-package.scm (cuirass)[native-inputs]:
Add ‘shepherd-1.0’.
---
Makefile.am | 1 +
README | 10 +++
build-aux/guix/cuirass-package.scm | 9 ++-
examples/shepherd.scm | 127 +++++++++++++++++++++++++++++++++++++
4 files changed, 146 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 645ac2f..6f20fcd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -240,6 +240,7 @@ EXTRA_DIST = \
examples/cuirass.scm \
examples/random.scm \
examples/random-manifest.scm \
+ examples/shepherd.scm \
$(TESTS) \
tests/common.scm \
tests/mail.sh
diff --git a/README b/README
index 8ef83cf..7822f45 100644
--- a/README
+++ b/README
@@ -99,6 +99,16 @@ Or, if you want to test the ZeroMQ-based remote build
mechanism, you can run:
--public-key=tests/signing-key.pub --private-key=tests/signing-key.sec &
#+end_example
+Even easier! With the Shepherd, you can run:
+
+#+begin_example
+ shepherd -c examples/shepherd.scm
+ herd start cuirass-full
+#+end_example
+
+From there, run =herd status= and related commands to inspect and control the
+services.
+
* Run tests
Cuirass tests also require an access to a PostgreSQL database, provided by the
diff --git a/build-aux/guix/cuirass-package.scm
b/build-aux/guix/cuirass-package.scm
index b2e8bf8..55ee2c2 100644
--- a/build-aux/guix/cuirass-package.scm
+++ b/build-aux/guix/cuirass-package.scm
@@ -24,6 +24,7 @@
#:use-module (guix git-download)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix search-paths)
+ #:use-module (gnu packages admin)
#:use-module (gnu packages autotools)
#:use-module (gnu packages databases)
#:use-module (gnu packages gnupg)
@@ -132,7 +133,13 @@
guix))
(native-inputs
- (list autoconf-2.71 automake pkg-config texinfo ephemeralpg esbuild))
+ (list autoconf-2.71
+ automake
+ pkg-config
+ texinfo
+ ephemeralpg
+ esbuild
+ shepherd-1.0)) ;to run examples
(native-search-paths
;; For HTTPS access, Cuirass itself honors these variables, with the
;; same semantics as Git and OpenSSL (respectively).
diff --git a/examples/shepherd.scm b/examples/shepherd.scm
new file mode 100644
index 0000000..070b8d4
--- /dev/null
+++ b/examples/shepherd.scm
@@ -0,0 +1,127 @@
+;;; shepherd.scm -- Shepherd configuration to run Cuirass.
+;;; Copyright © 2025 Ludovic Courtès <[email protected]>
+;;;
+;;; This file is part of Cuirass.
+;;;
+;;; Cuirass is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; Cuirass is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
+
+(use-modules (ice-9 popen)
+ (ice-9 textual-ports))
+
+(define %state-directory
+ ;; State directory as set up in './pre-inst-env'.
+ "/tmp/cuirass-tests/var/run")
+
+(define %socket-directory
+ (in-vicinity %state-directory "cuirass"))
+
+(define (cuirass-endpoint name)
+ (endpoint (make-socket-address AF_UNIX
+ (in-vicinity %socket-directory name))
+ #:name name
+ #:socket-directory-permissions #o700))
+
+(define %top-directory
+ (let ((this (assoc-ref (current-source-location) 'filename)))
+ (in-vicinity (dirname this) "..")))
+
+(define %postgresql-directory
+ (mkdtemp "/tmp/cuirass-pgsql-XXXXXX"))
+
+(default-environment-variables
+ (append '("CUIRASS_LOGGING_LEVEL=debug"
+ "COLUMNS=200")
+ (default-environment-variables)))
+
+(register-services
+ (list (service '(postgresql)
+ #:start (lambda ()
+ (let* ((port (open-pipe*
+ OPEN_READ
+ "pg_tmp" "-w" "0"
+ "-d" %postgresql-directory))
+ (str (get-string-all port)))
+ (unless (zero? (close-pipe port))
+ (error "failed to start ephemeral database
server"))
+ (format #t "postgresql directory: ~a~%"
+ %postgresql-directory)
+ str))
+ #:stop (lambda (_)
+ (system* "pg_tmp" "stop" "-d" %postgresql-directory)
+ #f))
+ (service '(cuirass)
+ #:requirement '(postgresql)
+ #:start (lambda* (#:optional (spec "examples/random.scm"))
+ (define database
+ (service-running-value
+ (lookup-service 'postgresql)))
+
+ ((make-systemd-constructor
+ `("./pre-inst-env" "cuirass" "register"
+ "-S" ,spec
+ ,(string-append "--database=" database)
+ "--build-remote")
+ (list (cuirass-endpoint "bridge")
+ (cuirass-endpoint "remote-builds"))
+ #:log-file "/tmp/cuirass.log"
+ #:directory %top-directory)))
+ #:stop (make-systemd-destructor)
+ #:respawn? #t)
+ (service '(cuirass-web)
+ #:requirement '(cuirass postgresql)
+ #:start (lambda ()
+ (define database
+ (service-running-value
+ (lookup-service 'postgresql)))
+
+ ((make-forkexec-constructor
+ `("./pre-inst-env" "cuirass" "web"
+ ,(string-append "--database=" database))
+ #:directory %top-directory)))
+ #:stop (make-kill-destructor)
+ #:respawn? #t)
+ (service '(cuirass-remote-server)
+ #:requirement '(cuirass postgresql)
+ #:start (lambda ()
+ (define database
+ (service-running-value
+ (lookup-service 'postgresql)))
+
+ ((make-forkexec-constructor
+ `("./pre-inst-env" "cuirass" "remote-server"
+ ,(string-append "--database=" database)
+ "--public-key=tests/signing-key.pub"
+ "--private-key=tests/signing-key.sec")
+ #:directory %top-directory)))
+ #:stop (make-kill-destructor)
+ #:respawn? #t)
+ (service '(cuirass-remote-worker)
+ #:requirement '(cuirass-remote-server postgresql)
+ #:start (make-forkexec-constructor
+ '("./pre-inst-env" "cuirass" "remote-worker"
+ "-w" "2"
+ "--public-key=tests/signing-key.pub"
+ "--private-key=tests/signing-key.sec")
+ #:directory %top-directory)
+ #:stop (make-kill-destructor)
+ #:respawn? #t)
+ (service '(cuirass-full)
+ #:requirement '(cuirass-remote-server
+ cuirass-remote-worker
+ cuirass-web
+ cuirass)
+ #:start (const #t)
+ #:stop (const #f))))
+
+(perform-service-action root-service 'daemonize)