This repository contains the code for SELMA, our semantic and local code search system.
You need to have Java 11+ installed on your system in order to use Terrier. In order to use our Transformer-based features, we recommend using a platform which has access to at least one GPU (with CUDA installed).
We will use two programs to deploy our app, namely gunicorn and nginx.
- gunicorn is a python web server made for production (unlike flask's web server), and we will use it to run our backend app privately, on port 8000.
- nginx will serve the static files from our frontend app and it will make our backend public.
- Connect to the server through ssh
- Clone the retrievalsystem's app
- Navigate to
retrievalsystem/frontend
and runyarn
- Once the dependencies are installed, build the frontend app by running
yarn build
- Navigate to
retrievalsystem/backend
and create a venv:python3 -m venv venv
- Activate the venv:
source venv/bin/activate
- Apply migrations to
app.db
:flask db upgrade
(See [6]) - Install the requirements:
pip install -r requirements.txt
- Install gunicorn:
pip install gunicorn
- If nginx is not already installed, then install it:
sudo apt update
sudo apt install nginx
- nginx creates 2 folders:
/etc/nginx/sites-available
and/etc/nginx/sites-enabled
.- Normally, it comes with a file
default.nginx
insidesites-available
and a soft link to it insidesites-enabled
. If that's the case, then delete these files.
- Normally, it comes with a file
- Inside
sites-available
create a fileretrievalsystem.nginx
.-
Paste the following text inside that file, chage the root's path and save it.
server { # listen on port 80 (http) listen 80; # serve static files root /path/to/retrievalsystem/frontend/build; # tells nginx which file to serve when the client doesn't # request any file index index.html; # by specifying locations, nginx defines attributes that apply to # group of urls for any url starting with '/' nginx will see if # it can serve a file if $uri doesnt exist, then we try again, # but now we will treat it as a directory $uri/ if neither work, # then return 404 (not found) location / { try_files $uri $uri/ =404; } location /api/v1 { include proxy_params; # The proxy_pass command gives the address where the proxied # service is listening for requests. proxy_pass http://localhost:5000; } }
-
- Create a soft-link for the file created in the previous step in
/etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/retrievalsystem.nginx /etc/nginx/sites-enabled/retrievalsystem.nginx
- To install gunicorn, activate the desired virtual environment and run
pip install gunicorn
We want to run gunicorn as a service, instead of opening a terminal and running the flask app by hand. This has the advantage that, even if the server is rebooted, the app will restart it self as soon as the server is powered again (nginx also runs as a service).
To do that, we will use systemd
.
- Navigate to
/etc/systemd/system
- Create a file:
touch retrievalsystem.service
- Paste the following text inside that file, change the User, the WorkingDirectory and the ExecStart variables and save it.
⚠️ The GPU-Server used by us is shared with other people, so the app should not start automatically. For that reason, we should change the 6th line of the file below fromRestart=always
toRestart=no
when deplyoing there.
[Unit]
Description=Retrival System
[Service]
User=<username-of-who-is-running-the-service>
Restart=always
WorkingDirectory=/path/to/retrievalsystem
ExecStart=/path/to/retrievalsystem/backend/venv/bin/gunicorn -b localhost:5000 retrievalsystem:app
[Install]
WantedBy=networking.target
If the app is already installed and all you wish is to update it, all you need to do is:
- Update the project with
git pull
- (optional) Rebuild the frontend app:
- Navigate to
retrievalsystem/frontend
and runyarn build
- Navigate to