# Server Setup

How to set up autograde from scratch. This guide assumes you have full root access to a dedicated server/vps instance, and a fresh install of Ubuntu 18.04 LTS (As of this writing).

# Prerequisites/Dependencies

WARNING

Due to the nature of Docker, AutoGrade is unable to support most OpenVZ virtualized environments due to inabilities to run Docker. A dedicated server, or KVM based host is preferred. (ex. Linode, DigitalOcean)

The AutoGrade middle-end/backend relies on the following technologies:

  • MariaDB (Tested on 10.3.13 or higher)
    • Set up with an autograde database, and an autograde user.
  • Docker (Tested on 18.09.5 or higher)
  • NodeJS (Tested on 10.16.0 or higher)
    • pm2 (global dependency)
    • yarn (global dependency)
  • Nginx preferred (Tested on nginx/1.15.9)
  • Git (For autograde git integration)
    • sudo apt install git

# Example Dependency Installation

The commands below are simply an example of how you might install these dependencies. Please consult with your operating system's package manager to determine the correct packages to install. Run commands below as sudo/root


# Linux Users Setup

We HIGHLY recommend to run all autograde services, with the exception of the grading daemon (Due to docker) under an autograde user.

We have set up an autograde user as follows

adduser autograde

# Database setup

Install MariaDB, and create an autograde database/user/pass

# Add additional repositories for MariaDB
sudo curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

# Update repositories list
sudo apt update

# Install MariaDB
sudo apt install mariadb-server

# Open MySQL/MariaDB shell
sudo mysql -u root

You should now be granted with the MariaDB/MySQL shell. Type the following comands below in order:

  • Create the autograde database
CREATE DATABASE autograde;
  • Create the autograde user, replacing your desired password
CREATE USER 'autograde'@'localhost' IDENTIFIED BY 'your_desired_autograde_db_pass';
  • Assign autograde user to autograde DATABASE
GRANT ALL ON autograde.* TO 'autograde'@'localhost';
  • Reload Permissions
FLUSH PRIVILEGES;

# Docker Setup

Most things are from https://docs.docker.com/install/linux/docker-ce/ubuntu/

# HTTPS repository Dependencies
sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# Add dockers official GPG key
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Set up stable docker repo
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Update
sudo apt update

# Install latest versions of docker-ce/containerd
sudo apt install docker-ce docker-ce-cli containerd.io

# Verify docker is installed
sudo docker run hello-world

If your docker hello world works, then proceed to the next step.

# NodeJS setup

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs

# Install yarn globally and pm2
npm install -g yarn pm2

# Set up pm2 startup for the autograde user
su autograde
pm2 startup

Upon typing pm2 startup under the user autograde, you will be prompted to run a command as sudo. An example output is:

[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u autograde --hp /home/autograde

Simply copy that last line, then type exit to go back to the root user, and execute the command as root.

Continuing on as the root user:

# pm2 startup for root
pm2 startup

This concludes preliminary NodeJS install.

# Nginx config, with LetsEncrypt SSL

# Add certbot PPA
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update

# Install nginx and certbot
sudo apt-get install nginx certbot python-certbot-nginx

Example Nginx config, replace your.domain.here with your domain pointing to your server.

Place the config below in a file called autograde under /etc/nginx/sites-enabled/

server {
        index index.html index.htm;

        server_name   your.domain.here;

        root /home/autograde/www;

        client_max_body_size 50M;

        location ^~ /git/ {
                proxy_pass http://127.0.0.1:7005/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
        }

        location ^~ /api/v1/ {
                proxy_pass       http://127.0.0.1:8080;
                proxy_set_header Host      $host;
                proxy_set_header X-Real-IP $remote_addr;
        }

        location ^~ /api-docs {
                proxy_pass http://127.0.0.1:8080;
        }

        location / {
                try_files $uri $uri/ /index.html;
        }
}

Once the configuration file for nginx/autograde has been placed, confirm it is valid with

sudo nginx -t

#Then reload
sudo service nginx restart

Now we can create SSL certificates for your domain, if needed with certbot.

Simply run

sudo certbot

and follow the on screen prompts.

Be sure when it asks Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. to select option 2 for redirect.

This concludes preliminary setup to run autograde! In the next section, we will clone the autograde repo and configure.