diff --git a/.gitignore b/.gitignore index 20a4137..ebd4704 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ coverage.xml # Rope .ropeproject .idea/ +.vscode/ # Django stuff: *.log *.pot diff --git a/build/Dockerfile b/build/Dockerfile index 91cbe45..693610c 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,16 +1,23 @@ FROM ubuntu:16.04 ENV DEBIAN_FRONTEND noninteractive -RUN apt-get update -RUN apt-get -y install software-properties-common python-software-properties python python-dev gcc g++ git libtool python-pip libseccomp-dev cmake -RUN add-apt-repository ppa:openjdk-r/ppa -RUN apt-get update -RUN apt-get install -y openjdk-7-jdk -RUN cd /tmp && git clone https://github.com/QingdaoU/Judger && cd Judger && git checkout newnew && mkdir build && cd build && cmake .. && make && make install && cd ../bindings/Python && python setup.py install -RUN mkdir -p /judger_run /test_case /log /code + COPY java_policy /etc -RUN pip install futures psutil gunicorn web.py requests -RUN useradd -r compiler + +RUN buildDeps='software-properties-common git libtool cmake python-dev python-pip libseccomp-dev' && \ + apt-get update && apt-get install -y python python-pkg-resources gcc g++ $buildDeps && \ + add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-7-jdk && \ + pip install --no-cache-dir futures psutil gunicorn web.py 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 && python setup.py install && \ + apt-get purge -y --auto-remove $buildDeps && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /judger_run /test_case /log /code && \ + useradd -r compiler + HEALTHCHECK --interval=5s --retries=3 CMD python /code/service.py WORKDIR /code + +VOLUME ["/code"] EXPOSE 8080 -CMD /bin/bash /code/run.sh \ No newline at end of file +CMD /bin/bash /code/run.sh diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 7f135a1..bef20cd 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -1,7 +1,7 @@ version: "2" services: judge_server: - image: registry.cn-hangzhou.aliyuncs.com/v-image/judge_server + image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server read_only: true cap_drop: - SETPCAP @@ -15,12 +15,12 @@ services: - /judger_run:exec,mode=777 - /spj:exec,mode=777 volumes: - - $PWD/tests/test_case:/test_case + - $PWD/tests/test_case:/test_case:ro - /data/log:/log - $PWD/server:/code:ro environment: - - service_discovery_url=https://virusdefender.net/service.php - - service_url=http://1.2.3.4:12358 - - token=YOUR_TOKEN_HERE + - service_discovery_url=http://127.0.0.1:8000/api/judge_server_heartbeat + - service_url=http://127.0.0.1:12358 + - TOKEN=YOUR_TOKEN_HERE ports: - "0.0.0.0:12358:8080" diff --git a/server/judge_client.py b/server/judge_client.py index 2e05aa2..aaa4bb5 100644 --- a/server/judge_client.py +++ b/server/judge_client.py @@ -61,7 +61,7 @@ class JudgeClient(object): with open(user_output_file, "r") as f: content = f.read() output_md5 = hashlib.md5(content.rstrip()).hexdigest() - result = output_md5 == self._get_test_case_file_info(test_case_file_id)["striped_output_md5"] + result = output_md5 == self._get_test_case_file_info(test_case_file_id)["stripped_output_md5"] return output_md5, result def _spj(self, in_file_path, user_out_file_path): diff --git a/server/run.sh b/server/run.sh index 8d8d7e2..4802a1e 100644 --- a/server/run.sh +++ b/server/run.sh @@ -4,5 +4,4 @@ echo 0 > /tmp/counter core=$(grep --count ^processor /proc/cpuinfo) n=$(($core*2)) chmod 400 /tmp/counter -chmod -R 400 /test_case -gunicorn --workers $n --threads $n --error-logfile /log/gunicorn.log --time 600 --bind 0.0.0.0:8080 server:wsgiapp +exec gunicorn --workers $n --threads $n --error-logfile /log/gunicorn.log --time 600 --bind 0.0.0.0:8080 server:wsgiapp diff --git a/server/utils.py b/server/utils.py index bb89f2b..ded9977 100644 --- a/server/utils.py +++ b/server/utils.py @@ -28,11 +28,11 @@ def server_info(): def get_token(): - token = os.environ.get("token") + token = os.environ.get("TOKEN") if token: return token else: - raise JudgeClientError("ENV token not found") + raise JudgeClientError("ENV TOKEN not found") token = hashlib.sha256(get_token()).hexdigest() diff --git a/tests/test_case/normal/info b/tests/test_case/normal/info index 3a604a7..70c3564 100755 --- a/tests/test_case/normal/info +++ b/tests/test_case/normal/info @@ -1 +1 @@ -{"test_case_number": 1, "spj": false, "test_cases": {"1": {"striped_output_md5": "eccbc87e4b5ce2fe28308fd9f2a7baf3", "output_size": 2, "output_md5": "6d7fce9fee471194aa8b5b6e47267f03", "input_name": "1.in", "input_size": 4, "output_name": "1.out"}}} +{"test_case_number": 1, "spj": false, "test_cases": {"1": {"stripped_output_md5": "eccbc87e4b5ce2fe28308fd9f2a7baf3", "output_size": 2, "output_md5": "6d7fce9fee471194aa8b5b6e47267f03", "input_name": "1.in", "input_size": 4, "output_name": "1.out"}}}