diff --git a/.gitignore b/.gitignore index 31d22157..e0873616 100644 --- a/.gitignore +++ b/.gitignore @@ -62,4 +62,5 @@ static/src/upload_image/* build.txt tmp/ test_case/ -release/ \ No newline at end of file +release/ +upload/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2e10830a..113ed588 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:2.7 ENV PYTHONBUFFERED 1 -RUN mkdir -p /code/log /code/test_case +RUN mkdir -p /code/log /code/test_case /code/upload WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt diff --git a/judge/judger/settings.py b/judge/judger/settings.py index 1f15b96b..224cf5dd 100644 --- a/judge/judger/settings.py +++ b/judge/judger/settings.py @@ -1,4 +1,5 @@ # coding=utf-8 +import os # 单个判题端最多同时运行的程序个数,因为判题端会同时运行多组测试数据,比如一共有5组测试数据 # 如果MAX_RUNNING_NUMBER大于等于5,那么这5组数据就会同时进行评测,然后返回结果。 # 如果MAX_RUNNING_NUMBER小于5,为3,那么就会同时运行前三组测试数据,然后再运行后两组数据 @@ -14,12 +15,10 @@ lrun_gid = 1002 # judger工作目录 judger_workspace = "/var/judger/" - -# 这个是在docker 中访问数据库 ip 不一定和web服务器还有celery的一样 submission_db = { - "host": "192.168.42.1", + "host": os.environ.get("MYSQL_PORT_3306_TCP_ADDR", "127.0.0.1"), "port": 3306, "db": "oj_submission", "user": "root", - "password": "mypwd" + "password": os.environ.get("MYSQL_ENV_MYSQL_ROOT_PASSWORD", "root") } diff --git a/oj/local_settings.py b/oj/local_settings.py index 3b685e7a..074b1b01 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -3,10 +3,6 @@ import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# 下面是需要自己修改的 -LOG_PATH = "log/" - # 注意这是web 服务器访问的地址,判题端访问的地址不一定一样,因为可能不在一台机器上 DATABASES = { 'default': { @@ -17,11 +13,11 @@ DATABASES = { 'submission': { 'NAME': 'oj_submission', 'ENGINE': 'django.db.backends.mysql', - 'HOST': "121.42.32.129", + 'CONN_MAX_AGE': 0.1, + 'HOST': "127.0.0.1", 'PORT': 3306, 'USER': 'root', - 'PASSWORD': 'mypwd', - 'CONN_MAX_AGE': 0.1, + 'PASSWORD': 'root', } } @@ -33,13 +29,11 @@ REDIS_CACHE = { DEBUG = True -# 同理 这是 web 服务器的上传路径 -TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/') - ALLOWED_HOSTS = [] -IMAGE_UPLOAD_DIR = os.path.join(BASE_DIR, 'static/src/upload_image/') - -STATICFILES_DIRS = [os.path.join(BASE_DIR, "static/src/")] +# 在 debug 关闭的情况下,静态文件不是有 django runserver 来处理的,应该由 nginx 返回 +# 在 debug 开启的情况下,django 会在下面两个文件夹中寻找对应的静态文件。 +STATICFILES_DIRS = [os.path.join(BASE_DIR, "static/src/"), BASE_DIR] +# 模板文件夹 TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'template/src/')] \ No newline at end of file diff --git a/oj/server_settings.py b/oj/server_settings.py index 1702fa95..77ca1fd0 100644 --- a/oj/server_settings.py +++ b/oj/server_settings.py @@ -3,47 +3,41 @@ import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# 下面是需要自己修改的 -LOG_PATH = "/var/log/oj/" - # 注意这是web 服务器访问的地址,判题端访问的地址不一定一样,因为可能不在一台机器上 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': "oj", 'CONN_MAX_AGE': 0.1, - 'HOST': '127.0.0.1', + 'HOST': os.environ.get("MYSQL_PORT_3306_TCP_ADDR", "127.0.0.1"), 'PORT': 3306, 'USER': 'root', - 'PASSWORD': 'mypwd' + 'PASSWORD': os.environ.get("MYSQL_ENV_MYSQL_ROOT_PASSWORD", "root") }, 'submission': { 'NAME': 'oj_submission', 'ENGINE': 'django.db.backends.mysql', 'CONN_MAX_AGE': 0.1, - 'HOST': "127.0.0.1", + 'HOST': os.environ.get("MYSQL_PORT_3306_TCP_ADDR", "127.0.0.1"), 'PORT': 3306, 'USER': 'root', - 'PASSWORD': 'mypwd' + 'PASSWORD': os.environ.get("MYSQL_ENV_MYSQL_ROOT_PASSWORD", "root") } } REDIS_CACHE = { - "host": "127.0.0.1", + "host": os.environ.get("REDIS_PORT_6379_TCP_ADDR", "127.0.0.1"), "port": 6379, "db": 1 } -DEBUG = True - -# 同理 这是 web 服务器的上传路径 -TEST_CASE_DIR = '/root/test_case/' +DEBUG = False ALLOWED_HOSTS = ['*'] -IMAGE_UPLOAD_DIR = '/var/mnt/source/OnlineJudge/static/src/upload_image/' - -STATICFILES_DIRS = [os.path.join(BASE_DIR, "static/release/")] +# 在 debug 关闭的情况下,静态文件不是有 django runserver 来处理的,应该由 nginx 返回 +# 在 debug 开启的情况下,django 会在下面两个文件夹中寻找对应的静态文件。 +STATICFILES_DIRS = [os.path.join(BASE_DIR, "static/release/"), os.path.join(BASE_DIR, "static/release/")] +# 模板文件夹 TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'template/release/')] diff --git a/oj/settings.py b/oj/settings.py index bc400692..7e479194 100644 --- a/oj/settings.py +++ b/oj/settings.py @@ -89,7 +89,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'oj.wsgi.application' - # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ @@ -111,6 +110,9 @@ STATIC_URL = '/static/' AUTH_USER_MODEL = 'account.User' +LOG_PATH = "log/" + + LOGGING = { 'version': 1, 'disable_existing_loggers': True, @@ -162,4 +164,8 @@ REST_FRAMEWORK = { 'TEST_REQUEST_DEFAULT_FORMAT': 'json' } -DATABASE_ROUTERS = ['oj.db_router.DBRouter'] \ No newline at end of file +DATABASE_ROUTERS = ['oj.db_router.DBRouter'] + +TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/') + +IMAGE_UPLOAD_DIR = os.path.join(BASE_DIR, 'upload/') \ No newline at end of file diff --git a/utils/views.py b/utils/views.py index 87beeb4f..7e2375e2 100644 --- a/utils/views.py +++ b/utils/views.py @@ -26,8 +26,8 @@ class SimditorImageUploadAPIView(APIView): return Response(data={ "success": True, "msg": "上传错误", - "file_path": "/static/upload_image/" + image_name}) + "file_path": "/static/upload/" + image_name}) return Response(data={ "success": True, "msg": "", - "file_path": "/static/upload_image/" + image_name}) + "file_path": "/static/upload/" + image_name})