fix project structure

This commit is contained in:
virusdefender 2016-10-27 18:38:04 +08:00
parent a58f7210f6
commit ff160cbbef
14 changed files with 30 additions and 29 deletions

1
.gitignore vendored
View File

@ -7,7 +7,6 @@ __pycache__/
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/

View File

@ -1,16 +1,16 @@
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN rm /etc/apt/sources.list
COPY deploy/sources.list /etc/apt/
COPY sources.list /etc/apt/
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 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 pip install psutil gunicorn web.py requests
RUN mkdir -p /judger_run /test_case /log /code
COPY deploy/java_policy /etc
COPY java_policy /etc
RUN pip install futures psutil gunicorn web.py
RUN useradd -r compiler
HEALTHCHECK --interval=5s --retries=3 CMD python /code/service.py
WORKDIR /code
EXPOSE 8080
CMD chown compiler:compiler /spj; echo 0 > /tmp/counter; gunicorn --workers 4 --threads 4 --error-logfile /log/gunicorn.log --bind 0.0.0.0:8080 server:wsgiapp
CMD /bin/bash /code/run.sh

View File

@ -18,7 +18,7 @@ services:
volumes:
- /data/JudgeServer/tests/test_case:/test_case:ro
- /data/log:/log
- /data/JudgeServer:/code:ro
- /data/JudgeServer/server:/code:ro
environment:
- judger_token=token
- service_discovery_url=https://virusdefender.net/service.php

View File

@ -3,7 +3,6 @@ from __future__ import unicode_literals
import json
import os
import time
import _judger

4
server/run.sh Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
chown compiler:compiler /spj
echo 0 > /tmp/counter
gunicorn --workers 4 --threads 4 --error-logfile /log/gunicorn.log --bind 0.0.0.0:8080 server:wsgiapp

View File

@ -13,7 +13,7 @@ from compiler import Compiler
from config import JUDGER_WORKSPACE_BASE, SPJ_SRC_DIR, SPJ_EXE_DIR, COUNTER_FILE_PATH
from exception import TokenVerificationFailed, CompileError, SPJCompileError,JudgeClientError
from judge_client import JudgeClient
from utils import server_info, get_token, logger, TaskCounter
from utils import server_info, logger, TaskCounter, token
DEBUG = os.environ.get("judger_debug") == "1"
@ -49,13 +49,6 @@ class JudgeServer(object):
data["action"] = "pong"
return data
@property
def _token(self):
t = get_token()
if not t:
raise TokenVerificationFailed("token not set")
return hashlib.sha256(t).hexdigest()
def judge(self, language_config, src, max_cpu_time, max_memory, test_case_id,
spj_version=None, spj_config=None, spj_compile_config=None, spj_src=None, output=False):
# init
@ -118,9 +111,9 @@ class JudgeServer(object):
return "success"
def POST(self):
token = web.ctx.env.get("HTTP_X_JUDGE_SERVER_TOKEN", None)
_token = web.ctx.env.get("HTTP_X_JUDGE_SERVER_TOKEN", None)
try:
if token != self._token:
if _token != token:
raise TokenVerificationFailed("invalid token")
if web.data():
try:
@ -164,9 +157,6 @@ urls = (
if DEBUG:
logger.info("DEBUG=ON")
# check token
JudgeServer()._token
app = web.application(urls, globals())
wsgiapp = app.wsgifunc()

View File

@ -6,7 +6,7 @@ import requests
import hashlib
from exception import JudgeServiceError
from utils import server_info, get_token, logger
from utils import server_info, logger, token
class JudgeService(object):
@ -29,7 +29,7 @@ class JudgeService(object):
def _request(self, data):
try:
r = requests.post(self.service_discovery_url, data=json.dumps(data),
headers={"X-JUDGE-SERVER-TOKEN": hashlib.sha256(get_token()).hexdigest(),
headers={"X-JUDGE-SERVER-TOKEN": token,
"Content-Type": "application/json"}, timeout=5).json()
except Exception as e:
logger.exception(e)

View File

@ -3,11 +3,21 @@ from __future__ import unicode_literals
import _judger
import psutil
import socket
import os
import logging
import fcntl
import hashlib
import os
from config import COUNTER_FILE_PATH
from exception import JudgeClientError
logger = logging.getLogger(__name__)
handler = logging.FileHandler("/log/judge_server.log")
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.WARNING)
class TaskCounter(object):
@ -48,12 +58,11 @@ def server_info():
def get_token():
return os.environ.get("OJ_WEB_SERVER_ENV_judger_token") or os.environ.get("judger_token")
token = os.environ.get("OJ_WEB_SERVER_ENV_judger_token") or os.environ.get("judger_token")
if not token:
raise JudgeClientError("judger_token not set")
return token
logger = logging.getLogger(__name__)
handler = logging.FileHandler("/log/judge_server.log")
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.WARNING)
token = hashlib.sha256(get_token()).hexdigest()