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.
The instructions below are for an Ubuntu system. Commands may vary for other distributions.
-
Install Python 3.4+ and pip.
apt-get install python3-dev libffi-dev python3-pip
-
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
-
Install metadata repository dependencies.
cd /path/to/metadata_repository pip3 install -r requirements.txt
-
Install a driver for your database of choice. See SQLAlchemy's dialect documentation for options.
-
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
inWSGIDaemonProcess
may vary based on your version of Python. -
Configure the application. Create a
.env
file in themetadata_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)
.
-
-
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
-
Disable default Apache site.
a2dissite 000-default
-
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.
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.