A marketplace website for sharing custom model files for SasView
Deployed at http://marketplace.sasview.org
A script has been generated that will execute all the steps shown in the next section to provide an automated way of going from a fresh Ubuntu install to having a running marketplace, to run this you will need to type the following into an Ubuntu console
git clone https://github.com/SasView/sasmodel-marketplace
./sasmodel-marketplace/scripts/quick_setup.sh
As part of the installation process it will ask for your password to run sudo so the user that runs the installation will need to be on the sudoers list.
You should now be able to access the newly created SasView Marketplace site by navigating to 127.0.0.1 on a web browser the server itself or by navigating to the server's external IP address in a web browser on another machine.
N.B. This setup is only recommended for testing and development as the passwords generated are the same as the usernames and therefore are highly insecure and not suitable for deployment.
These instructions will create an installation of the SasView marketplace using the system Python installation on Ubuntu. This setup is suitable for environments where there is only one web service present on the server or virtual machine. Should the intention be to serve multiple sites from one machine the use of virtual Python environments is strongly recommended. More information about setting up and using a virtual environment can be found on these pages. These instructions should be usable for other Linux flavours, however, modifications may be required to the steps delineated below.
-
First download and install Ubuntu server edition, which is currently Ubuntu 18.04.1 LTS
-
After installation the
apache2,apache2-dev,postgresql,python3-devandpython3-setuptoolspackages will need to be installed via the system package manager, for Ubuntu this isaptand should be invoked thuslysudo apt install *package-name* -
As, by default, the command
pythonis undefined with onlypython3is installed we will make a symbolic link to allow both users and software to use Python 'as normal' by invokingsudo ln -s /usr/bin/python3 /usr/bin/python -
With Python setup it is then necessary to use
easy_installto installpipviasudo python /usr/lib/python3/dist-packages/easy_install.py pip -
With all the required operating system packages installed it is then necessary to clone the git repository into the appropriate location for the Apache web server by entering
sudo git clone https://github.com/SasView/sasmodel-marketplace /var/www/marketplace.sasview.org -
With the repository downloaded and
pipinstalled it is then possible to install all the marketplace dependencies using the followingsudo pip install -r /var/www/marketplace.sasview.org/requirements.txt -
Now, with all the appropriate software loaded, it is subsequently possible to set up the database in which all the models will be saved. Assuming that this is a new installation of Ubuntu this will also require setting up the
postgresuser with a password usingsudo passwd postgres- N.B. in these setup instructions all passwords will be the same as the entity that requires the password, i.e. the
postgresuser will have the passwordpostgres. This is not a suitable paradigm for deployment systems.
- N.B. in these setup instructions all passwords will be the same as the entity that requires the password, i.e. the
-
You can now
suto this user in order to use thepsqlcommandsu postgres ***insert super-secret password*** psql -
From
psqlyou can then set up a postgres user and a storage database by entering in the following three commandsCREATE DATABASE sasmodeldatabase; CREATE USER sasmodeluser WITH PASSWORD 'sasmodeluser'; GRANT ALL PRIVILEGES ON DATABASE sasmodeldatabase TO sasmodeluser; -
With the database created you may
\qfrompsqlandexitfrom thepostgresuser shell, returning to the/var/www/marketplace.sasview.orgdirectory for the subsequent steps -
It is now necessary to alter the
settings.pyfile for the site in thesasmarketdirectory. Taking a copy of the example file is recommendedsudo cp /var/www/sasmarket/settings.py.example /var/www/sasmarket/settings.pyInside this file the following will need to be altered
- Line 26 - Debug boolean (when ready for deployment)
DEBUG = False - Line 28 - Allowed hosts, i.e.
ALLOWED_HOSTS = ['127.0.0.1'] - Line 82 - Database name
'NAME': 'sasmodeldatabase' - Line 83 - Database user
'USER': 'sasmodeluser' - Line 84 - Database password
'PASSWORD': 'sasmodeluser'
- Line 26 - Debug boolean (when ready for deployment)
-
Following the installation of the marketplace dependencies it is necessary to perform a migration, from the root marketplace directory, using
sudo python manage.py migrate -
Now that the site is configured, we must configure Apache accordingly, first copy the example Apache configuration file into the
sites-enabledfoldersudo cp /var/www/sasmarket/marketplace.sasview.org.conf.example /etc/apache2/sites-enabled/marketplace.sasview.org.conf -
Subsequently the
wsgimodification must be made available to Apache for which a script exists inside the marketplace repository, it can be run by executing/var/www/marketplace.sasview.org/scripts/mod_wsgi_generator.sh -
The final step is to restart the Apache webserver service by executing
sudo service apache2 restartAfter which the marketplace should be running and accessible from either the server itself via 127.0.0.1 or from external hosts using the server's external IP address.
- settings.py on the deployment server is different from the one in Github
- Secret keys and passwords are in there!
- Deployment is semi-automatic:
- When changes are pushed to Github, a Travis job is kicked off to test.
- If the tests pass, the code is pushed to a git repo on the deployment server.
- If any new static files are added, run the following on the server:
cd /var/www/marketplace.sasview.orgsource virtualenv/bin/activatewhich should give a prompt beginning with(virtualenv)- Collect static files with
sudo python manage.py collectstatic
- Any changes made won't take effect until Apache is reloaded with
sudo service apache2 reload
- Ensure you have a Postgresql server up and running
- Run
pip install -r requirements.txt - Rename
sasmarket/settings.py.exampletosasmarket/settings.pyand fill in the database details. - Run
python manage.py runserver