Browse Source

Prepare for alpha9

* Update documentation
* Update Docker files
* Add wsgi script
Stefano Cossu 6 years ago
parent
commit
b73053368d
8 changed files with 118 additions and 92 deletions
  1. 8 11
      README.rst
  2. 3 2
      docker/docker_entrypoint
  3. 0 31
      docker/etc/gunicorn.py
  4. 24 0
      docker/etc/gunicorn.yml
  5. 11 23
      docs/setup.rst
  6. 2 24
      requirements.txt
  7. 1 1
      setup.py
  8. 69 0
      wsgi.py

+ 8 - 11
README.rst

@@ -31,20 +31,17 @@ Dependencies
 Installation steps
 ~~~~~~~~~~~~~~~~~~
 
-1. Create a virtualenv in a project folder:
-   ``virtualenv -p <python 3.5+ exec path> <virtualenv folder>``
-2. Activate the virtualenv: ``source <path_to_virtualenv>/bin/activate``
-3. Clone this repo:
-   ``git clone https://github.com/scossu/lakesuperior.git``
-4. ``cd`` into repo folder
-5. Install dependencies: ``pip install -r requirements.txt``
-6. Start your STOMP broker, e.g.: ``coilmq &``. If you have another
+#. Create a virtualenv in a project folder:
+   ``python3 -m venv <virtualenv folder>``
+#. Activate the virtualenv: ``source <path_to_virtualenv>/bin/activate``
+#. Install dependencies: ``pip install -r requirements.txt``
+#. Start your STOMP broker, e.g.: ``coilmq &``. If you have another
    queue manager listening to port 61613 you can either configure a
    different port on the application configuration, or use the existing
    message queue.
-7. Run ``./lsup-admin bootstrap`` to initialize the binary and graph
-   stores
-8. Run ``./fcrepo``.
+#. Run ``lsup-admin bootstrap`` to initialize the binary and graph
+   stores.
+#. Run ``fcrepo``.
 
 Contributing
 ------------

+ 3 - 2
docker/docker_entrypoint

