Try   HackMD

YTP 2022 CMS 升級文件

2022 YTP 比賽導入了 TPS 系統,今年是透過一台額外的機器負責管理題目上傳,以下是把 TPS 安裝入 YTP CMS 系統的方法:

CMS

要讓 CMS 支援 TPS 需要在 /cms/cmscontrib/loaders 中加入 TPS 的引用程式。這個部份我們 merge 了去年的 CMS source,保留了原本的功能同時加入了 TPS。

今年的 TPS 有一個問題是 subtask 順序不符合 subtasks.json 設定,這個問題也在我們的 repo 修正完成。

Docker

我們的改動和原本的 YTP CMS 系統架構相容,所以只需要使用新的 docker image 。

Dockerfile

修改 repo 位置

RUN git clone --recurse-submodules https://github.com/YTPxAPCSCamp/cms.git

完整板

FROM ubuntu:18.04

#Install tzdata first due to error occured when installing it with other packages.
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
tzdata \
&& rm -rf /var/lib/apt/lists/*

#Set timezone used in the container
ENV TZ=Asia/Taipei
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

#Install required packages
#Uncomment or comment out some lines to meet languages you're using. (Currently only c/cpp and java are installeded)
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install --no-install-recommends -y \
build-essential \
cgroup-lite \
cppreference-doc-en-html \
curl \
file \
g++ \
gcc \
gettext \
git \
iso-codes \
libcap-dev \
libcups2-dev \
libffi-dev \
libpq-dev \
openjdk-8-jdk-headless \
postgresql \
postgresql-client \
### python 2.7 (for cms) \
python \
python-dev \
python-pip \
python-setuptools \
python-wheel \
shared-mime-info \
vim \
wget \
zip \
#fp-compiler \
#haskell-platform  \
#mono-mcs \
#php7.2-cli  \
#php7.2-fpm \
#phppgadmin  \
#rustc \
&& rm -rf /var/lib/apt/lists/*


#Install newer version of python
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
apt-get install -y python3.10 \
&& rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/python3 python /usr/bin/python3.10 1

#Set up locale used in the container
RUN locale-gen en_US.UTF-8
ENV LANG en_US.utf-8

#Download CMS source. You can change version here. This system was designed to be used with CMS v1.4.
# RUN wget -qO- https://github.com/cms-dev/cms/releases/download/v1.4.rc1/v1.4.rc1.tar.gz | tar xvz -C /
RUN git clone --recurse-submodules https://github.com/YTPxAPCSCamp/cms.git

WORKDIR /cms/

#Install CMS and its python dependencies.
RUN python prerequisites.py -y --as-root install && \
usermod -a -G cmsuser root && \
python -m pip install --no-cache-dir -r requirements.txt && \
python setup.py install

重新編譯 docker image

docker build --no-cache -t cms-docker .

使用新的 docker image

將 deploy-apply.yml 的所有 image 欄位從 brianbbsu/cms:YTP2020 改成 cms-docker

重新執行 docker containers

方法跟之前一樣

setup_env deploy-apply <id>
docker-compose up -d

使用方式

TPS 的使用方式可以參考 https://drive.google.com/file/d/1_2uCbHwx0WYG4g4eAVn0BUB2cKfLpJQm/view?usp=sharing 資料夾中的 README.md 資料夾中包含 tps 的範例結構。

cmsImportTask

匯入題目的方法是在機器上放入題目資料夾,假設 path 是 PROBLEM。
這邊假設 cms.conf 放在 CMS_CONF_PATH

cd PROBLEM
tps gen # compile problem
docker run -i -t --rm -v "$(pwd):/problem" -v "CMS_CONF_PATH:/usr/local/etc/cms.conf:ro" --network=host cms-docker /usr/local/bin/cmsImportTask -S -L tps_task /problem --update

YTP 2022 系統經驗紀錄

以下是一些我在 2022 YTP 的幾次比賽中獲得的經驗整理分享:

  • checker 的題目要多檢查:
    • 如果有使用 testlib.h 要避免不正當的 _fail (會回傳 judge_error)
    • 避免把使用者輸入輸出回 cms (有機會 Evaluating 原因是 Decode Error)
    • 避免 checker 本身超過 wall time limit (解法是在設計題目的時候注意範圍 緊急的時候可以調整 cms.conf trusted_sandbox_max_time_s)
  • 題目可以建立 git repo 方便管理每個題目的更新狀況