aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnu/services/web.scm97
-rw-r--r--gnu/tests/web.scm42
2 files changed, 95 insertions, 44 deletions
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 816cbaa3f0..8f61f52485 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -39,6 +39,7 @@
#:use-module (gnu packages python)
#:use-module (gnu packages guile)
#:use-module (gnu packages logging)
+ #:use-module (guix packages)
#:use-module (guix records)
#:use-module (guix modules)
#:use-module (guix utils)
@@ -249,6 +250,9 @@
patchwork-configuration-settings-module
patchwork-configuration-domain
+ patchwork-wsgi-wrapper
+ patchwork-virtualhost
+ patchwork-initial-database-setup-service
patchwork-service-type))
;;; Commentary:
@@ -1321,7 +1325,7 @@ files.")
(name patchwork-database-configuration-name
(default "patchwork"))
(user patchwork-database-configuration-user
- (default ""))
+ (default "httpd"))
(password patchwork-database-configuration-password
(default ""))
(host patchwork-database-configuration-host
@@ -1452,19 +1456,16 @@ STATICFILES_STORAGE = (
"\n"
"exec(open(\"" patchwork-wsgi.py "\").read())\n"))
-(define patchwork-httpd-configuration
+(define patchwork-virtualhost
(match-lambda
(($ <patchwork-configuration> patchwork settings-module
domain)
(define wsgi.py (patchwork-wsgi-wrapper patchwork))
- (list "WSGISocketPrefix /var/run/mod_wsgi"
- (list "LoadModule wsgi_module "
- (file-append mod-wsgi "/modules/mod_wsgi.so"))
- (httpd-virtualhost
- "*:8080"
- `("ServerAdmin admin@example.com
+ (httpd-virtualhost
+ "*:8080"
+ `("ServerAdmin admin@example.com
ServerName " ,domain "
LogFormat \"%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" customformat
@@ -1474,8 +1475,8 @@ CustomLog \"/var/log/httpd/" ,domain "-access_log\" customformat
ErrorLog /var/log/httpd/error.log
WSGIScriptAlias / " ,wsgi.py "
-WSGIDaemonProcess patchwork user=httpd group=httpd processes=1 threads=2 display-name=%{GROUP} lang='en_US.UTF-8' locale='en_US.UTF-8' python-path=" ,settings-module "
-WSGIProcessGroup patchwork
+WSGIDaemonProcess " ,(package-name patchwork) " user=httpd group=httpd processes=1 threads=2 display-name=%{GROUP} lang='en_US.UTF-8' locale='en_US.UTF-8' python-path=" ,settings-module "
+WSGIProcessGroup " ,(package-name patchwork) "
WSGIPassAuthorization On
<Files " ,wsgi.py ">
@@ -1487,36 +1488,59 @@ Alias /static " ,patchwork "/share/patchwork/htdocs
AllowOverride None
Options MultiViews Indexes SymlinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
-</Directory>"))))))
+</Directory>")))))
+
+(define (patchwork-httpd-configuration patchwork-configuration)
+ (list "WSGISocketPrefix /var/run/mod_wsgi"
+ (list "LoadModule wsgi_module "
+ (file-append mod-wsgi "/modules/mod_wsgi.so"))
+ (patchwork-virtualhost patchwork-configuration)))
-(define (patchwork-setup-gexp settings-module)
+(define patchwork-initial-database-setup-service
+ (match-lambda
+ (($ <patchwork-database-configuration>
+ engine name user password host port)
+
+ (define start-gexp
+ #~(lambda ()
+ (display "\nSETTING UP PATCHWORK DATABASE USER\n\n\n")
+ (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")
+ #$user))
+ (zero?
+ (system* #$(file-append postgresql "/bin/createdb")
+ "-O" #$user #$name)))
+ 0
+ 1)))
+ (lambda ()
+ (primitive-exit 1)))
+ (zero? (cdr (waitpid pid)))))))
+
+ (shepherd-service
+ (requirement '(postgres))
+ (provision '(patchwork-postgresql-user-and-database))
+ (start start-gexp)
+ (stop #~(const #f))
+ (respawn? #f)
+ (documentation "Setup patchwork database.")))))
+
+(define (patchwork-setup-gexp patchwork settings-module)
(with-imported-modules (source-module-closure
'((guix build utils)))
#~(lambda ()
(catch #t
(lambda ()
(let ((pid (primitive-fork))
- (user (getpwnam "postgres")))
- (if (eq? pid 0)
- (dynamic-wind
- (const #t)
- (lambda ()
- (setgid (passwd:gid user))
- (setuid (passwd:uid user))
- (primitive-exit
- (if (and
- (zero?
- (system* #$(file-append postgresql "/bin/createuser")
- "httpd"))
- (zero?
- (system* #$(file-append postgresql "/bin/createdb")
- "-O" "httpd" "patchwork")))
- 0
- 1)))
- (lambda ()
- (primitive-exit 1)))
- (zero? (cdr (waitpid pid)))))
- (let ((pid (primitive-fork))
(user (getpwnam "httpd")))
(if (eq? pid 0)
(dynamic-wind
@@ -1526,7 +1550,6 @@ Alias /static " ,patchwork "/share/patchwork/htdocs
(setuid (passwd:uid user))
;; TODO Extract
(setenv "DJANGO_SECRET_KEY" "testsecretkey")
- (setenv "DATABASE_NAME" "patchwork")
(setenv "PYTHONPATH" #$settings-module)
(primitive-exit
(if (and
@@ -1557,8 +1580,10 @@ Alias /static " ,patchwork "/share/patchwork/htdocs
domain)
(list (shepherd-service
(requirement '(postgres))
- (provision '(patchwork-setup))
- (start (patchwork-setup-gexp settings-module))
+ (provision (list (string->symbol
+ (string-append (package-name patchwork)
+ "-setup"))))
+ (start (patchwork-setup-gexp patchwork settings-module))
(stop #~(const #f))
(respawn? #f)
(documentation "Setup patchwork."))))))))
diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm
index fbdf78a036..d61232dde9 100644
--- a/gnu/tests/web.scm
+++ b/gnu/tests/web.scm
@@ -48,7 +48,8 @@
%test-php-fpm
%test-hpcguix-web
%test-tailon
- %test-patchwork))
+ %test-patchwork
+ %test-patchwork-fdo))
(define %index.html-contents
;; Contents of the /index.html file.
@@ -516,7 +517,7 @@ HTTP-PORT."
;;; Patchwork
;;;
-(define %patchwork-os
+(define (patchwork-os patchwork)
(simple-operating-system
(service dhcp-client-service-type)
(service httpd-service-type
@@ -527,20 +528,26 @@ HTTP-PORT."
(service postgresql-service-type)
(service patchwork-service-type
(patchwork-configuration
+ (patchwork patchwork)
(settings-module
(patchwork-settings-module
(secret-key "00000")
(allowed-hosts '("*"))
(default-from-email "")
(debug? #t)))
- (domain "localhost")))))
-
-(define* (run-patchwork-test)
+ (domain "localhost")))
+ (simple-service 'patchwork-database-setup
+ shepherd-root-service-type
+ (list
+ (patchwork-initial-database-setup-service
+ (patchwork-database-configuration))))))
+
+(define (run-patchwork-test patchwork)
"Run tests in %NGINX-OS, which has nginx running and listening on
HTTP-PORT."
(define os
(marionette-operating-system
- %patchwork-os
+ (patchwork-os patchwork)
#:imported-modules '((gnu services herd)
(guix combinators))))
@@ -568,11 +575,24 @@ HTTP-PORT."
(test-begin "patchwork")
+ (test-equal "patchwork-postgresql-user-and-database"
+ #t
+ (marionette-eval
+ '(begin
+ (use-modules (gnu services herd))
+ (match (start-service 'patchwork-postgresql-user-and-database)
+ (#f #f)
+ (('service response-parts ...)
+ (match (assq-ref response-parts 'running)
+ ((#t) #t)
+ (_ #f)))))
+ marionette))
+
(test-assert "httpd service running"
(marionette-eval
'(begin
(use-modules (gnu services herd))
- (match (start-service 'httpd)
+ (match (start-service 'patchwork-postgresql-user-and-database)
(#f #f)
(('service response-parts ...)
(match (assq-ref response-parts 'running)
@@ -599,4 +619,10 @@ HTTP-PORT."
(system-test
(name "patchwork")
(description "")
- (value (run-patchwork-test))))
+ (value (run-patchwork-test patchwork))))
+
+(define %test-patchwork-fdo
+ (system-test
+ (name "patchwork-fdo")
+ (description "")
+ (value (run-patchwork-test patchwork-fdo))))