Project: Code Quality Portal
Link: http://codequalityportal.tk
Team 6 Members:
- Fatema Olia: folia
- Rachit Shah: rshah25
- Udit Misra: umisra
- Steps adopted from this tutorial
- Create an account on Digital Ocean and buy an Ubuntu 18.04 droplet
- Add the necessary SSH keys to access the droplet remotely via terminal
- Create a domain name on sites like FreeNom (e.g., codequalityportal.tk).
- Add ip address of the droplet to their DNS service when buying the domain name.
- Add ns1.digitalocean.com, ns2.digitalocean.com and ns3.digitalocean.com to the nameserver on FreeNom client area.
- Add the domain to DigitalOcean's droplet
- Create a non-root user on the droplet and ssh to the droplet using that user. We create a non-root user named sammy. If you use another name, change the consecutive steps accordingly.
- Install nginx on the droplet.
- Domain name should redirect to "Welcome nginx" page after following the above steps
- Install python and other packages from terminal.
sudo apt update
sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
- Clone our repository and switch to branch "deploy".
- Create a Python3 virtual env
sudo apt install python3-venv
python3.6 -m venv myprojectenv
source myprojectenv/bin/activate
- Install all requirements.
cd csc510-project/CodeQualityPortal
pip install -r requirements.txt
- Open port 5000 in the firewall to let remote users access the hosted app on localhost
sudo ufw allow 5000
- Before deploying the app check if the app works on the localhost by following these steps from the first CodeQualityPortal folder in the repo
cd csc510-project/CodeQualityPortal
export FLASK_APP=__init__
flask run --host=0.0.0.0
- Accessing the site with the domain name/ip address and port should open the app in the browser.
http://your_server_ip:5000 (e.g. http://codequalityportal.tk:5000)
- Close the flask run command.
- Test if uWSGI is working to deploy our app using the following command.
uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app
- Again accessing the site with the domain name/ip address and port should open the app in the browser.
http://your_server_ip:5000 (e.g. http://codequalityportal.tk:5000)
- Close the command and deactivate the virtual environment
deactivate
- Create a systemd unit service file which will allow Ubuntu's init system to automatically start uWSGI and serve the Flask application whenever the server boots.
sudo nano /etc/systemd/system/CodeQualityPortal.service
- Add the following code changing user name and paths accordingly
[Unit]
Description=uWSGI instance to serve CodeQualityPortal
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/CodeQualityPortal
Environment="PATH=/home/sammy/myprojectenv/bin"
ExecStart=/home/sammy/myprojectenv/bin/uwsgi --ini CodeQualityPortal.ini
[Install]
WantedBy=multi-user.target
- Start the uWSGI service we created and enable it so that it starts at boot
sudo systemctl start CodeQualityPortal
sudo systemctl enable CodeQualityPortal
- Check the status and check that it returns active
sudo systemctl status CodeQualityPortal
- Create a new server block configuration file in Nginx's sites-available directory named CodeQualityPortal
sudo nano /etc/nginx/sites-available/CodeQualityPortal
- Add the following to the file while changing domain name, user name, paths and ports as needed.
server {
listen 80;
server_name codequalityportal.tk www.codequalityportal.tk;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/sammy/CodeQualityPortal/CodeQualityPortal.sock;
}
}
- Enable the Nginx server block configuration you've just created and link the file to the sites-enabled directory. Test for syntax errors
sudo ln -s /etc/nginx/sites-available/CodeQualityPortal /etc/nginx/sites-enabled
sudo nginx -t
- If there are no syntax errors, restart the Nginx process to read the new configuration.
sudo systemctl restart nginx
- Adjust firewall to open ports
sudo ufw delete allow 5000
sudo ufw allow 'Nginx Full'
-
Done! This should deploy the app. Check your domain name to see if its working. http://codequalityportal.tk
-
Check logs to see if there are any errors.
cat ~/log/CodeQualityPortal.log