gnu: Fix patchwork service test.

* gnu/packages/patchutils.scm (patchwork):[arguments]: Write version.txt,
tweak some indentation, patch the STATICFILES_DIRS entry.
[propagated-inputs]: Add python-tzdata.
* gnu/services/web.scm (patchwork-settings-module-compiler): Don't set
STATIC_ROOT on debug, as this clashes with STATICFILES_DIRS.
(patchwork-django-admin-gexp): Fix.
(patchwork-shepherd-services): Workaround issue referencing random-token.
* gnu/tests/web.scm (patchwork-initial-database-setup-service): Don't use
primitive-fork, as this doesn't work with newer shepherds.
(run-patchwork-test): Check the setup runs.

Change-Id: I7dfeb816b4f6c9070358d433fb7ca8faa1fbfd2a
This commit is contained in:
Christopher Baines 2025-11-10 10:19:48 +00:00
parent 9bf06d93a4
commit f7125fb55d
No known key found for this signature in database
GPG key ID: 5E28A33B0B84F577
3 changed files with 64 additions and 47 deletions

View file

@ -55,6 +55,7 @@
#:use-module (gnu packages less)
#:use-module (gnu packages mail)
#:use-module (gnu packages text-editors)
#:use-module (gnu packages time)
#:use-module (gnu packages ncurses)
#:use-module (gnu packages ocaml)
#:use-module (gnu packages package-management)
@ -432,13 +433,20 @@ application = get_wsgi_application()\n") port)))))
(delete-file-recursively (string-append out-site-packages
"/patchwork/tests"))
(call-with-output-file
(string-append out-site-packages "/version.txt")
(lambda (port)
(display #$version port)
(newline port)))
;; Install patchwork related tools
(for-each (lambda (file)
(install-file file
(string-append out "/bin")))
(list (string-append out-site-packages
"/patchwork/bin/parsemail.sh")
(string-append out-site-packages
(for-each
(lambda (file)
(install-file file (string-append out "/bin")))
(list
(string-append out-site-packages
"/patchwork/bin/parsemail.sh")
(string-append out-site-packages
"/patchwork/bin/parsemail-batch.sh")))
;; Collect the static assets, this includes JavaScript, CSS and
@ -449,8 +457,15 @@ application = get_wsgi_application()\n") port)))))
;; The intent here is that you can serve files from this
;; directory through a webserver, which is recommended when
;; running Django applications.
(let ((static-root (string-append out
"/share/patchwork/htdocs")))
(let ((static-root
(string-append out "/share/patchwork/htdocs")))
;; Patch the STATICFILES_DIRS entry
(substitute* (string-append
out-site-packages
"/patchwork/settings/base.py")
(("os\\.path\\.join\\(ROOT\\_DIR, 'htdocs'\\)")
(string-append "'" static-root "'")))
(mkdir-p static-root)
(copy-file "patchwork/settings/production.example.py"
"patchwork/settings/assets.py")
@ -496,6 +511,7 @@ if __name__ == \"__main__\":
(inputs (list python-wrapper))
(propagated-inputs
(list python-django
python-tzdata
;; TODO: Make this configurable
python-psycopg2
python-mysqlclient

View file

@ -1771,11 +1771,9 @@ DATABASES = {
},
}
" #$(if debug?
#~(string-append "STATIC_ROOT = '"
#$(file-append patchwork "/share/patchwork/htdocs")
"'")
#~(string-append "STATIC_URL = '" #$static-url "'")) "
" #$(if static-url
#~(string-append "STATIC_URL = '" #$static-url "'")
"") "
STATICFILES_STORAGE = (
'django.contrib.staticfiles.storage.StaticFilesStorage'
@ -1840,7 +1838,7 @@ WSGIPassAuthorization On
#~(lambda command
(zero? (spawn-command
`(#$(file-append patchwork "/bin/patchwork-admin")
,command)
,@command)
#:user "httpd"
#:group "httpd"
#:environment-variables
@ -1864,10 +1862,9 @@ WSGIPassAuthorization On
(with-extensions (list guile-gcrypt)
#~(let ((secret-key-file
#$(patchwork-settings-module-secret-key-file
settings-module)))
(use-modules (guix build utils)
(gcrypt random))
settings-module))
(random-token
(@ (gcrypt random) random-token)))
(unless (file-exists? secret-key-file)
(mkdir-p (dirname secret-key-file))
(call-with-output-file secret-key-file

View file

@ -609,40 +609,32 @@ HTTP-PORT, along with php-fpm."
(define (patchwork-initial-database-setup-service configuration)
(define start-gexp
#~(lambda ()
(let ((pid (primitive-fork))
(postgres (getpwnam "postgres")))
(if (eq? pid 0)
(dynamic-wind
(const #t)
(lambda ()
(setgid (passwd:gid postgres))
(setuid (passwd:uid postgres))
(primitive-exit
(if (and
(zero?
(system* #$(file-append postgresql "/bin/createuser")
#$(patchwork-database-configuration-user
configuration)))
(zero?
(system* #$(file-append postgresql "/bin/createdb")
"-O"
#$(patchwork-database-configuration-user
configuration)
#$(patchwork-database-configuration-name
configuration))))
0
1)))
(lambda ()
(primitive-exit 1)))
(zero? (cdr (waitpid pid)))))))
#~(primitive-exit
(if (and
(zero?
(system* #$(file-append postgresql "/bin/createuser")
#$(patchwork-database-configuration-user
configuration)))
(zero?
(system* #$(file-append postgresql "/bin/createdb")
"-O"
#$(patchwork-database-configuration-user
configuration)
#$(patchwork-database-configuration-name
configuration))))
0
1)))
(shepherd-service
(requirement '(postgres))
(provision '(patchwork-postgresql-user-and-database))
(start start-gexp)
(start #~(lambda _
(zero? (spawn-command
'(#$(program-file "patchwork-initial-database-setup"
start-gexp))
#:user "postgres"
#:group "postgres"))))
(stop #~(const #f))
(respawn? #f)
(documentation "Setup patchwork database.")))
(define (patchwork-os patchwork)
@ -724,6 +716,18 @@ HTTP-PORT."
((pid) pid)))))
marionette))
(test-assert "patchwork-setup started"
(marionette-eval
'(begin
(use-modules (gnu services herd))
(match (start-service 'patchwork-setup)
(#f #f)
(('service response-parts ...)
(match (assq-ref response-parts 'running)
((#t) #t)
((pid) pid)))))
marionette))
(test-assert "httpd running"
(marionette-eval
'(begin