@@ -2,8 +2,9 @@
 
 mkdir -p /data/log /data/run /data/bootstrap
 cp ./data/bootstrap/* /data/bootstrap
+pip install -e .
 coilmq &
 if [ ! -d /data/ldpnr_store ] && [ ! -d /data/ldprs_store ]; then
-  echo yes | ./lsup-admin bootstrap
+  echo yes | lsup-admin bootstrap
 fi
-exec ./fcrepo
+exec fcrepo

+ 0 - 31
docker/etc/gunicorn.py

@@ -1,31 +0,0 @@
-# See: http://docs.gunicorn.org/en/stable/settings.html
-
-# Directory where to store logs, PIDfile, etc.
-_data_dir = '/data/'
-
-# Set app_mode to either 'prod', 'test' or 'dev'.
-# 'prod' is normal running mode. 'test' is used for running test suites.
-# 'dev' is similar to normal mode but with reload and debug enabled.
-_app_mode = 'dev'
-
-
-bind = "0.0.0.0:8000"
-workers = 4
-worker_class = 'gevent'
-max_requests = 512
-
-#user = "user"
-#group = "group"
-
-raw_env = 'APP_MODE={}'.format(_app_mode)
-
-# Set this to the directory containing logs, etc.
-# The path must end with a slash.
-#chdir = "/usr/local/lakesuperior/"
-
-daemon = _app_mode=='prod'
-pidfile = _data_dir + "run/fcrepo.pid"
-reload = _app_mode=='dev'
-
-accesslog = _data_dir + "log/gunicorn-access.log"
-errorlog = _data_dir + "log/gunicorn-error.log"

+ 24 - 0
docker/etc/gunicorn.yml

@@ -0,0 +1,24 @@
+# Set up main GUnicorn options.
+# See: http://docs.gunicorn.org/en/stable/settings.html
+
+# Commented values are the application defaults.
+
+# Directory where the WSGI server data are stored.
+data_dir: 'data'
+
+# Set app_mode to either 'prod', 'test' or 'dev'.
+# 'prod' is normal running mode. 'test' is used for running test suites.
+# 'dev' is similar to normal mode but with reload and debug enabled.
+app_mode: 'dev'
+
+#listen_addr: '0.0.0.0'
+#listen_port: 8000
+#workers: 4
+#worker_class: 'gevent'
+#max_requests: 512
+
+#user: ''
+#group: ''
+
+#preload_app: True
+

+ 11 - 23
docs/setup.rst

@@ -49,26 +49,14 @@ Installation steps
 #. Create a virtualenv in a project folder:
    ``python3 -m venv <virtualenv folder>``
 #. Activate the virtualenv: ``source <path_to_virtualenv>/bin/activate``
-#. Clone this repo:
-   ``git clone https://github.com/scossu/lakesuperior.git``
-#. ``cd`` into repo folder
 #. Install dependencies: ``pip install -r requirements.txt``
-
-   - (Optional) For a development server, install additional dependencies:
-     ``pip install -r requirements_dev.txt``. These include some heavyweight
-     packages needed for development and testing but not for regular operation.
-
-#. Start your STOMP broker, e.g.: ``coilmq &``.
-
-   - If you have another
-     queue manager listening to port 61613 you can either configure a
-     different port on the application configuration, or use the existing
-     message queue.
-
-#. Make sure that the ``lsup-admin`` and ``fcrepo`` files are executable.
-#. Run ``./lsup-admin bootstrap`` to initialize the binary and graph
+#. Start your STOMP broker, e.g.: ``coilmq &``. If you have another
+   queue manager listening to port 61613 you can either configure a
+   different port on the application configuration, or use the existing
+   message queue.
+#. Run ``lsup-admin bootstrap`` to initialize the binary and graph
    stores.
-#. Run ``./fcrepo``.
+#. Run ``fcrepo``.
 
 Configuration
 -------------
@@ -79,14 +67,14 @@ the ``data`` directory.
 
 To change the default configuration you should:
 
-1. Copy the ``etc.skeleton`` folder to a separate location
-2. Set the configuration folder location in the environment:
+#. Copy the ``etc.skeleton`` folder to a separate location
+#. Set the configuration folder location in the environment:
    ``export FCREPO_CONFIG_DIR=<your config dir location>`` (you can add
    this line at the end of your virtualenv ``activate`` script)
-3. Configure the application
-4. Bootstrap the app or copy the original data folders to the new
+#. Configure the application
+#. Bootstrap the app or copy the original data folders to the new
    location if any loction options changed
-5. (Re)start the server: ``./fcrepo``
+#. (Re)start the server: ``./fcrepo``
 
 The configuration options are documented in the files.
 

+ 2 - 24
requirements.txt

@@ -1,24 +1,2 @@
-CoilMQ==1.0.1
-Flask==0.12.2
-HiYaPyCo==0.4.11
-Pillow==4.3.0
-PyYAML==3.12
-arrow==0.10.0
-click-log==0.2.1
-click==6.7
-gevent==1.2.2
-gunicorn==19.7.1
-lmdb==0.93
-numpy==1.14.1
-pytest-flask==0.10.0
-pytest==3.2.2
-rdflib==4.2.2
-requests-toolbelt==0.8.0
-requests==2.18.4
-sphinx-rtd-theme==0.2.4
-stomp.py==4.1.20
-wheel==0.30.0a0
-
-# Uncomment this and remove all above when the project will be in PyPI.
-#--index-url https://pypi.python.org/lakesuperior/
-#-e .
+--index-url https://pypi.python.org/lakesuperior/
+-e .

+ 1 - 1
setup.py

@@ -26,7 +26,7 @@ with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
 
 setup(
     name='lakesuperior',
-    version='1.0.0a9pre1',
+    version='1.0.0a91',
 
     description='A Linked Data Platform repository sever.',
     long_description=long_description,

+ 69 - 0
wsgi.py

@@ -0,0 +1,69 @@
+import multiprocessing
+import yaml
+
+from os import environ, path
+
+import gunicorn.app.base
+
+from server import fcrepo
+
+
+default_config_dir = '{}/etc.defaults'.format(
+        path.dirname(path.abspath(__file__)))
+config_dir = environ.get('FCREPO_CONFIG_DIR', default_config_dir)
+config_file = '{}/gunicorn.yml'.format(config_dir)
+
+with open(config_file, 'r') as fh:
+    config = yaml.load(fh, yaml.SafeLoader)
+
+listen_addr = config.get('listen_addr', '0.0.0.0')
+listen_port = config.get('listen_port', 8000)
+preload_app = config.get('preload_app', True)
+app_mode = config.get('app_mode', 'prod')
+data_dir = path.realpath(config.get('data_dir'))
+
+def default_workers():
+    return (multiprocessing.cpu_count() * 2) + 1
+
+options = {
+    'bind': '{}:{}'.format(listen_addr, listen_port),
+    'workers': config.get('workers', default_workers()),
+    'worker_class': config.get('worker_class', 'gevent'),
+    'max_requests': config.get('max_requests', 512),
+
+    'user': config.get('user'),
+    'group': config.get('group'),
+
+    'raw_env': 'APP_MODE={}'.format(app_mode),
+
+    'preload_app': preload_app,
+    'daemon': app_mode=='prod',
+    'reload': app_mode=='dev' and not preload_app,
+
+    'pidfile': '{}/run/fcrepo.pid'.format(data_dir),
+    'accesslog': '{}/log/gunicorn-access.log'.format(data_dir),
+    'errorlog': '{}/log/gunicorn-error.log'.format(data_dir),
+}
+
+
+class WsgiApp(gunicorn.app.base.BaseApplication):
+
+    def __init__(self, app, options={}):
+        self.options = options
+        self.application = app
+        super(WsgiApp, self).__init__()
+
+    def load_config(self):
+        for key, value in self.options.items():
+            self.cfg.set(key.lower(), value)
+
+    def load(self):
+        return self.application
+
+
+def run():
+    WsgiApp(fcrepo, options).run()
+
+
+if __name__ == '__main__':
+    run()