From patchwork Fri Jan 25 21:00:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 821 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 68F2A169CD; Fri, 25 Jan 2019 21:01:18 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 294AA169BD for ; Fri, 25 Jan 2019 21:01:17 +0000 (GMT) Received: from localhost ([127.0.0.1]:50621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn8bD-0000sR-Vt for patchwork@mira.cbaines.net; Fri, 25 Jan 2019 16:01:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn8bB-0000qs-1j for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gn8b5-0002OU-Pc for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:10 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:46323) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gn8b1-0002Mi-Lm for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gn8az-0008K2-Nc for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#33185] [PATCH v3 1/2] gnu: Add patchwork. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 25 Jan 2019 21:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33185 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 33185@debbugs.gnu.org Received: via spool by 33185-submit@debbugs.gnu.org id=B33185.154845001931922 (code B ref 33185); Fri, 25 Jan 2019 21:01:01 +0000 Received: (at 33185) by debbugs.gnu.org; 25 Jan 2019 21:00:19 +0000 Received: from localhost ([127.0.0.1]:45602 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gn8a8-0008Hg-CT for submit@debbugs.gnu.org; Fri, 25 Jan 2019 16:00:19 -0500 Received: from li622-129.members.linode.com ([212.71.249.129]:56782 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gn8a6-0008HP-21 for 33185@debbugs.gnu.org; Fri, 25 Jan 2019 16:00:07 -0500 Received: from localhost (cpc102582-walt20-2-0-cust14.13-2.cable.virginm.net [86.27.34.15]) by mira.cbaines.net (Postfix) with ESMTPSA id 0BD7F169BD for <33185@debbugs.gnu.org>; Fri, 25 Jan 2019 21:00:05 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 49688dec for <33185@debbugs.gnu.org>; Fri, 25 Jan 2019 21:00:04 +0000 (UTC) From: Christopher Baines Date: Fri, 25 Jan 2019 21:00:03 +0000 Message-Id: <20190125210004.28221-1-mail@cbaines.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <87y3aie8a1.fsf@cbaines.net> References: <87y3aie8a1.fsf@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/patchutils.scm (patchwork): New variable. --- gnu/packages/patchutils.scm | 165 ++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/gnu/packages/patchutils.scm b/gnu/packages/patchutils.scm index 09f5afbb28..260bba3d41 100644 --- a/gnu/packages/patchutils.scm +++ b/gnu/packages/patchutils.scm @@ -31,6 +31,8 @@ #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages check) + #:use-module (gnu packages databases) + #:use-module (gnu packages django) #:use-module (gnu packages file) #:use-module (gnu packages gawk) #:use-module (gnu packages gettext) @@ -305,3 +307,166 @@ directories, and has support for many popular version control systems. Meld helps you review code changes and understand patches. It might even help you to figure out what is going on in that merge you keep avoiding.") (license gpl2))) + +(define-public patchwork + (package + (name "patchwork") + (version "2.1.1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/getpatchwork/patchwork.git") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "1wpcgkji9cb50lyv12ifgk08sjn7dkqkzis9qjwhx6y855dfdfn1")))) + (build-system python-build-system) + (arguments + `(;; TODO: Tests require a running database + #:tests? #f + #:phases + (modify-phases %standard-phases + (delete 'configure) + (delete 'build) + (add-after 'unpack 'replace-wsgi.py + (lambda* (#:key inputs outputs #:allow-other-keys) + (delete-file "patchwork/wsgi.py") + (call-with-output-file "patchwork/wsgi.py" + (lambda (port) + ;; Embed the PYTHONPATH containing the dependencies, as well + ;; as the python modules in this package in the wsgi.py file, + ;; as this will ensure they are available at runtime. + (define pythonpath + (string-append (getenv "PYTHONPATH") + ":" + (site-packages inputs outputs))) + (display + (string-append " +import os, sys + +sys.path.extend('" pythonpath "'.split(':')) + +from django.core.wsgi import get_wsgi_application + +# By default, assume that patchwork is running as a Guix service, which +# provides the settings as the 'guix.patchwork.settings' Python module. +# +# When using httpd, it's hard to set environment variables, so rely on the +# default set here. +os.environ['DJANGO_SETTINGS_MODULE'] = os.getenv( + 'DJANGO_SETTINGS_MODULE', + 'guix.patchwork.settings' # default +) + +application = get_wsgi_application()\n") port))))) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.dev") + (invoke "python" "-Wonce" "./manage.py" "test" "--noinput")) + #t)) + (replace 'install + (lambda* (#:key inputs outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out")) + (out-site-packages (site-packages inputs outputs))) + (for-each (lambda (directory) + (copy-recursively + directory + (string-append out-site-packages directory))) + '(;; Contains the python code + "patchwork" + ;; Contains the templates for the generated HTML + "templates")) + (delete-file-recursively + (string-append out-site-packages "patchwork/tests")) + + ;; Install patchwork related tools + (for-each (lambda (file) + (install-file file (string-append out "/bin"))) + (list + (string-append out-site-packages + "patchwork/bin/pwclient") + (string-append out-site-packages + "patchwork/bin/parsemail.sh") + (string-append out-site-packages + "patchwork/bin/parsemail-batch.sh"))) + + ;; TODO: Can't remembed why this was important... but I think + ;; it is. + (let ((template-pwclient (string-append + out-site-packages + "patchwork/templates/patchwork/pwclient"))) + (delete-file template-pwclient) + (copy-file (string-append out-site-packages + "patchwork/bin/pwclient") + template-pwclient)) + + ;; Collect the static assets, this includes JavaScript, CSS and + ;; fonts. This is a standard Django process when running a + ;; Django application for regular use, and includes assets for + ;; dependencies like the admin site from Django. + ;; + ;; 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"))) + (mkdir-p static-root) + (copy-file "patchwork/settings/production.example.py" + "patchwork/settings/assets.py") + (setenv "DJANGO_SECRET_KEY" "dummyvalue") + (setenv "DJANGO_SETTINGS_MODULE" "patchwork.settings.assets") + (setenv "STATIC_ROOT" static-root) + (invoke "./manage.py" "collectstatic" "--no-input")) + + ;; The lib directory includes example configuration files that + ;; may be useful when deploying patchwork. + (copy-recursively "lib" + (string-append + out "/share/doc/" ,name "-" ,version))) + #t)) + ;; The hasher script is used from the post-receive.hook + (add-after 'install 'install-hasher + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (out-site-packages (site-packages inputs outputs)) + (out-hasher.py (string-append out-site-packages + "/patchwork/hasher.py"))) + (chmod out-hasher.py #o555) + (symlink out-hasher.py (string-append out "/bin/hasher"))) + #t)) + ;; Create a patchwork specific version of Django's command line admin + ;; utility. + (add-after 'install 'install-patchwork-admin + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out"))) + (mkdir-p (string-append out "/bin")) + (call-with-output-file (string-append out "/bin/patchwork-admin") + (lambda (port) + (simple-format port "#!~A +import os, sys + +if __name__ == \"__main__\": + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv)" (which "python")))) + (chmod (string-append out "/bin/patchwork-admin") #o555)) + #t))))) + (inputs + `(("python-wrapper" ,python-wrapper))) + (propagated-inputs + `(("python-django" ,python-django) + ;; TODO: Make this configurable + ("python-psycopg2" ,python-psycopg2) + ("python-mysqlclient" ,python-mysqlclient) + ("python-django-filter" ,python-django-filter) + ("python-djangorestframework" ,python-djangorestframework) + ("python-django-debug-toolbar" ,python-django-debug-toolbar))) + (synopsis "Web based patch tracking system") + (description + "Patchwork is a patch tracking system. It takes in emails containing +patches, and displays the patches along with comments and state information. +Users can login allowing them to change the state of patches.") + (home-page "http://jk.ozlabs.org/projects/patchwork/") + (license gpl2+))) From patchwork Fri Jan 25 21:00:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 822 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E4850169BD; Fri, 25 Jan 2019 21:01:22 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id EA6E4169BD for ; Fri, 25 Jan 2019 21:01:21 +0000 (GMT) Received: from localhost ([127.0.0.1]:50623 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn8bJ-0000v5-9E for patchwork@mira.cbaines.net; Fri, 25 Jan 2019 16:01:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn8bB-0000qt-1p for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gn8b5-0002OV-PZ for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:10 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:46324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gn8b1-0002Mo-NX for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gn8b1-0008KD-LA for guix-patches@gnu.org; Fri, 25 Jan 2019 16:01:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#33185] [PATCH v3 2/2] services: Add patchwork. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 25 Jan 2019 21:01:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33185 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 33185@debbugs.gnu.org Received: via spool by 33185-submit@debbugs.gnu.org id=B33185.154845002031928 (code B ref 33185); Fri, 25 Jan 2019 21:01:03 +0000 Received: (at 33185) by debbugs.gnu.org; 25 Jan 2019 21:00:20 +0000 Received: from localhost ([127.0.0.1]:45604 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gn8aJ-0008Ip-77 for submit@debbugs.gnu.org; Fri, 25 Jan 2019 16:00:19 -0500 Received: from li622-129.members.linode.com ([212.71.249.129]:56784 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gn8a5-0008HQ-WE for 33185@debbugs.gnu.org; Fri, 25 Jan 2019 16:00:07 -0500 Received: from localhost (cpc102582-walt20-2-0-cust14.13-2.cable.virginm.net [86.27.34.15]) by mira.cbaines.net (Postfix) with ESMTPSA id 1C30F169C0 for <33185@debbugs.gnu.org>; Fri, 25 Jan 2019 21:00:05 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id c91e1ac1 for <33185@debbugs.gnu.org>; Fri, 25 Jan 2019 21:00:04 +0000 (UTC) From: Christopher Baines Date: Fri, 25 Jan 2019 21:00:04 +0000 Message-Id: <20190125210004.28221-2-mail@cbaines.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190125210004.28221-1-mail@cbaines.net> References: <87y3aie8a1.fsf@cbaines.net> <20190125210004.28221-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/service/web.scm ( , ): New record types. (patchwork-virtualhost): New procedure. (patchwork-service-type): New variable. * gnu/tests/web.scm (%test-patchwork): New variable. --- gnu/services/web.scm | 284 ++++++++++++++++++++++++++++++++++++++++++- gnu/tests/web.scm | 160 +++++++++++++++++++++++- 2 files changed, 442 insertions(+), 2 deletions(-) diff --git a/gnu/services/web.scm b/gnu/services/web.scm index d71fed20ed..1986c2095c 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -32,12 +32,17 @@ #:use-module (gnu system pam) #:use-module (gnu system shadow) #:use-module (gnu packages admin) + #:use-module (gnu packages databases) #:use-module (gnu packages web) + #:use-module (gnu packages patchutils) #:use-module (gnu packages php) + #: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) #:use-module (guix gexp) #:use-module ((guix store) #:select (text-file)) #:use-module ((guix utils) #:select (version-major)) @@ -211,7 +216,42 @@ varnish-configuration-parameters varnish-configuration-extra-options - varnish-service-type)) + varnish-service-type + + + patchwork-database-configuration + patchwork-database-configuration? + patchwork-database-configuration-engine + patchwork-database-configuration-name + patchwork-database-configuration-user + patchwork-database-configuration-password + patchwork-database-configuration-host + patchwork-database-configuration-port + + + patchwork-settings-module + patchwork-settings-module? + patchwork-settings-module-database-configuration + patchwork-settings-module-secret-key + patchwork-settings-module-allowed-hosts + patchwork-settings-module-default-from-email + patchwork-settings-module-static-url + patchwork-settings-module-admins + patchwork-settings-module-debug? + patchwork-settings-module-enable-rest-api? + patchwork-settings-module-enable-xmlrpc? + patchwork-settings-module-force-https-links? + patchwork-settings-module-extra-settings + + + patchwork-configuration + patchwork-configuration? + patchwork-configuration-patchwork + patchwork-configuration-settings-module + patchwork-configuration-domain + + patchwork-virtualhost + patchwork-service-type)) ;;; Commentary: ;;; @@ -1269,3 +1309,245 @@ files.") varnish-shepherd-service))) (default-value (varnish-configuration)))) + + +;;; +;;; Patchwork +;;; + +(define-record-type* + patchwork-database-configuration make-patchwork-database-configuration + patchwork-database-configuration? + (engine patchwork-database-configuration-engine + (default "django.db.backends.postgresql_psycopg2")) + (name patchwork-database-configuration-name + (default "patchwork")) + (user patchwork-database-configuration-user + (default "httpd")) + (password patchwork-database-configuration-password + (default "")) + (host patchwork-database-configuration-host + (default "")) + (port patchwork-database-configuration-port + (default ""))) + +(define-record-type* + patchwork-settings-module make-patchwork-settings-module + patchwork-settings-module? + (database-configuration patchwork-settings-module-database-configuration + (default (patchwork-database-configuration))) + (secret-key-file patchwork-settings-module-secret-key-file + (default "/etc/patchwork/django-secret-key")) + (allowed-hosts patchwork-settings-module-allowed-hosts) + (default-from-email patchwork-settings-module-default-from-email) + (static-url patchwork-settings-module-static-url + (default "/static/")) + (admins patchwork-settings-module-admins + (default '())) + (debug? patchwork-settings-module-debug? + (default #f)) + (enable-rest-api? patchwork-settings-module-enable-rest-api? + (default #t)) + (enable-xmlrpc? patchwork-settings-module-enable-xmlrpc? + (default #t)) + (force-https-links? patchwork-settings-module-force-https-links? + (default #t)) + (extra-settings patchwork-settings-module-extra-settings + (default ""))) + +(define-record-type* + patchwork-configuration make-patchwork-configuration + patchwork-configuration? + (patchwork patchwork-configuration-patchwork + (default patchwork)) + (settings-module patchwork-configuration-settings-module) + (domain patchwork-configuration-domain)) + +;; Django uses a Python module for configuration, so this compiler generates a +;; Python module from the configuration record. +(define-gexp-compiler (patchwork-settings-module-compiler + (file ) system target) + (match file + (($ database-configuration secret-key-file + allowed-hosts default-from-email + static-url admins debug? enable-rest-api? + enable-xmlrpc? force-https-links? + extra-configuration) + (gexp->derivation + "patchwork-settings" + (with-imported-modules '((guix build utils)) + #~(let ((output #$output)) + (define (create-__init__.py filename) + (call-with-output-file filename + (lambda (port) (display "" port)))) + + (use-modules (guix build utils) + (srfi srfi-1)) + + (mkdir-p (string-append output "/guix/patchwork")) + (create-__init__.py + (string-append output "/guix/__init__.py")) + (create-__init__.py + (string-append output "/guix/patchwork/__init__.py")) + + (call-with-output-file + (string-append output "/guix/patchwork/settings.py") + (lambda (port) + (display + (string-append "from patchwork.settings.base import * + +# Configuration from Guix +with open('" #$secret-key-file "') as f: + SECRET_KEY = f.read().strip() + +ALLOWED_HOSTS = [ +" #$(string-concatenate + (map (lambda (allowed-host) + (string-append " '" allowed-host "'\n")) + allowed-hosts)) +"] + +DEBUG = " #$(if debug? "True" "False") " + +ENABLE_REST_API = " #$(if enable-xmlrpc? "True" "False") " +ENABLE_XMLRPC = " #$(if enable-xmlrpc? "True" "False") " + +FORCE_HTTPS_LINKS = " #$(if force-https-links? "True" "False") " + +DATABASES = { + 'default': { +" #$(match database-configuration + (($ + engine name user password host port) + (string-append + " 'ENGINE': '" engine "',\n" + " 'NAME': '" name "',\n" + " 'USER': '" user "',\n" + " 'PASSWORD': '" password "',\n" + " 'HOST': '" host "',\n" + " 'PORT': '" port "',\n"))) " + }, +} + +" #$(if debug? + #~(string-append "STATIC_ROOT = '" #$(file-append patchwork "/share/patchwork/htdocs") "'") + #~(string-append "STATIC_URL = '" #$static-url "'")) " + +STATICFILES_STORAGE = ( + 'django.contrib.staticfiles.storage.StaticFilesStorage' +) + +# Guix Extra Configuration +" #$extra-configuration " +") port))) + #t)) + #:local-build? #t)))) + +(define patchwork-virtualhost + (match-lambda + (($ patchwork settings-module + domain) + + (define wsgi.py + (file-append patchwork + (string-append + "/lib/python" + (version-major+minor + (package-version python)) + "/site-packages/patchwork/wsgi.py"))) + + (httpd-virtualhost + "*:8080" + `("ServerAdmin admin@example.com +ServerName " ,domain " + +LogFormat \"%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" customformat +LogLevel info +CustomLog \"/var/log/httpd/" ,domain "-access_log\" customformat + +ErrorLog /var/log/httpd/error.log + +WSGIScriptAlias / " ,wsgi.py " +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 + + + Require all granted + + +Alias /static " ,patchwork "/share/patchwork/htdocs + + AllowOverride None + Options MultiViews Indexes SymlinksIfOwnerMatch IncludesNoExec + Require method GET POST OPTIONS +"))))) + +(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-django-admin-gexp patchwork settings-module) + #~(lambda command + (let ((pid (primitive-fork)) + (user (getpwnam "httpd"))) + (if (eq? pid 0) + (dynamic-wind + (const #t) + (lambda () + (setgid (passwd:gid user)) + (setuid (passwd:uid user)) + + (setenv "DJANGO_SETTINGS_MODULE" "guix.patchwork.settings") + (setenv "PYTHONPATH" #$settings-module) + (primitive-exit + (if (zero? + (apply system* + #$(file-append patchwork "/bin/patchwork-admin") + command)) + 0 + 1))) + (lambda () + (primitive-exit 1))) + (zero? (cdr (waitpid pid))))))) + +(define (patchwork-django-admin-action patchwork settings-module) + (shepherd-action + (name 'django-admin) + (documentation + "Run a django admin command for patchwork") + (procedure (patchwork-django-admin-gexp patchwork settings-module)))) + +(define patchwork-service-type + (service-type + (name 'patchwork-setup) + (extensions + (list (service-extension httpd-service-type + patchwork-httpd-configuration) + (service-extension + shepherd-root-service-type + (match-lambda + (($ patchwork settings-module + domain) + (list (shepherd-service + (requirement '(postgres)) + (provision (list (string->symbol + (string-append (package-name patchwork) + "-setup")))) + (start + #~(lambda () + (define run-django-admin-command + #$(patchwork-django-admin-gexp patchwork + settings-module)) + + (run-django-admin-command "migrate"))) + (stop #~(const #f)) + (actions + (list (patchwork-django-admin-action patchwork + settings-module))) + (respawn? #f) + (documentation "Setup patchwork.")))))))) + (description + "Patchwork patch tracking system."))) diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 319655396a..0b109c0ed7 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm @@ -28,15 +28,27 @@ #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services web) + #:use-module (gnu services databases) #:use-module (gnu services networking) + #:use-module (gnu services shepherd) + #:use-module (gnu packages databases) + #:use-module (gnu packages patchutils) + #:use-module (gnu packages python) + #:use-module (gnu packages web) + #:use-module (guix packages) + #:use-module (guix modules) + #:use-module (guix records) #:use-module (guix gexp) #:use-module (guix store) + #:use-module (guix utils) + #:use-module (ice-9 match) #:export (%test-httpd %test-nginx %test-varnish %test-php-fpm %test-hpcguix-web - %test-tailon)) + %test-tailon + %test-patchwork)) (define %index.html-contents ;; Contents of the /index.html file. @@ -498,3 +510,149 @@ HTTP-PORT." (name "tailon") (description "Connect to a running Tailon server.") (value (run-tailon-test)))) + + +;;; +;;; Patchwork +;;; + +(define patchwork-initial-database-setup-service + (match-lambda + (($ + engine name user password host port) + + (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") + #$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-os patchwork) + (simple-operating-system + (service dhcp-client-service-type) + (service httpd-service-type + (httpd-configuration + (config + (httpd-config-file + (listen '("8080")))))) + (service postgresql-service-type) + (simple-service 'patchwork-create-django-secret-key + activation-service-type + #~(begin + (mkdir "/etc/patchwork") + (call-with-output-file "/etc/patchwork/django-secret-key" + (lambda (p) + (display "000000\n" p))) + #t)) + (service patchwork-service-type + (patchwork-configuration + (patchwork patchwork) + (settings-module + (patchwork-settings-module + (allowed-hosts '("*")) + (default-from-email "") + (debug? #t))) + (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) + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define forwarded-port 8080) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings `((8080 . ,forwarded-port))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-11) (srfi srfi-64) + (gnu build marionette) + (web uri) + (web client) + (web response)) + + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "patchwork") + + (test-assert "patchwork-postgresql-user-and-service started" + (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) + ((pid) (number? pid)))))) + marionette)) + + (test-assert "httpd running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'httpd)) + marionette)) + + (test-equal "http-get" + 200 + (let-values + (((response text) + (http-get #$(simple-format + #f "http://localhost:~A/" forwarded-port) + #:decode-body? #t))) + (response-code response))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "patchwork-test" test)) + +(define %test-patchwork + (system-test + (name "patchwork") + (description "Connect to a running Patchwork service.") + (value (run-patchwork-test patchwork))))