mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2024-12-28 21:31:43 +00:00
parent
de58bb33f2
commit
cbcc9cb313
@ -5,10 +5,9 @@ services:
|
||||
before_install:
|
||||
- sudo mkdir -p /data/log
|
||||
- pip install requests
|
||||
- echo "token" > token.txt
|
||||
script:
|
||||
- docker pull qduoj/judge_server
|
||||
- cp docker-compose.example.yml docker-compose.yml
|
||||
- docker-compose up -d
|
||||
- docker ps -a
|
||||
- python tests/tests.py
|
||||
- python tests/tests.py
|
||||
|
@ -18,9 +18,9 @@ services:
|
||||
- $PWD/tests/test_case:/test_case
|
||||
- /data/log:/log
|
||||
- $PWD/server:/code:ro
|
||||
- $PWD/token.txt:/token.txt
|
||||
environment:
|
||||
- service_discovery_url=https://virusdefender.net/service.php
|
||||
- service_url=http://1.2.3.4:12358
|
||||
- token=YOUR_TOKEN_HERE
|
||||
ports:
|
||||
- "0.0.0.0:12358:8080"
|
||||
|
@ -20,5 +20,3 @@ COMPILER_GROUP_GID = grp.getgrnam("compiler").gr_gid
|
||||
TEST_CASE_DIR = "/test_case"
|
||||
SPJ_SRC_DIR = "/spj"
|
||||
SPJ_EXE_DIR = "/spj"
|
||||
|
||||
TOKEN_FILE_PATH = "/token.txt"
|
||||
|
@ -11,14 +11,14 @@ from utils import server_info, logger, token
|
||||
|
||||
class JudgeService(object):
|
||||
def __init__(self):
|
||||
# this container's ip and port, if these are not set, web server will think it's a linked container
|
||||
self.service_url = os.environ.get("service_url")
|
||||
|
||||
# exists if docker link oj_web_server:oj_web_server
|
||||
self.service_discovery_host = os.environ.get("OJ_WEB_SERVER_PORT_8080_TCP_ADDR")
|
||||
self.service_discovery_port = os.environ.get("OJ_WEB_SERVER_PORT_8080_TCP_PORT")
|
||||
self.service_discovery_url = os.environ.get("service_discovery_url", "")
|
||||
|
||||
# this container's ip and port, if these are not set, web server will think it's a linked container
|
||||
self.service_url = os.environ.get("service_url")
|
||||
|
||||
if not self.service_discovery_url:
|
||||
if not (self.service_discovery_host and self.service_discovery_port):
|
||||
raise JudgeServiceError("service discovery host or port not found")
|
||||
|
@ -5,8 +5,8 @@ import psutil
|
||||
import socket
|
||||
import logging
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
from config import TOKEN_FILE_PATH
|
||||
from exception import JudgeClientError
|
||||
|
||||
|
||||
@ -28,11 +28,11 @@ def server_info():
|
||||
|
||||
|
||||
def get_token():
|
||||
try:
|
||||
with open(TOKEN_FILE_PATH, "r") as f:
|
||||
return f.read().strip()
|
||||
except IOError:
|
||||
raise JudgeClientError("token.txt not found")
|
||||
token = os.environ.get("token")
|
||||
if token:
|
||||
return token
|
||||
else:
|
||||
raise JudgeClientError("ENV token not found")
|
||||
|
||||
|
||||
token = hashlib.sha256(get_token()).hexdigest()
|
||||
|
@ -24,7 +24,7 @@ class JudgeServerClientForTokenHeaderTest(JudgeServerClient):
|
||||
|
||||
class JudgeServerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.token = "token"
|
||||
self.token = "YOUR_TOKEN_HERE"
|
||||
self.server_base_url = "http://127.0.0.1:12358"
|
||||
self.client = JudgeServerClient(token=self.token, server_base_url=self.server_base_url)
|
||||
|
||||
@ -44,4 +44,4 @@ class JudgeServerTest(unittest.TestCase):
|
||||
self.assertEqual(data["err"], "TokenVerificationFailed")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
@ -1 +0,0 @@
|
||||
PLEASE_USE_YOUR_OWN_TOKEN
|
Loading…
Reference in New Issue
Block a user