diff options
| author | Pjotr <wrk@bosa.lan> | 2026-10-04 10:30:28 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-04 10:30:28 +0000 |
| commit | 1a873fcbe49eafbcbe91c8a8248e95d595144670 (patch) | |
| tree | 2dcfe40d11592e4725fe7243e0373bb7628c17d2 | |
| parent | 14620fcfe44a9f60cbf8acceb506b87fb81b624d (diff) | |
| download | gn-machines-1a873fcbe49eafbcbe91c8a8248e95d595144670.tar.gz | |
gn-guile container: use the webserver shipped by gn-guile
gn-guile now ships web/webserver-aging.scm and bin/gn-guile-webserver (the stripped branding webserver for aging.genenetwork.org) in its own tree, so the container no longer embeds them: the strip phase only deletes the REST API files and the install phase copies/substitutes the shipped script. The brand-page footers also render the current copyright year (see gn-guile f2d53ea), and the pages now serialize through the shipped (web sxml) -- the htmlprag serializer rendered (doctype "html") as a literal <doctype> element, showing stray HTML in the top-left corner.
| -rw-r--r-- | genenetwork/containers/gn-guile-container.scm | 163 |
1 files changed, 12 insertions, 151 deletions
diff --git a/genenetwork/containers/gn-guile-container.scm b/genenetwork/containers/gn-guile-container.scm index 49612b0..7c0b563 100644 --- a/genenetwork/containers/gn-guile-container.scm +++ b/genenetwork/containers/gn-guile-container.scm @@ -54,141 +54,6 @@ through the run-guix-system-container daemon: #:use-module (gnu packages linux)) (use-package-modules base bash admin linux) -(define %webserver-aging-scm-text - ";;; webserver-aging --- the stripped branding webserver that serves -;;; aging.genenetwork.org. This replaces the full REST API webserver -;;; (web/webserver.scm): only the branding pages, css, static images -;;; and doc rendering remain. -(define-module (web webserver-aging) - #:use-module (web server) - #:use-module (web request) - #:use-module (web response) - #:use-module (web uri) - ;; sxml->html comes from guile-lib's (htmlprag); guile core's - ;; (sxml simple) only has sxml->xml - #:use-module (htmlprag) - #:use-module (rnrs io ports) - #:use-module (srfi srfi-1) - #:use-module (ice-9 match) - #:use-module (ice-9 format) - #:use-module (ice-9 receive) - #:use-module (web view view) - #:export (start-web-server)) - -(define file-mime-types - '((\"css\" text/css) - (\"js\" text/javascript) - (\"svg\" image/svg+xml) - (\"png\" image/png) - (\"gif\" image/gif) - (\"jpg\" image/jpg) - (\"jpeg\" image/jpeg) - (\"woff\" application/font-woff) - (\"ttf\" application/octet-stream) - (\"html\" text/html))) - -(define (file-extension file-name) - (last (string-split file-name #\\.))) - -(define (web-dir) - \"The installed web/ directory of this package (css, static, doc).\" - (dirname (dirname (search-path %load-path \"web/view/view.scm\")))) - -(define* (render-static-file path) - (let ((stat (stat path #f))) - (if stat - (list `((content-type . ,(assoc-ref file-mime-types - (file-extension path)))) - (call-with-input-file path get-bytevector-all)) - (not-found path)))) - -(define (render-brand-page path) - ;; htmlprag's sxml->html takes one argument and RETURNS the html - ;; string (guile core's two-argument sxml->xml writes to a port) - (list '((content-type text/html)) - (lambda (port) - (display (sxml->html (view-brand path)) port)))) - -(define (not-found path) - ;; routes return (list response body) -- the handler applies values - (list (build-response #:code 404) - (string-append \"Not found: \" path \"\\n\"))) - -(define (controller request body) - (match-lambda - ;; the aging.genenetwork.org front page - (('GET) (render-brand-page \"aging\")) - (('GET \"home\") (render-brand-page \"aging\")) - (('GET \"home\" \"aging\") (render-brand-page \"aging\")) - (('GET \"home\" \"aging\" path ...) (render-brand-page - (string-append \"aging/\" - (string-join path \"/\")))) - (('GET \"home\" path ...) (render-brand-page (string-join path \"/\"))) - (('GET \"css\" fn) - (render-static-file (string-append (web-dir) \"/css/\" fn))) - (('GET \"static\" \"images\" fn) - (render-static-file (string-append (web-dir) \"/static/images/\" fn))) - (('GET \"static\" fn ...) - (render-static-file (string-append (web-dir) \"/static/\" - (string-join fn \"/\")))) - (('GET \"doc\" path ...) (render-brand-page \"aging\")) - (_ (not-found (string-join (cons \"/\" (request-path-components request)) - \"/\"))))) - -(define (request-path-components request) - (split-and-decode-uri-path (uri-path (request-uri request)))) - -(define (handler request body) - (format #t \"~a ~a\\n\" (request-method request) - (uri-path (request-uri request))) - (apply values ((controller request body) - (cons (request-method request) - (request-path-components request))))) - -(define (start-web-server address port) - (format (current-error-port) - \"GN aging branding webserver listening on http://~a:~a/~%\" - address port) - (run-server handler 'http - (list #:addr (inet-pton AF_INET address) - #:port port))) -") - -(define %gn-guile-webserver-script-text - "#!@GUILE@ --no-auto-compile -!# - -;;; gn-guile-webserver --- stripped branding webserver for -;;; aging.genenetwork.org. Runs the (web webserver-aging) module -;;; shipped with this package; everything REST/API related was -;;; physically removed from the package source at build time. - -(use-modules (ice-9 match)) - -(define (parse-port args) - (let loop ((args args)) - (match args - ((\"--port\" p . rest) p) - (((? string->number p) . rest) p) - ((_ . rest) (loop rest)) - (() \"8091\")))) - -(define (main args) - ;; TLS: the views fetch their markdown from raw.githubusercontent.com; - ;; point guile/gnutls at the profile CA bundle (generated per-profile - ;; from nss-certs). - (setenv \"SSL_CERT_FILE\" - \"/run/current-system/profile/etc/ssl/certs/ca-certificates.crt\") - (setenv \"GUILE_TLS_CERTIFICATE_DIRECTORY\" - \"/run/current-system/profile/etc/ssl/certs\") - (let ((port (parse-port args))) - (let ((webserver (resolve-module '(web webserver-aging) #t))) - ((module-ref webserver 'start-web-server) - \"0.0.0.0\" (string->number port))))) - -(main (command-line)) -") - ;;; The stripped webserver package: inherits the gn-guile source ;;; (git.genenetwork.org/gn-guile, commit-pinned), deletes every API ;;; and build-only file, and ships a single guile script that serves @@ -229,15 +94,17 @@ through the run-guix-system-container daemon: ;; REST API modules (gn/*), the API web server and its ;; config, the precompute scripts, the test runner and ;; the development guix files. What remains is - ;; web/{sxml.scm,view/*,templates/*,css,static,doc} -- - ;; the views, their templates and the static assets. + ;; web/{sxml.scm,webserver-aging.scm,view/*,templates/*, + ;; css,static,doc} -- the views, their templates, the + ;; static assets and the stripped webserver module (all + ;; shipped by gn-guile since commit c04a67a). ;; Use lstat-aware deletion: guix.scm is a symlink to ;; .guix/modules/gn-guile.scm (which we delete), so it ;; becomes dangling and file-exists? would skip it. (for-each (lambda (f) (when (and (false-if-exception (lstat f)) - (not (member f '("." ".." "web")))) + (not (member f '("." ".." "web" "bin")))) (false-if-exception (delete-file-recursively f)))) (scandir ".")) ;; keep only the view/rendering side of web/ (delete @@ -246,11 +113,7 @@ through the run-guix-system-container daemon: (lambda (f) (when (file-exists? f) (delete-file f))) '("web/webserver.scm" "web/config.scm" - "web/gn-uri.scm")) - ;; the stripped webserver module - (call-with-output-file "web/webserver-aging.scm" - (lambda (port) (display #$%webserver-aging-scm-text port))) - (mkdir-p "bin"))) + "web/gn-uri.scm")))) ;; guile-build-system only installs .scm files; install the ;; branding webserver entry point plus the css/static/doc ;; assets it serves. @@ -279,7 +142,6 @@ through the run-guix-system-container daemon: ;; which defaults to the package name) (scm-libs (list #$(this-package-input "guile-json") #$(this-package-input "guile-commonmark") - #$(this-package-input "guile-lib") #$(this-package-input "guile-gnutls"))) (scm-path (map (lambda (x) (string-append x scm-dir)) @@ -291,14 +153,13 @@ through the run-guix-system-container daemon: (cons out scm-libs))) (site-web (string-append out scm-dir "/web"))) (mkdir-p bin) - ;; the entry-point script (sh/guile polyglot, same - ;; pattern as the old upstream bin/gn-guile) - (call-with-output-file - (string-append bin "/gn-guile-webserver") - (lambda (port) - (display #$%gn-guile-webserver-script-text port))) + ;; the entry-point script ships with gn-guile + ;; (bin/gn-guile-webserver); point its shebang at the + ;; store guile + (copy-file "bin/gn-guile-webserver" + (string-append bin "/gn-guile-webserver")) (substitute* (string-append bin "/gn-guile-webserver") - (("@GUILE@") (string-append guile-pkg "/bin/guile"))) + (("@GUILE@") guile)) (chmod (string-append bin "/gn-guile-webserver") #o755) ;; the static assets served by webserver-aging (copy-recursively "web/css" |
