-
Notifications
You must be signed in to change notification settings - Fork 102
Deploy Server
The reporting feature in the supplychainpy library was built using Flask and comes prepacked with uWSGI - an application server. Client-side, the prepackaged Flask server is used to serve the reporting feature. However, the Flask documentation advises that this server is best used for debugging and testing, not for production.
A web interface was chosen to avoid the problem faced by deploying on different operating systems. Initially, the expectation was the reports would be used client-side with only one user making requests. The built-in server for Flask is handy for this application.
This wiki explains two separate methods for deploying to an application server. 'Method 1' uses Flask's built-in server, and 'Method 2' uses Nginx and Gunicorn.
'Method 2' is necessary for a scenario in which an analyst wishes to share the reports with a team on a private internal server, where a more robust setup might be required. Supplychainpy is experimenting with deploying the reporting suite to a server (Ubuntu 16.04) using Nginx and Gunicorn.
'Method 2' using Nginx and Gunicorn requires a login with an alternative user to 'root'. Therefore, for 'Method 2', please start by setting up a new user. Otherwise only use 'Method 1' below.
To add another user please refer to the documentation provided by DigitalOcean (ignore is using Method 1).
Warning: Currently, the recommendations and simple exponential smoothing forecast are failing to load during the processing of the file. Feel free to test the reports using the library from source (master branch) and Method 1 on a remote server, but be aware of this limitation.
To create our Python environment, we are going to use Anaconda' Conda virtual environment manager. Check the Anaconda Archive for the latest version for your operating system. Since we are setting up on a 64bit Ubuntu 16.04 server we can use:
$ wget https://repo.continuum.io/archive/Anaconda3-5.0.0-Linux-x86_64.sh
Install the Anaconda package with:
$ bash Anaconda3-5.0.0-Linux-x86_64.sh
Add the path to the Anaconda manager to the bottom of you .bashrc file or use to add the path to current console session (remember to replace 'root' with whatever name you have specified for the system user):
$ export PATH=/root/anaconda3/bin:$PATH
The library uses Cython which requires a c/c++ compilier:
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install gcc
Create a virtual environment for the flask application:
$ conda create -n suchpy_env python=3.5
Activate the newly created virtual environment using:
$ source activate suchpy_env
Install Cython
(suchpy_env)$ pip install Cython
Clone the Repository
(suchpy_env)$ git clone https://github.com/KevinFasusi/supplychainpy.git
Move to the 'supplychainpy' directory:
(suchpy_env)$ cd supplychainpy
Build the library from source using the bash script provided. The script takes three variables the library name, the conda environment name used and the python packaging type (e.g. sdist, bdist, bdist_wheel etc.). We are using the bdist_wheel:
(suchpy_env)$ bash packaging_helper.sh supplychainpy suchpy_env bdist_wheel
The script will uninstall any previous version of the supplychainpy library and build a new package from source using bdist_wheel
, before finally installing the new package. If the script has been successful, skip to Install Dependencies and Copy Test Data File
If script above fails, make sure you are in the root directory of the 'supplychainpy' library and continue with the manual process below.
Check if the 'dist' directory is present:
(suchpy_env)$ ls
If so remove the dist folder and its content
(suchpy_env)$ rm -r dist/
Build the new package:
(suchpy_env)$ python setup.py bdist_wheel
Navigate to the newly created 'dist' folder and install the package (the package may have a slightly different name):
(suchpy_env)$ pip install supplychainpy.0.0.x-cp35-cp35m-linux_x86_64.whl
Now you should have the library installed on the server. We can copy a file from the cloned repo to use a sample data file for testing.
Navigate back out to the root difrectory of your system:
(suchpy_env)$ cd
Install the bot dependencies:
(suchpy_env)$ python -m textblob.download_corpora
and copy the data file here:
(suchpy_env)$ cp supplychainpy/supplychainpy/sample_data/complete_dataset_small.csv ~/complete_dataset_small.csv
To use the built in Flask webserver run the folloing command:
(suchpy_env)$ supplychainpy complete_dataset_small.csv -a -loc ~/ -lx --host 0.0.0.0 --debug
If there is an internal error, when launching the application in the browser, don't worry. The most important thing is that you now have a database named reporting.db on your server, populated with all the results of the calculation. This database is the backend for the reporting. Exit the current running process and run the following command removing the -a
flag:
(suchpy_env)$ supplychainpy complete_dataset_small.csv -loc ~/ -lx --host 0.0.0.0 --debug
The --debug
provides more information during the build process.
As mentioned above, this method should only be used for testing and not with servers expecting heavy traffic.
To be posted later