[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: hydra: web: Add mcron job to build /packages.json and /sources.js
From: |
Ludovic Courtès |
Subject: |
02/02: hydra: web: Add mcron job to build /packages.json and /sources.json. |
Date: |
Wed, 4 Jan 2023 16:06:22 -0500 (EST) |
civodul pushed a commit to branch master
in repository maintenance.
commit 5664984bdd4a4ecbd7a2a5feb4033d610cea59fd
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Jan 4 22:02:18 2023 +0100
hydra: web: Add mcron job to build /packages.json and /sources.json.
Previously, these two files were built as part of the web site's build
process.
* hydra/modules/sysadmin/web.scm (%package-metadata-directory)
(guix-web-site-mcron-jobs, guix-web-site-activation): New variables.
(guix-web-site-service-type): Add extensions using them.
* hydra/modules/sysadmin/nginx.scm (guix.gnu.org-other-locations): Add
locations for /packages.json and /sources.json.
---
hydra/modules/sysadmin/nginx.scm | 12 +++++++++++-
hydra/modules/sysadmin/web.scm | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/hydra/modules/sysadmin/nginx.scm b/hydra/modules/sysadmin/nginx.scm
index e666c34..9d98a72 100644
--- a/hydra/modules/sysadmin/nginx.scm
+++ b/hydra/modules/sysadmin/nginx.scm
@@ -1,5 +1,5 @@
;; Nginx configuration for ci.guix.gnu.org
-;; Copyright © 2016-2022 Ludovic Courtès <ludo@gnu.org>
+;; Copyright © 2016-2023 Ludovic Courtès <ludo@gnu.org>
;; Copyright © 2017, 2018, 2019, 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
;; Copyright © 2020 Christopher Baines <mail@cbaines.net>
;; Copyright © 2020, 2021 Florian Pelz <pelzflorian@pelzflorian.de>
@@ -701,6 +701,16 @@ synonymous IETF language tags that should be mapped to the
same $lang."
(uri "~ (.html|.htm)$")
(body (list "try_files $uri /$lang/$uri /$lang/$uri/index.html =404;")))
+ (nginx-location-configuration
+ (uri "= /packages.json")
+ (body (list "if_modified_since on;"
+ "root /srv/package-metadata")))
+
+ (nginx-location-configuration
+ (uri "= /sources.json")
+ (body (list "if_modified_since on;"
+ "root /srv/package-metadata")))
+
(nginx-location-configuration ;certbot
(uri "/.well-known")
(body (list "root /var/www;")))))
diff --git a/hydra/modules/sysadmin/web.scm b/hydra/modules/sysadmin/web.scm
index fcf94e4..1bf3500 100644
--- a/hydra/modules/sysadmin/web.scm
+++ b/hydra/modules/sysadmin/web.scm
@@ -1,6 +1,6 @@
;;; GNU Guix system administration tools.
;;;
-;;; Copyright © 2019-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2019-2023 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This program is free software: you can redistribute it and/or modify
@@ -290,12 +290,43 @@ taken from a Git repository.")
(environment-variables '(("GUIX_MANUAL" . "guix-cookbook")
("GUIX_WEB_SITE_URL" . "/"))))))
+(define %package-metadata-directory
+ ;; Directory where to store 'packages.json' and 'sources.json'.
+ "/srv/package-metadata")
+
+(define guix-web-site-mcron-jobs
+ ;; Job that periodically builds 'packages.json' and 'sources.json'.
+ (let ((program (program-file "build-package-metadata"
+ #~(execl #$(file-append guix "/bin/guix")
+ "guix"
+ "time-machine" "--" "repl" "--"
+ #$(local-file
+ "../../build-package-metadata.scm")
+ #$%package-metadata-directory))))
+ (list #~(job "30 */6 * * *" #$program
+ #:user "static-web-site"))))
+
+(define guix-web-site-activation
+ (with-imported-modules '((guix build utils))
+ #~(begin
+ (use-modules (guix build utils))
+
+ (let ((pw (getpwnam "static-web-site")))
+ (mkdir-p #$%package-metadata-directory)
+ (chown #$%package-metadata-directory
+ (passwd:uid pw) (passwd:gid pw))
+ (chmod #$%package-metadata-directory #o755)))))
+
(define guix-web-site-service-type
(service-type
(name 'guix-web-site)
(extensions
(list (service-extension static-web-site-service-type
(const guix-static-web-sites))
+ (service-extension activation-service-type
+ (const guix-web-site-activation))
+ (service-extension mcron-service-type
+ (const guix-web-site-mcron-jobs))
(service-extension nginx-service-type
(const (list guix.gnu.org-nginx-server)))))
(description