Skip to content

Latest commit

 

History

History
112 lines (86 loc) · 4.59 KB

Installation.md

File metadata and controls

112 lines (86 loc) · 4.59 KB

Installation

For setting up a local environment for development, see the developer documentation

The metadata repository is a WSGI application written using the Flask framework. It also requires a relational database for storing data. SQLAlchemy, the library used for database interactions, supports several different databases. The metadata repository is developed and tested with SQLite and PostgreSQL.

There are many WSGI application servers available and Flask's documentation explains some options for deployment. A few choices are explained here.

Apache + mod_wsgi

The instructions below are for an Ubuntu system. Commands may vary for other distributions.

  1. Install Python 3.4+ and pip.

    apt-get install python3-dev libffi-dev python3-pip
  2. Install Apache and mod_wsgi.

    apt-get install apache2 apache2-dev
    pip3 install mod_wsgi
    mod_wsgi-express install-module
    echo "LoadModule wsgi_module $(mod_wsgi-express module-location)" > /etc/apache2/mods-available/wsgi_express.load
    echo "WSGIPythonHome /usr" > /etc/apache2/mods-available/wsgi_express.conf
    a2enmod wsgi_express
    service apache2 restart
  3. Install metadata repository dependencies.

    cd /path/to/metadata_repository
    pip3 install -r requirements.txt
  4. Install a driver for your database of choice. See SQLAlchemy's dialect documentation for options.

  5. Configure a virtual host. Create a file at /etc/apache2/sites-available/bdss_metadata_repository.conf and add the following:

    <VirtualHost *:80>
    
        <Directory "/path/to/metadata_repository">
            Require all granted
        </Directory>
    
        Alias /static/ /path/to/metadata_repository/app/static/
    
        WSGIDaemonProcess bdss user=www-data group=www-data processes=1 threads=5 \
            python-path=/usr/local/lib/python3.5/dist-packages:/path/to/metadata_repository
        WSGIScriptAlias / /path/to/metadata_repository/app.wsgi
        WSGIProcessGroup bdss
        WSGIApplicationGroup %{GLOBAL}
    
    </VirtualHost>

    The python-path in WSGIDaemonProcess may vary based on your version of Python.

  6. Configure the application. Create a .env file in the metadata_repository directory and add the following:

    DATABASE_URL=
    SESSION_KEY=
    

    The values for the options will depend on your specific configuration.

    • DATABASE_URL - Location of the database to use. See the SQLAlchemy documentation for more information. If you use a path to an SQLite database, it will be automatically created if it doesn't exist. For other database types, you may have to install an additional driver.

    • SESSION_KEY - Secret key for Flask sessions. To generate a random key, run dotenv set SESSION_KEY $(./scripts/generate_flask_key).

  7. Run database migrations. The with_dotenv script loads environment variables from the .env file created in the last step.

    cd /path/to/metadata_repository
    ./scripts/with_dotenv ./scripts/migrate
  8. Disable default Apache site.

    a2dissite 000-default
  9. Enable BDSS site and restart Apache.

    a2ensite bdss_metadata_repository
    service apache2 reload

For more information, see mod_wsgi's documentation or Flask's documentation on deploying with mod_wsgi.

Docker

The metadata repository can be also be deployed using Docker.

The repository includes a sample configuration file for Docker Compose to set up multiple app containers running the metadata repository using gunicorn behind an nginx proxy and backed by a PostgreSQL database.