This repository contains the Docker files to run a clone of the DMOJ site. It configures some additional services, such as mathoid and texoid.
First, Docker and Docker Compose must be installed. Installation instructions can be found on their respective websites.
Clone the repository:
cd ~
git clone https://git.epl.tw/DanielLin/dmoj_docker.git dmoj_docker
cd dmoj_docker
git submodule update --init --recursive
cp .env.example .envConfigure the environment variables in the files in .env. In particular, set the MYSQL_PASSWORD and MYSQL_ROOT_PASSWORD, DOMAIN and SECRET_KEY. Also, configure the server_name directive in .docker/nginx/nginx.conf.
Remember to configure local_settings.py (email).
Initialize the setup by moving the configuration files into the submodule and by creating the necessary directories:
mkdir -m777 problems mediaCreate dmoj_judge network
sudo docker network create dmoj_judgeNext, build the images:
sudo docker compose buildStart up the site, so you can perform the initial migrations and generate the static files:
sudo docker compose up -d uwsgiWait a few seconds to let the database initialize. You will need to generate the schema for the database, since it is currently empty:
sudo docker compose exec uwsgi python3 manage.py migrateYou will also need to generate the static files:
sudo docker compose exec uwsgi bash
./make_style.sh
cp -r resources/ /assets/
cp 502.html /assets/
cp logo.png /assets/
cp robots.txt /assets/
python3 manage.py collectstatic --noinput
python3 manage.py compilemessages
python3 manage.py compilejsi18n
exitFinally, the DMOJ comes with fixtures so that the initial install is not blank. They can be loaded with the following commands:
sudo docker compose exec uwsgi python3 manage.py loaddata navbar
sudo docker compose exec uwsgi python3 manage.py loaddata language_all # language_small
#sudo docker compose exec uwsgi python3 manage.py loaddata demoStart all containers with
sudo docker compose up -dsudo docker compose up -dAdd judge and generate token in admin site Build judge docker images
sudo apt-get install -y make
cd ~
git clone --recursive https://github.com/DMOJ/judge.git
cd judge/.docker
sudo make judge-tier3Run judge container, if you need to access the judge though api, you need to bind port 9998.
# e.g. -p "$(ip addr show dev eth0 | perl -ne 'm@inet (.*)/.*@ and print$1 and exit')":9998:9998
sudo docker run \
--name $JUDGE_NAME \
-v ~/dmoj_docker/problems:/problems \
--cap-add=SYS_PTRACE \
-d \
--restart=always \
dmoj/judge-tier3:latest \
run -p "9999" \
"dmoj_bridged" "$JUDGE_NAME" "$JUDGE_AUTHENTICATION_KEY"See if judge is running correctly
sudo docker ps -a
sudo docker logs judge1sudo docker compose exec uwsgi python3 manage.py adduser --staff --superuser account email password
sudo docker compose exec uwsgi python3 manage.py createsuperuser # if you use this command, you need to restart uwsgi to generate user profilesudo docker compose exec uwsgi python3 manage.py adduser account email passwordAs the DMOJ site is a Django app, you may need to migrate whenever you update. Assuming the site container is running, running the following command should suffice:
sudo docker compose exec uwsgi python3 manage.py migrateIf your static files ever change, you will need to rebuild them:
sudo docker compose exec uwsgi bash
./make_style.sh
python3 manage.py collectstatic --noinput
python3 manage.py compilemessages
python3 manage.py compilejsi18n
cp -r resources/ /assets/
cp 502.html /assets/
cp logo.png /assets/
cp robots.txt /assets/
exitgit submodule update --remote dmoj
git add dmoj
git commit -m "update submodule"Updating various sections of the site requires different images to be rebuilt.
If any prerequisites were modified, you will need to rebuild most of the images:
git reset --hard origin/master
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
sudo docker compose build
sudo docker compose up -d
sudo docker compose exec uwsgi bash
./make_style.sh
python3 manage.py collectstatic --noinput
python3 manage.py compilemessages
python3 manage.py compilejsi18n
python3 manage.py migrate
cp -rf resources/ /assets/
cp 502.html /assets/
cp logo.png /assets/
cp robots.txt /assets/
exit
sudo docker compose up -dIf the static files are modified, read the section on Managing Static Files.
If only the source code is modified, a restart is sufficient:
sudo docker compose restart site celery bridged wseventgit reset --hard origin/master
git submodule foreach --recursive git reset --hard
git submodule update --remote
git add .
git commit -m "git submodule updated"
git push originThe docker-compose.yml configures Nginx to publish to port 80. If you have another Nginx instance on your host machine, you may want to change the port and proxy pass instead.
For example, a possible Nginx configuration file on your host machine would be:
server {
listen 80;
listen [::]:80;
add_header X-UA-Compatible "IE=Edge,chrome=1";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
location / {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080/;
}
}
In this case, the port that the Nginx instance in the Docker container is published to would need to be modified to 10080.
Ensure that you also restart the Nginx container if you restart the site container as Nginx caches DNS queries. Otherwise, Nginx will try to hit the old IP, causing a 502 Bad Gateway. See this issue for more information.
Add a line in the http section of nginx.conf (/etc/nginx/nginx.conf) client_max_body_size 100M; and reload nginx