diff --git a/gnu/packages/patchutils.scm b/gnu/packages/patchutils.scm index 540b85b41aa..2d17d9d57be 100644 --- a/gnu/packages/patchutils.scm +++ b/gnu/packages/patchutils.scm @@ -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 diff --git a/gnu/services/web.scm b/gnu/services/web.scm index ae33a25394d..9d314368ff9 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -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 diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 419b5f0b5bf..47879aa08f7 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm @@ -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