GoJudge环境部署本地部署云服务器部署go-judge判题机详细部署教程go-judge多种判题语言样例请求输入输出(C++、C语言、Java、Python3、Python2)

go-judge判题机详细部署教程

前言

本文基于go-judge项目搭建,由于go-judge官网项目https://github.com/criyle/go-judge,资料太少,而且只给了C++语言的调用样例,无法知道其他常见语言比如:Python、Java等;同时go-judge也没有给出鉴权方式如何设置与调用,内部原理是啥? 因此本文结合自己搭建OJ系统的实践经验,耗时一周,总结了这篇文章,你可以按照文章步骤快速搭建一个基于go-judge完善的判题系统,支持C++、C语言、Java、Python3、Python2。

本文同时借鉴参考了HOJ、QDUOJ等其他开源OJ。

注意,文章中如若涉及楼主公网IP或者其他私有信息,请务必保密!

阅读本文你将了解:

(1)如何使用云服务器单独部署go-judge,不使用docker;

(2)使用docker如何部署go-judge服务;

(3)go-judge官方各项目介绍,中文文档补充;

(4)go-judge请求接口举例,以C++、C语言、Java、Python3、Python2为例,如需其他环境也可自行根据样例探索;

(5)go-judge启动参数如何设置,如何调整限制内存、CPU等参数;

(6)流程基于Linux宝塔面板搭建,你不需要对linux特别了解。

(7)常见问题处理:sudo apt-get update apt install执行慢的解决方法、GoJudge官网源码压缩包无法下载,Chrome浏览器等均提示有病毒,或者无法解压;Docker内安装语言包等问题处理;

(8)多机部署建议;

(9)教你如何基于Docker构建多语言支持的镜像,文章给了dockerfile文件,你可以基于他构建自己的镜像,本文支持C++、C语言、Java、Python3、Python2语言。HOJ的Dockerfile过于复杂,本文进行了精简。

全文目录:

1 官网
2 部署流程
2.1 服务器部署
2.2 Docker部署(推荐)
2.3 构建全新镜像
2.4 隐患
2.5 构建镜像和容器命令
3 启动参数设置
3.1 所有参数
3.2 常用参数设置
4 请求接口
4.1 全部接口
4.2 Run接口举例
5 请求参数样例
5.1 C语言
5.2 C++
5.3 Java
5.4 Python3
5.5 Python2
6 常见问题解决
6.1 sudo apt-get update apt install执行慢的解决方法,更换镜像源
6.2 apt install g++报Unable to locate package
6.3 CentOS7系统需要开启User命名空间才能使用Docker部署沙箱
6.4 GoJudge官网源码压缩包无法下载,Chrome浏览器等均提示有病毒,或者无法解压
6.5 Git Clone时报错
6.6 Docker内安装语言包
7 附录
7.1 HOJ language.yml配置

一、官网

go-judge官网:https://github.com/criyle/go-judge

官方中文文档:https://github.com/criyle/go-judge/blob/master/README.cn.md

go-sandbox 官网 https://github.com/criyle/go-sandbox

go-judge是由REST / gRPC API实现的go-sandbox,底层是go-sandbox
部署go-judge有两种方式:
(1)直接服务器部署,用官网给的可执行文件;
(2)Docker部署,用官网给的命令,会基于官网镜像生成docker容器。
以上两种方式都不需要额外安装go环境,但判题环境比如c++,python等需要安装。

官网也给出了使用go-judge的例子:https://github.com/criyle/go-judger-demo
在该例子中,可基于Dockerfile.exec,构建自己的镜像,下文将给出了如何构建一个go-judge镜像。

注意:相关的源码文件已本地备份!

文章耗时3天精心整理。

隐藏内容

此内容需要购买查看

  • 普通用户39 U币

少一点点挥霍,多很多很多知识

7、附录

7.1 HOJ language.yml配置


