Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions buildall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
set -e
git submodule update --init --recursive

cd dmoj

mkdir -p problems media

cp ../config.js repo/websocket/
cp ../local_settings.py repo/dmoj/
cp ../uwsgi.ini repo/

docker compose build
docker compose up -d db
docker compose up -d redis
docker compose up -d site

docker compose exec $COMPOSE_EXEC_FLAGS site python3 manage.py makemigrations $@
docker compose exec $COMPOSE_EXEC_FLAGS site python3 manage.py migrate $@

docker compose exec $COMPOSE_EXEC_FLAGS site /bin/bash -c "\
bash make_style.sh && \
python3 manage.py collectstatic --noinput && \
python3 manage.py compilemessages && \
python3 manage.py compilejsi18n && \
cp -r resources/ /assets/ && \
rm resources/style.css resources/martor-description.css resources/select2-dmoj.css resources/ace-dmoj.css && \
rm resources/dark/style.css resources/dark/martor-description.css resources/dark/select2-dmoj.css resources/dark/ace-dmoj.css && \
rm -r sass_processed && \
cp 502.html /assets/ && \
cp logo.png /assets/ && \
cp robots.txt /assets/"

docker compose up -d

#docker compose exec $COMPOSE_EXEC_FLAGS site python3 manage.py createsuperuser $@
5 changes: 5 additions & 0 deletions cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker system prune -a --volumes
docker rmi $(docker images -aq)
docker volume rm $(docker volume ls -q)

rm -rf dmoj/database
44 changes: 29 additions & 15 deletions dmoj/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
version: '3.7'
name: prod-medocker-moj-004
services:
db:
container_name: dmoj_mysql
#container_name: dmoj_mysql
image: mariadb
restart: always
volumes:
- ./database/:/var/lib/mysql/
env_file: [environment/mysql.env, environment/mysql-admin.env]
networks: [db]
redis:
container_name: dmoj_redis
#container_name: dmoj_redis
image: redis:alpine
restart: always
networks: [site]
texoid:
build:
context: .
dockerfile: ./texoid/Dockerfile
image: ninjaclasher/dmoj-texoid
image: moj/dmoj-texoid
init: true
restart: unless-stopped
networks: [site]
pdfoid:
build:
context: .
dockerfile: ./pdfoid/Dockerfile
image: ninjaclasher/dmoj-pdfoid
image: moj/dmoj-pdfoid
init: true
restart: unless-stopped
networks: [site]
Expand All @@ -35,23 +35,23 @@ services:
build:
context: .
dockerfile: ./mathoid/Dockerfile
image: ninjaclasher/dmoj-mathoid
image: moj/dmoj-mathoid
init: true
restart: unless-stopped
volumes:
- ./mathoid/config.yaml:/node_modules/mathoid/config.yaml
- ./mathoid/config.yaml:/app/node_modules/mathoid/config.yaml
networks: [site]
base:
build:
context: .
dockerfile: ./base/Dockerfile
image: ninjaclasher/dmoj-base
image: moj/dmoj-base
network_mode: none
site:
build:
context: .
dockerfile: ./site/Dockerfile
image: ninjaclasher/dmoj-site
image: moj/dmoj-site
init: true
restart: unless-stopped
volumes:
Expand All @@ -70,7 +70,7 @@ services:
build:
context: .
dockerfile: ./celery/Dockerfile
image: ninjaclasher/dmoj-celery
image: moj/dmoj-celery
init: true
restart: unless-stopped
volumes:
Expand All @@ -85,7 +85,7 @@ services:
build:
context: .
dockerfile: ./bridged/Dockerfile
image: ninjaclasher/dmoj-bridged
image: moj/dmoj-bridged
init: true
restart: unless-stopped
volumes:
Expand All @@ -102,7 +102,7 @@ services:
build:
context: .
dockerfile: ./wsevent/Dockerfile
image: ninjaclasher/dmoj-wsevent
image: moj/dmoj-wsevent
init: true
restart: unless-stopped
volumes:
Expand All @@ -111,20 +111,34 @@ services:
env_file: [environment/mysql.env, environment/site.env]
networks: [site, nginx]
nginx:
container_name: dmoj_nginx
#container_name: dmoj_nginx
image: nginx:alpine
restart: always
ports:
- 80:80
- 443:443
volumes:
- assets:/assets/
- pdfcache:/pdfcache/
- datacache:/datacache/
- cache:/cache/
- ./media/:/media/
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks: [nginx]
- /etc/letsencrypt/:/etc/letsencrypt:ro
- ./nginx/mokla-site/:/var/www/mokla-site/
networks: [site,nginx]
depends_on: [site, wsevent]
headscale:
image: headscale/headscale:stable
container_name: headscale
restart: unless-stopped
volumes:
- ./headscale/volume:/var/lib/headscale
- ./headscale/config.yaml:/etc/headscale/config.yaml
ports:
- 8080:8080
- 9090:9090
command: ["serve"]
networks: [nginx]
networks:
site:
db:
Expand Down
2 changes: 1 addition & 1 deletion dmoj/environment/mysql-admin.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MYSQL_ROOT_PASSWORD=<password>
MYSQL_ROOT_PASSWORD=NervouseNational#4
3 changes: 2 additions & 1 deletion dmoj/environment/mysql.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#:TBD Covnert to prod
MYSQL_DATABASE=dmoj
MYSQL_USER=dmoj
MYSQL_PASSWORD=<password>
MYSQL_PASSWORD=NervousNewton#4
5 changes: 3 additions & 2 deletions dmoj/environment/site.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
HOST=<host>
#;TBD verify lcoalhost for dev/test , shoudnt be in prod
HOST=code.mokla.org
DEBUG=0
SECRET_KEY=<secret key>
SECRET_KEY=ThisIsTheAttemptFor20260520OnGardenCelledVMToDeployAWorkingSolutionForCodeMappingtoDockerDB
35 changes: 35 additions & 0 deletions dmoj/fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
The site was down after unexpected machine shutdown by azure.
the troubleshooting surfaced following issues
- bridged sites was not able to connect to db
- the db user was getting access denied
- required resetting user password and grant of permissions
- nginx was unable to access site
- the docker compose networking needed netwrosk entry site for nginx
- the site was not accessible
- ngnix host was auto-running after reboot of vm
- required disabling host nginx
- ngnix docekr was being sticky
- required ```sudo killall nginx```
- the certs were expired
renewed certs with ```sudo certbot renew```


