aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-11-23 11:02:36 +0100
committerWojtek Kosior <koszko@koszko.org>2022-11-23 11:18:02 +0100
commit2b2c70932bf6ffcd77fbe5f6c59a203299f755a5 (patch)
tree5efca6171b7f7984612a5d7b6e0d63d9a89d9b25
parent366d927d626065db29cdf4aeb92a2122683cdf73 (diff)
downloadhydrilla-website-2b2c70932bf6ffcd77fbe5f6c59a203299f755a5.tar.gz
hydrilla-website-2b2c70932bf6ffcd77fbe5f6c59a203299f755a5.zip
add WSGI script
-rw-r--r--guix-module-dir/hydrilla-website.scm32
-rw-r--r--src/hydrilla_website/__init__.py2
-rw-r--r--wsgi.py16
3 files changed, 49 insertions, 1 deletions
diff --git a/guix-module-dir/hydrilla-website.scm b/guix-module-dir/hydrilla-website.scm
index af593bf..ce76784 100644
--- a/guix-module-dir/hydrilla-website.scm
+++ b/guix-module-dir/hydrilla-website.scm
@@ -57,6 +57,38 @@
;; checkout. We instead build from source tarball generated under ./dist/.
(local-file (string-append %source-dir "/dist/" source-tarball-name)))
(build-system python-build-system)
+ (arguments
+ `(#:phases
+ (modify-phases %standard-phases
+ (add-after 'unpack 'replace-wsgi.py
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ ;; In the wsgi.py file, embed the PYTHONPATH containing both the
+ ;; dependencies and the python modules of this package. This will
+ ;; make them available at runtime.
+ (let ((pythonpath
+ (string-append (getenv "GUIX_PYTHONPATH")
+ ":"
+ (site-packages inputs outputs))))
+ (substitute* "wsgi.py"
+ (("^from .* import .*" import-line)
+ (string-append
+ "# Make Guix-installed dependencies visible to Python.\n"
+ "import sys\n"
+ "sys.path.extend('" pythonpath "'.split(':'))\n"
+ "\n"
+ import-line))
+ (("^set_secret.*")
+ (string-append
+ "from pathlib import Path\n"
+ "path_to_secret = Path('/etc/hydrilla-website/secret.txt')\n"
+ "if path_to_secret.exists():\n"
+ " set_secret(path_to_secret.read_text().strip())"))))))
+ (add-after 'install 'install-wsgi-script
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ (let* ((out (assoc-ref outputs "out"))
+ (share-dir (string-append out "/share/hydrilla-website")))
+ (mkdir-p share-dir)
+ (copy-file "wsgi.py" (string-append share-dir "/wsgi.py"))))))))
(propagated-inputs
(list python-flask))
(native-inputs
diff --git a/src/hydrilla_website/__init__.py b/src/hydrilla_website/__init__.py
index 3ac4327..f3bd4e7 100644
--- a/src/hydrilla_website/__init__.py
+++ b/src/hydrilla_website/__init__.py
@@ -4,4 +4,4 @@
#
# Available under the terms of Creative Commons Zero v1.0 Universal.
-from .app import website_app
+from .app import website_app, set_secret
diff --git a/wsgi.py b/wsgi.py
new file mode 100644
index 0000000..d43f8e3
--- /dev/null
+++ b/wsgi.py
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: CC0-1.0
+
+# WSGI script for Hydrilla&Haketilo website.
+#
+# Copyright (C) 2022 Wojtek Kosior
+
+# Uncomment the lines below if you want to use a virtualenv installation of
+# the website package.
+
+#from pathlib import Path
+#path = Path('/path/to/virtualenv/bin/activate_this.py')
+#exec(path.read_text(), {'__file__': str(path)})
+
+from hydrilla_website import website_app as application, set_secret
+
+set_secret('please replace this with something appropriate')