Docker 搭建 Hydro-OJ 系统

发布于 22 天前  46 次阅读


Hydro简介

  • Hydro是目前来看比较新的一款开源Online Judge系统
  • 目前官网有常见的安装方式,但是Docker的支持不是很好,于是我自己在官网架构基础上,重新编写了一下容器部署。
  • 项目地址:Hydro-Docker
imagepng

使用方式

  • 直接使用docker-compose运行容器,在本地构建镜像
git clone https://github.com/xiabee/Hydro-Docker
cd Hydro-Docker
docker-compose up -d

没有报错就是成功(x):

docker-compose ps 

imagepng

聊聊编写过程

  • 准确的说所有模块的测试完全靠自己,全网没有找到相关的报错,可能是因为官方并不打算提供容器安装的技术支持......
  • 于是有了以下内容(都是我遇到的bug,大家构建过程中可以参考一下)

构建速度较慢

  • 问题描述:如题
  • 解决方案:这个直接给Dockerfile换源就好,找一个合适的源,比如清华源:
RUN sed -i "s/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list && \
sed -i "s/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list && \
apt-get update && apt-get install -y --no-install-recommends && apt upgrade -y
  • 同时给宿主机配置容器加速器,这里以阿里云、Ubuntu为例:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ee1z0bm0.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart

测评机不响应

  • 问题描述:各个容器运行正常,但是测评机一直处于不工作状态,即提交代码无法测评

Error: Request failed with status code 404

docker-compose logs | grep judge 查看测评机容器日志,发现以下内容:

oj-judge    | Unhandled Rejection at: Promise  Promise {
oj-judge    |   <rejected> Error: Request failed with status code 404
oj-judge    |       at createError (/usr/local/share/.config/yarn/global/node_modules/axios/lib/core/createError.js:16:15)
oj-judge    |       at settle (/usr/local/share/.config/yarn/global/node_modules/axios/lib/core/settle.js:17:12)
oj-judge    |       at IncomingMessage.handleStreamEnd (/usr/local/share/.config/yarn/global/node_modules/axios/lib/adapters/http.js:322:11)
oj-judge    |       at IncomingMessage.emit (events.js:412:35)
oj-judge    |       at endReadableNT (internal/streams/readable.js:1334:12)
oj-judge    |       at processTicksAndRejections (internal/process/task_queues.js:82:21) {
oj-judge    |     config: {
oj-judge    |       transitional: [Object],
oj-judge    |       adapter: [Function: httpAdapter],
oj-judge    |       transformRequest: [Array],
oj-judge    |       transformResponse: [Array],
oj-judge    |       timeout: 30000,
oj-judge    |       xsrfCookieName: 'XSRF-TOKEN',
oj-judge    |       xsrfHeaderName: 'X-XSRF-TOKEN',
oj-judge    |       maxContentLength: -1,
oj-judge    |       maxBodyLength: -1,
oj-judge    |       validateStatus: [Function: validateStatus],
oj-judge    |       headers: [Object],
oj-judge    |       baseURL: 'http://oj-backend:8888/',
oj-judge    |       method: 'post',
oj-judge    |       url: 'login',
oj-judge    |       data: '{"uname":"root","password":"rootroot","rememberme":"on"}'
oj-judge    |     },

注意此时报错:oj-judge在不断请求http://oj-backend:8888/,但是返回值一直是404,然而观察到oj-backend并没有暴露8888端口......发现问题所在!

  • 解决方案:在docker-compose中暴露oj-backend的服务端口:
# main site
  oj-backend:
    build: ./backend
    container_name: oj-backend
    ...
    expose:
      - 8888

server User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]

docker-compose logs | grep backend查看后端容器日志,发现以下内容:

oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]
oj-backend  | [E]  server  User: 0(Guest) get: /judge/files You don't have the required privilege. [ 512 ]

此时推断,测评机在抓取后端请求,但是后端并没有权限写入测评机

结合上面测评机容器请求内容:

oj-judge    |       url: 'login',
oj-judge    |       data: '{"uname":"root","password":"rootroot","rememberme":"on"}'

推测测评机设置的账号密码与后端不匹配

  • 解决方案:修改./data/judge/judge.yamlunamepassword修改为对应管理员账号的用户名和密码:
hosts:
  localhost:
    type: hydro
    server_url: http://oj-backend:8888/
    uname: root
    password: rootroot
    detail: true
  • 然后重启容器就可以正常测评了:docker-compose restart
image.png

其他问题

  • 暂时不记得了,想起来了来写