here are some of the commands

docker compose exec -it db healthcheck.sh --connect
docker compose exec -it db bash
healthcheck.sh --connect
mariadb-admin ping -u root -p"NervouseNational#4"
mariadb -u root -p"NervouseNational#4" -e "SELECT 1;"

ALTER USER 'dmoj'@'%' IDENTIFIED BY 'NervousNewton#4'
ALTER USER 'dmoj'@'localhost' IDENTIFIED BY 'NervousNewton#4';


--------
sudo systemctl status nginx
docker compose up -d --force-recreate nginx
sudo killall nginx

sudo certbot renew
docker compose exec nginx nginx -s reload
21 changes: 16 additions & 5 deletions dmoj/mathoid/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
FROM node:10.21.0
FROM node:18

RUN npm install mathoid && \
ln -sfv /node_modules/mathoid/app.js /node_modules/app.js
# Create app directory
WORKDIR /app

# Initialize a minimal package.json (avoids npm bug)
RUN npm init -y

# Install mathoid locally
RUN npm install mathoid

# Link entry point
RUN ln -sfv /app/node_modules/mathoid/app.js /app/app.js

EXPOSE 10044
WORKDIR /node_modules/mathoid
CMD /node_modules/mathoid/server.js

WORKDIR /app/node_modules/mathoid

CMD ["node", "server.js"]
64 changes: 61 additions & 3 deletions dmoj/nginx/conf.d/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
server {
listen 80;
listen [::]:80;
server_name dmoj.ca;
listen 80;
server_name mokla.org;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name mokla.org; # or localhost

ssl_certificate /etc/letsencrypt/live/mokla.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mokla.org/privkey.pem;

# Standard SSL settings (managed by Certbot)
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

client_max_body_size 48M;

add_header X-UA-Compatible "IE=Edge,chrome=1";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

root /var/www/mokla-site; # Path to your folder
index mokla.html;

location / {
try_files $uri $uri/ =404;
}
}

server {
listen 80;
server_name code.mokla.org;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
#listen [::]:80;
server_name code.mokla.org;

ssl_certificate /etc/letsencrypt/live/code.mokla.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/code.mokla.org/privkey.pem;

# Standard SSL settings (managed by Certbot)
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

client_max_body_size 48M;

add_header X-UA-Compatible "IE=Edge,chrome=1";
Expand Down
1 change: 1 addition & 0 deletions dmoj/nginx/mokla-site
Submodule mokla-site added at 442cc6
15 changes: 8 additions & 7 deletions local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
'HOST': os.environ.get('MYSQL_HOST', 'db'),
'OPTIONS': {
'charset': 'utf8mb4',
'sql_mode': 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION',
},
}
}
Expand All @@ -54,8 +53,8 @@

# Internationalization.
# Documentation: <https://docs.djangoproject.com/en/1.11/topics/i18n/>
LANGUAGE_CODE = 'en-ca'
DEFAULT_USER_TIME_ZONE = 'America/Toronto'
LANGUAGE_CODE = 'en-us'
DEFAULT_USER_TIME_ZONE = 'America/Los_Angeles'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Expand Down Expand Up @@ -108,7 +107,7 @@
ADMINS = ()

# The sender for the aforementioned emails.
SERVER_EMAIL = 'DMOJ: Modern Online Judge <errors@dmoj.ca>'
SERVER_EMAIL = 'Mokla Online Judge<moklaeducation@gmail.com>'


##################################################
Expand All @@ -133,9 +132,9 @@
############################################

## DMOJ site display settings.
SITE_NAME = 'DMOJ'
SITE_LONG_NAME = 'DMOJ: Modern Online Judge'
SITE_ADMIN_EMAIL = 'admin@example.com'
SITE_NAME = 'MOJ'
SITE_LONG_NAME = 'Mokla Online Judge'
SITE_ADMIN_EMAIL = 'moklaeducation@gmail.com'
TERMS_OF_SERVICE_URL = None

## Bridge controls.
Expand Down Expand Up @@ -304,3 +303,5 @@

MEDIA_ROOT = '/media/'
MEDIA_URL = '/media/'

SILENCED_SYSTEM_CHECKS = ["models.W036"]