guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/07: hydra: web: Add 'static-web-site-service-type'.


From: Ludovic Courtès
Subject: 05/07: hydra: web: Add 'static-web-site-service-type'.
Date: Thu, 11 Jul 2019 08:56:17 -0400 (EDT)

civodul pushed a commit to branch master
in repository maintenance.

commit 1b87fa45f6ed770dc746e3eaab8d56397d64c776
Author: Ludovic Courtès <address@hidden>
Date:   Thu Jul 11 14:38:29 2019 +0200

    hydra: web: Add 'static-web-site-service-type'.
    
    * hydra/modules/sysadmin/web.scm (build-program): Add #:file, #:ref, and
     #:name parameters, and honor them.
    (<static-web-site-configuration>): New record type.
    (static-web-site-mcron-jobs, static-web-site-activation)
    (static-web-site-accounts): New procedures.
    (static-web-site-service-type): New variable.
---
 hydra/modules/sysadmin/web.scm | 95 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 88 insertions(+), 7 deletions(-)

diff --git a/hydra/modules/sysadmin/web.scm b/hydra/modules/sysadmin/web.scm
index 9ca53a4..824002b 100644
--- a/hydra/modules/sysadmin/web.scm
+++ b/hydra/modules/sysadmin/web.scm
@@ -17,10 +17,21 @@
 
 (define-module (sysadmin web)
   #:use-module (guix git)
+  #:use-module (guix gexp)
   #:use-module (guix packages)
+  #:use-module (guix records)
   #:use-module (gnu packages)
+  #:use-module (gnu services)
+  #:use-module (gnu services mcron)
+  #:use-module (gnu services web)
+  #:use-module (gnu system shadow)
   #:use-module (ice-9 match)
-  #:export (build-program))
+  #:export (build-program
+
+            static-web-site-configuration
+            static-web-site-configuration?
+
+            static-web-site-service-type))
 
 (define guix-extensions
   (match (package-transitive-propagated-inputs
@@ -28,9 +39,14 @@
     (((labels packages) ...)
      (cons (specification->package "guix") packages))))
 
-(define (build-program url root)
-  "Return a program that pulls code from URL, builds it using its 'guix.scm'
-file, and registers the result as ROOT (an indirect GC root) upon success.
+(define* (build-program url root
+                        #:key
+                        (file "guix.scm")
+                        (ref '(branch . "master"))
+                        (name "build-program"))
+  "Return a program that pulls code from URL, builds it by loading FILE from
+that checkout (usually a 'guix.scm' file), and registers the result as
+ROOT (an indirect GC root) upon success.
 
 The typical use case is polling from the source repository of a web site
 that's built with Haunt or similar."
@@ -49,10 +65,10 @@ that's built with Haunt or similar."
                 (return #t))))
 
           (define-values (checkout commit)
-            (update-cached-checkout #$url))
+            (update-cached-checkout #$url #:ref '#$ref))
 
           (define obj
-            (primitive-load (string-append checkout "/guix.scm")))
+            (primitive-load (string-append checkout "/" #$file)))
 
           (with-store store
             (run-with-store store
@@ -62,4 +78,69 @@ that's built with Haunt or similar."
                   (built-derivations (list drv))
                   (root-installed drv #$root))))))))
 
-  (program-file "build-program" build))
+  (program-file name build))
+
+
+;;;
+;;; Service.
+;;;
+
+(define-record-type* <static-web-site-configuration>
+  static-web-site-configuration make-static-web-site-configuration
+  static-web-site-configuration?
+  (git-url     static-web-site-configuration-git-url)
+  (git-ref     static-web-site-configuration-git-ref
+               (default '(branch . "master")))
+  (build-file  static-web-site-configuration-build-file
+               (default "guix.scm"))
+  (directory   static-web-site-configuration-directory
+               (default "/srv/www")))
+
+(define (static-web-site-mcron-jobs config)
+  (define update
+    (build-program (static-web-site-configuration-git-url config)
+                   (static-web-site-configuration-directory config)
+                   #:file (static-web-site-configuration-build-file config)
+                   #:ref (static-web-site-configuration-git-ref config)
+                   #:name (string-append
+                           "update-"
+                           (basename
+                            (static-web-site-configuration-directory 
config)))))
+
+  (list #~(job '(next-minute '(0)) #$update
+               #:user "static-web-site")))
+
+(define (static-web-site-activation config)
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (let ((directory (dirname
+                          #$(static-web-site-configuration-directory config))))
+          (mkdir-p directory)
+          (chown directory
+                 (passwd:uid (getpw "static-web-site"))
+                 (group:gid (getgr "static-web-site")))))))
+
+(define (static-web-site-accounts config)
+  (list (user-account
+         (name "static-web-site")
+         (group "static-web-site")
+         (system? #t))
+        (user-group
+         (name "static-web-site")
+         (system? #t))))
+
+(define static-web-site-service-type
+  (service-type (name 'static-web-site)
+                (extensions
+                 ;; TODO: Extend nginx directly from here?
+                 (list (service-extension mcron-service-type
+                                          static-web-site-mcron-jobs)
+                       (service-extension account-service-type
+                                          static-web-site-accounts)
+                       (service-extension activation-service-type
+                                          static-web-site-activation)))
+                (description
+                 "Update and publish a web site that is built from source
+taken from a Git repository.")))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]