language: C
src_path: main.c
exe_path: main
compile:
env: default
command: /usr/bin/gcc -DONLINE_JUDGE -w -fmax-errors=1 -std=c11 {src_path} -lm -o {exe_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 256mb
run:
env: default
command: /w/{exe_path}


language: C With O2
src_path: main.c
exe_path: main
compile:
env: default
command: /usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=1 -std=c11 {src_path} -lm -o {exe_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 256mb
run:
env: default
command: /w/{exe_path}


language: C++
src_path: main.cpp
exe_path: main
compile:
command: /usr/bin/g++ -DONLINE_JUDGE -w -fmax-errors=1 -std=c++14 {src_path} -lm -o {exe_path}
env: default
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}


language: C++ With O2
src_path: main.cpp
exe_path: main
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=1 -std=c++14 {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}


language: C++ 17
src_path: main.cpp
exe_path: main
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -w -fmax-errors=1 -std=c++17 {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}


language: C++ 17 With O2
src_path: main.cpp
exe_path: main
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=1 -std=c++17 {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}


language: C++ 20
src_path: main.cpp
exe_path: main
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -w -fmax-errors=1 -std=c++2a {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}


language: C++ 20 With O2
src_path: main.cpp
exe_path: main
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=1 -std=c++2a {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}


language: Java
src_path: Main.java
exe_path: Main.jar
compile:
env: default
command: /bin/bash -c “javac -encoding utf-8 {src_path} && jar -cvf {exe_path} *.class”
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /usr/bin/java -Dfile.encoding=UTF-8 -cp /w/{exe_path} Main


language: Python2
src_path: main.py
exe_path: main.pyc
compile:
env: default
command: /usr/bin/python2.7 -m py_compile /w/{src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 256mb
run:
env: default
command: /usr/bin/python2.7 /w/{exe_path}


language: Python3
src_path: main.py
exe_path: __pycache__/main.cpython-38.pyc
compile:
env: python3
command: /usr/bin/python3 -m py_compile /w/{src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 256mb
run:
env: python3
command: /usr/bin/python3 /w/{exe_path}


language: PyPy2
src_path: main.py
exe_path: __pycache__/main.pypy-73.pyc
compile:
env: default
command: /usr/bin/pypy -m py_compile /w/{src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 256mb
run:
env: default
command: /usr/bin/pypy /w/{exe_path}


language: PyPy3
src_path: main.py
exe_path: __pycache__/main.pypy39.pyc
compile:
env: python3
command: /usr/bin/pypy3 -m py_compile /w/{src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 256mb
run:
env: python3
command: /usr/bin/pypy3 /w/{exe_path}


language: Golang
src_path: main.go
exe_path: main
compile:
env: golang_compile
command: /usr/bin/go build -o {exe_path} {src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 512mb
run:
env: golang_run
command: /w/{exe_path}


language: C#
src_path: Main.cs
exe_path: main
compile:
env: default
command: /usr/bin/mcs -optimize+ -out:{exe_path} {src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 512mb
run:
env: default
command: /usr/bin/mono /w/{exe_path}


language: PHP
src_path: main.php
exe_path: main.php
run:
env: default
command: /usr/bin/php /w/{exe_path}


language: JavaScript Node
src_path: main.js
exe_path: main.js
run:
env: default
command: /usr/bin/node /w/{exe_path}


language: JavaScript V8
src_path: main.js
exe_path: main.js
run:
env: default
command: /usr/bin/jsv8/d8 /w/{exe_path}


language: Ruby
src_path: main.rb
exe_path: main.rb
run:
env: default
command: /usr/bin/ruby /w/{exe_path}


language: Rust
src_path: Main.cs
exe_path: main
compile:
env: default
command: /usr/bin/rustc -O -o {exe_path} {src_path}
maxCpuTime: 5s
maxRealTime: 10s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path}

# 以下为特殊评测或交互评测使用的语言

language: SPJ-C
src_path: spj.c
exe_path: spj
compile:
env: default
command: /usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c11 {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path} {std_input} {user_output} {std_output}


language: SPJ-C++
src_path: spj.cpp
exe_path: spj
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}
maxCpuTime: 15s
maxRealTime: 30s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path} {std_input} {user_output} {std_output}


language: INTERACTIVE-C
src_path: interactive.c
exe_path: interactive
compile:
env: default
command: /usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c11 {src_path} -lm -o {exe_path}
maxCpuTime: 10s
maxRealTime: 20s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path} {std_input} {user_output} {std_output}


language: INTERACTIVE-C++
src_path: interactive.cpp
exe_path: interactive
compile:
env: default
command: /usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}
maxCpuTime: 15s
maxRealTime: 30s
maxMemory: 512mb
run:
env: default
command: /w/{exe_path} {std_input} {user_output} {std_output}