Daily Shaarli

All links of one day in a single page.

July 12, 2021

Install VNOJ

Installing the prerequisites

sudo apt update
sudo apt upgrade
sudo apt install build-essential python3-dev python3-pip libseccomp-dev libxml2-dev libxslt1-dev zlib1g-dev gettext curl redis-server mariadb-server libmysqlclient-dev

nvm install 18
nvm alias default 18

Creating the database

sudo service mariadb start
sudo mysql_secure_installation
sudo mysql
CREATE USER 'dmoj'@'localhost' IDENTIFIED BY 'PASSWORD';
CREATE USER 'dmoj'@'%' IDENTIFIED BY 'PASSWORD';
CREATE DATABASE dmoj DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON dmoj.* TO 'dmoj'@'localhost';
GRANT ALL PRIVILEGES ON dmoj.* TO 'dmoj'@'%';
exit

Cloning VNOJ

git clone --recursive https://github.com/VNOI-Admin/OJ.git
cd OJ

Installing prerequisites

We will create a virtual environment with pyenv and install the dependencies:

pyenv install 3.11.9
pyenv virtualenv 3.11.9 vnoj
pyenv local vnoj

pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install -r additional_requirements.txt
pip install flake8 flake8-import-order flake8-future-import flake8-commas flake8-logging-format flake8-quotes

npm install

Configuring

Start up the Redis server, which is needed by the Celery workers:

sudo service redis-server start

Download the sample settings file:

cd dmoj
wget https://github.com/VNOI-Admin/vnoj-docs/raw/master/sample_files/local_settings.py

You will now need to configure dmoj/local_settings.py. You need to update MySQL credentials and the secret key and uncommenting CELERY_BROKER_URL and CELERY_RESULT_BACKEND. By default, Redis listens on localhost port 6379, which is reflected in local_settings.py. You will need to update the addresses if you changed Redis's settings.

Now, verify that everything is going according to plan:

./manage.py check

Compiling assets

Compile and optimize the stylesheets:

./make_style.sh

Collect static files into STATIC_ROOT as specified in dmoj/local_settings.py:

./manage.py collectstatic --no-input

Generate internationalization files:

./manage.py compilemessages
./manage.py compilejsi18n

Setting up database tables

If you have a database backup, skip this step.

Generate the schema for the database and load some initial data:

./manage.py migrate
./manage.py loaddata navbar
./manage.py loaddata language_small
./manage.py loaddata demo

Create an admin account:

./manage.py createsuperuser

Running the server

You need to start MySQL and Redis after restart:

sudo service mariadb start
sudo service redis-server start

Let's run the server, and see if it all works:

./manage.py runserver 0.0.0.0:8000