add golang

This commit is contained in:
yang.li 2020-07-08 01:30:49 +00:00
parent e81fc56481
commit 641a535af3
4 changed files with 44 additions and 10 deletions

View File

@ -1,10 +1,10 @@
FROM registry.docker-cn.com/library/ubuntu:16.04
FROM ubuntu:18.04
COPY build/java_policy /etc
# add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk && \
RUN buildDeps='software-properties-common git libtool cmake python-dev python3-pip python-pip libseccomp-dev' && \
apt-get update && apt-get install -y python python3.5 python-pkg-resources python3-pkg-resources gcc g++ $buildDeps && \
add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk && \
add-apt-repository ppa:openjdk-r/ppa && add-apt-repository ppa:longsleep/golang-backports && apt-get update && apt-get install -y golang-go openjdk-8-jdk && \
pip3 install --no-cache-dir psutil gunicorn flask requests && \
cd /tmp && git clone -b newnew --depth 1 https://github.com/QingdaoU/Judger && cd Judger && \
mkdir build && cd build && cmake .. && make && make install && cd ../bindings/Python && python3 setup.py install && \
@ -12,7 +12,6 @@ RUN buildDeps='software-properties-common git libtool cmake python-dev python3-p
apt-get clean && rm -rf /var/lib/apt/lists/* && \
mkdir -p /code && \
useradd -u 12001 compiler && useradd -u 12002 code && useradd -u 12003 spj && usermod -a -G code spj
HEALTHCHECK --interval=5s --retries=3 CMD python3 /code/service.py
ADD server /code
WORKDIR /code

View File

@ -4,7 +4,7 @@ import json
import requests
from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, \
c_lang_spj_compile, py2_lang_config, py3_lang_config
c_lang_spj_compile, py2_lang_config, py3_lang_config, go_lang_config
class JudgeServerClientError(Exception):
@ -107,6 +107,15 @@ print int(s1[0]) + int(s1[1])"""
s1 = s.split(" ")
print(int(s1[0]) + int(s1[1]))"""
go_src = """package main
import "fmt"
func main() {
int a, b;
fmt.Scanf("%d %d", &a, &b);
fmt.Print("%d", a + b)
}"""
client = JudgeServerClient(token=token, server_base_url="http://127.0.0.1:12358")
print("ping")
print(client.ping(), "\n\n")
@ -141,12 +150,17 @@ print(int(s1[0]) + int(s1[1]))"""
print("py2_judge")
print(client.judge(src=py2_src, language_config=py2_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal"), "\n\n")
test_case_id="normal", output=True), "\n\n")
print("py3_judge")
print(client.judge(src=py3_src, language_config=py3_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal"), "\n\n")
test_case_id="normal", output=True), "\n\n")
print("go_judge")
print(client.judge(src=go_src, language_config=go_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal", output=True), "\n\n")
print("c_dynamic_input_judge")
print(client.judge(src=c_src, language_config=c_lang_config,

View File

@ -89,7 +89,7 @@ py2_lang_config = {
py3_lang_config = {
"compile": {
"src_name": "solution.py",
"exe_name": "__pycache__/solution.cpython-35.pyc",
"exe_name": "__pycache__/solution.cpython-36.pyc",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_memory": 128 * 1024 * 1024,
@ -101,3 +101,22 @@ py3_lang_config = {
"env": ["PYTHONIOENCODING=UTF-8"] + default_env
}
}
go_lang_config = {
"compile": {
"src_name": "main.go",
"exe_name": "main",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/go build -o {exe_path} {src_path}",
"env": ["GOCACHE=/tmp"]
},
"run": {
"command": "{exe_path}",
"seccomp_rule": "",
# 降低内存占用
"env": ["GODEBUG=madvdontneed=1", "GOCACHE=off"] + default_env,
"memory_limit_check_only": 1
}
}

View File

@ -15,11 +15,13 @@ class Compiler(object):
_command = command.split(" ")
os.chdir(output_dir)
env = compile_config.get("env", [])
env.append("PATH=" + os.getenv("PATH"))
result = _judger.run(max_cpu_time=compile_config["max_cpu_time"],
max_real_time=compile_config["max_real_time"],
max_memory=compile_config["max_memory"],
max_stack=128 * 1024 * 1024,
max_output_size=1024 * 1024,
max_output_size=20 * 1024 * 1024,
max_process_number=_judger.UNLIMITED,
exe_path=_command[0],
# /dev/null is best, but in some system, this will call ioctl system call
@ -27,7 +29,7 @@ class Compiler(object):
output_path=compiler_out,
error_path=compiler_out,
args=_command[1::],
env=["PATH=" + os.getenv("PATH")],
env=env,
log_path=COMPILER_LOG_PATH,
seccomp_rule_name=None,
uid=COMPILER_USER_UID,