## Guide này assume bạn đã cài và chạy bkdnOJ.v2 theo repo `deploy` - https://github.com/bkdnOJv2/deploy/tree/main-2.0 ## Thiết lập Máy chấm (theo PyPI) Tại bước này chúng ta sẽ thử setup một server chấm theo cách cấu hình thủ công. Các bước sau thực hiện tại máy chấm. ### Update danh sách package ```bash= sudo apt-get update ``` ### Cài đặt thư viện và máy chấm * Cài `pip3` nếu chưa có. * Thư viện ```bash= mkdir ~/judge cd ~/judge python3 -m venv venv source venv/bin/activate sudo apt install python3-dev python3-pip build-essential libseccomp-dev -y sudo apt-get install gcc libpq-dev -y sudo apt-get install python-dev python-pip -y sudo apt-get install python3-dev python3-pip python3-venv python3-wheel -y pip3 install wheel ``` * Cài đặt máy chấm DMOJ ```bash= git clone --recursive https://github.com/DMOJ/judge-server.git . pip3 install -e . ``` ### Cấu hình máy chấm Tạo một file có tên là `~/judge/judge.yml` và ghi những thông tin sau vào file: ``` id: '<judge name>' key: '<judge authentication key>' problem_storage_globs: - <đường dẫn đến thư mục `problem_data` ở backend có thêm ** ở cuối> ``` Tại đây: * **id**: Judge Name, Tên của Máy chấm, đặt trong cặp dấu nháy, thiết lập trên Admin * **key**: Judge Auth Key, Khóa xác thực của Máy chấm đặt trong cặp dấu nháy, thiết lập trên Admin ![](https://i.imgur.com/piwfVVZ.png) * **problem_storage_globs**: Đây là đường dẫn đến nơi chưa dữ liệu problem. * Nếu hệ thống của bạn chứa problem data ở `/home/problems` thì ta sẽ để giá trị như sau: ``` problem_storage_globs: - /home/problems/** ``` Quay lại terminal, vẫn ở `~/judge` trên máy chấm, chạy lệnh: ```bash dmoj-autoconf ``` Câu lệnh này sẽ phát hiện những Ngôn ngữ lập trình đã có sẵn trên máy chấm (thông qua biến `PATH`) và in ra. Ví dụ, khi chạy lệnh bạn sẽ có output tương tự như sau: ```bash ubuntu@judge-server:~$ dmoj-autoconf ... Auto-configuring C: Using /usr/bin/gcc (native target) Auto-configuring C11: Using /usr/bin/gcc (native target) ... Auto-configuring CPP11: Using /usr/bin/g++ (native target) Auto-configuring CPP14: Using /usr/bin/g++ (native target) Auto-configuring CPP17: Using /usr/bin/g++ (native target) ... Auto-configuring JAVA11: Could not find JVM Auto-configuring JAVA8: Could not find JVM ... Auto-configuring PAS: Failed to find "fpc" Auto-configuring PY2: Failed to find "python" Auto-configuring PY3: Using /usr/bin/python3 Auto-configuring PYPY: Failed to find "pypy" Auto-configuring PYPY3: Failed to find "pypy3" ... Configuration result: runtime: as_x64: /usr/bin/x86_64-linux-gnu-as as_x86: /usr/bin/as awk: /usr/bin/mawk cat: /usr/bin/cat g++: /usr/bin/g++ g++11: /usr/bin/g++ g++14: /usr/bin/g++ g++17: /usr/bin/g++ gcc: /usr/bin/gcc gcc11: /usr/bin/gcc ld_x64: /usr/bin/x86_64-linux-gnu-ld ld_x86: /usr/bin/ld perl: /usr/bin/perl python3: /usr/bin/python3 sed: /usr/bin/sed ``` Như ví dụ trên thì máy chấm sẽ không có ngôn ngữ Java và Pascal. Cái chúng ta quan tâm là khối text "`runtime`". Chúng ta sẽ copy nó và append vào cuối cùng của file `judge.yml` vừa tạo. Vậy, để máy chấm hỗ trợ thêm ngôn ngữ, ta chỉ cần cài bộ biên dịch/thông dịch cho ngôn ngữ đó. VD với java 8 ta cài như sau: ``` sudo apt-get update sudo apt-get install openjdk-8-jdk java -version ``` và chạy lại `dmoj-autoconf` để lấy khối text "`runtime`" mới. ### Một ví dụ `judge.yml` Giả sử trường hợp sau: * Máy chấm của bạn là local, nơi chứa dữ liệu problem data là `/home/backend/media/problem_data`. * Trên web admin, tồn tại một máy chấm có tên là `judge1`, key là `judge1keysecret`, đang offline và không bị block. * Chạy `dmoj-autoconf` cho output giống như trên. Vậy, file `judge.yml` của chúng ta sẽ trông như sau: ``` id: 'judge1' key: 'judge1keysecret' problem_storage_globs: - /home/backend/media/problem_data/** runtime: as_x64: /usr/bin/x86_64-linux-gnu-as as_x86: /usr/bin/as awk: /usr/bin/mawk cat: /usr/bin/cat g++: /usr/bin/g++ g++11: /usr/bin/g++ g++14: /usr/bin/g++ g++17: /usr/bin/g++ gcc: /usr/bin/gcc gcc11: /usr/bin/gcc ld_x64: /usr/bin/x86_64-linux-gnu-ld ld_x86: /usr/bin/ld perl: /usr/bin/perl python3: /usr/bin/python3 sed: /usr/bin/sed ``` ## Kết nối máy chấm * Sau khi thiết lập xong, giả sử máy chấm ta đang local với backend, tại folder `~/judge`, ta kết nối bằng lệnh: ```bash dmoj -c judge.yml -p 9999 127.0.0.1 ``` * Với: * `9999` là cổng DEFAULT của `BRIDGED_JUDGE_ADDRESS`