mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
new deploy
This commit is contained in:
parent
5fd6af52cf
commit
b1793d29a2
1
build.sh
Executable file
1
build.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
docker build -t registry.cn-hangzhou.aliyuncs.com/qduoj/oj_web_server -f dockerfiles/oj_web_server/Dockerfile .
|
||||||
@ -1,20 +1,15 @@
|
|||||||
FROM ubuntu:14.04
|
FROM ubuntu:16.04
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
RUN rm /etc/apt/sources.list
|
RUN apt-get update && apt-get -y install software-properties-common python-software-properties python python-dev gcc g++ git libtool python-pip libseccomp-dev
|
||||||
COPY sources.list /etc/apt/
|
RUN add-apt-repository -y ppa:webupd8team/java && echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
|
||||||
RUN apt-get update
|
RUN apt-get update && apt-get install -y oracle-java8-installer
|
||||||
RUN apt-get -y install software-properties-common python-software-properties python python-dev gcc g++ git libtool python-pip libseccomp-dev
|
RUN cd /tmp && git clone -b master https://github.com/QingdaoU/Judger && cd Judger && python setup.py install
|
||||||
RUN add-apt-repository -y ppa:webupd8team/java
|
|
||||||
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
|
|
||||||
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y oracle-java7-installer
|
|
||||||
RUN cd /tmp && git clone https://github.com/QingdaoU/Judger && cd Judger && python setup.py install
|
|
||||||
RUN mkdir -p /var/judger/run/ && mkdir /var/judger/test_case/ && mkdir /var/judger/code/
|
RUN mkdir -p /var/judger/run/ && mkdir /var/judger/test_case/ && mkdir /var/judger/code/
|
||||||
RUN chmod -R 777 /var/judger/run/
|
RUN chmod -R 777 /var/judger/run/
|
||||||
COPY policy /var/judger/run/
|
COPY dockerfiles/judger/policy /var/judger/run/
|
||||||
COPY supervisord.conf /etc
|
COPY dockerfiles/judger/supervisord.conf /etc
|
||||||
RUN pip install supervisor
|
RUN pip install supervisor
|
||||||
|
ADD . /var/judger/code
|
||||||
WORKDIR /var/judger/code/judge/
|
WORKDIR /var/judger/code/judge/
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD bash /var/judger/code/dockerfiles/judger/run.sh
|
CMD bash /var/judger/code/dockerfiles/judger/run.sh
|
||||||
@ -1,15 +1,11 @@
|
|||||||
FROM python:2.7
|
FROM ubuntu:16.04
|
||||||
ENV PYTHONBUFFERED 1
|
ENV PYTHONBUFFERED 1
|
||||||
RUN mkdir -p /code/log /code/test_case /code/upload
|
RUN apt-get update && apt-get install -y nginx python-pip libmysqlclient-dev curl nodejs
|
||||||
WORKDIR /code
|
|
||||||
ADD requirements.txt /code/
|
|
||||||
RUN pip install -i http://pypi.douban.com/simple -r requirements.txt --trusted-host pypi.douban.com
|
|
||||||
RUN rm /etc/apt/sources.list
|
|
||||||
ADD sources.list /etc/apt/
|
|
||||||
RUN curl -sL https://deb.nodesource.com/setup | bash -
|
RUN curl -sL https://deb.nodesource.com/setup | bash -
|
||||||
RUN apt-get -y install nodejs
|
RUN apt-get install nodejs
|
||||||
ADD gunicorn.conf /etc
|
ADD . /code
|
||||||
ADD supervisord.conf /etc
|
WORKDIR /code
|
||||||
ADD task_queue.conf /etc
|
RUN pip install -i https://pypi.douban.com/simple -r dockerfiles/oj_web_server/requirements.txt
|
||||||
EXPOSE 8080
|
RUN python tools/release_static.py
|
||||||
|
EXPOSE 80
|
||||||
CMD bash /code/dockerfiles/oj_web_server/run.sh
|
CMD bash /code/dockerfiles/oj_web_server/run.sh
|
||||||
@ -1,12 +0,0 @@
|
|||||||
[program:gunicorn]
|
|
||||||
command=gunicorn oj.wsgi:application -b 0.0.0.0:8080 --reload
|
|
||||||
directory=/code/
|
|
||||||
user=nobody
|
|
||||||
numprocs=1
|
|
||||||
stdout_logfile=/code/log/gunicorn.log
|
|
||||||
stderr_logfile=/code/log/gunicorn.log
|
|
||||||
autostart=true
|
|
||||||
autorestart=true
|
|
||||||
startsecs=5
|
|
||||||
stopwaitsecs = 5
|
|
||||||
killasgroup=true
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
server {
|
|
||||||
listen 80 default_server;
|
|
||||||
server_name _;
|
|
||||||
location /static/upload {
|
|
||||||
expires max;
|
|
||||||
alias /home/upload;
|
|
||||||
}
|
|
||||||
location /static {
|
|
||||||
etag off;
|
|
||||||
expires max;
|
|
||||||
alias /home/OnlineJudge/static/release;
|
|
||||||
}
|
|
||||||
location / {
|
|
||||||
client_max_body_size 100m;
|
|
||||||
proxy_pass http://oj_web_server:8080;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -4,7 +4,17 @@ if [ ! -f "/code/oj/custom_settings.py" ]; then
|
|||||||
echo "SECRET_KEY=\"`cat /dev/urandom | head -1 | md5sum | head -c 32`\"" >> /code/oj/custom_settings.py
|
echo "SECRET_KEY=\"`cat /dev/urandom | head -1 | md5sum | head -c 32`\"" >> /code/oj/custom_settings.py
|
||||||
fi
|
fi
|
||||||
find /code -name "*.pyc" -delete
|
find /code -name "*.pyc" -delete
|
||||||
python -m compileall /code
|
# python -m compileall /code
|
||||||
chown -R nobody:nogroup /code/log /code/test_case /code/upload
|
chown -R nobody:nogroup /code/log /code/test_case /code/upload
|
||||||
echo "Waiting MySQL and Redis to start"
|
cd /code
|
||||||
exec supervisord
|
n=0
|
||||||
|
until [ $n -ge 5 ]
|
||||||
|
do
|
||||||
|
python tools/create_db.py &&
|
||||||
|
python manage.py migrate --no-input &&
|
||||||
|
python manage.py migrate --database=submission --no-input &&
|
||||||
|
python manage.py initadmin && break
|
||||||
|
n=$(($n+1))
|
||||||
|
sleep 8
|
||||||
|
done
|
||||||
|
exec supervisord -c /code/dockerfiles/oj_web_server/supervisord.conf
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
deb http://mirrors.aliyun.com/debian wheezy main contrib non-free
|
|
||||||
deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free
|
|
||||||
|
|
||||||
deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free
|
|
||||||
deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free
|
|
||||||
|
|
||||||
deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free
|
|
||||||
deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free
|
|
||||||
@ -5,11 +5,44 @@ logfile_backups=10
|
|||||||
loglevel=info
|
loglevel=info
|
||||||
pidfile=/code/log/supervisord.pid
|
pidfile=/code/log/supervisord.pid
|
||||||
nodaemon=true
|
nodaemon=true
|
||||||
user=nobody
|
|
||||||
childlogdir=/code/log/
|
childlogdir=/code/log/
|
||||||
|
|
||||||
[supervisorctl]
|
[supervisorctl]
|
||||||
serverurl=unix:///tmp/supervisor.sock
|
serverurl=unix:///tmp/supervisor.sock
|
||||||
|
|
||||||
[include]
|
[program:gunicorn]
|
||||||
files=gunicorn.conf task_queue.conf
|
command=gunicorn oj.wsgi:application --user nobody -b 127.0.0.1:8080 --reload
|
||||||
|
directory=/code/
|
||||||
|
numprocs=1
|
||||||
|
stdout_logfile=/code/log/gunicorn.log
|
||||||
|
stderr_logfile=/code/log/gunicorn.log
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
startsecs=5
|
||||||
|
stopwaitsecs = 5
|
||||||
|
killasgroup=true
|
||||||
|
|
||||||
|
[program:task_queue]
|
||||||
|
command=celery -A oj worker -l warning
|
||||||
|
directory=/code/
|
||||||
|
user=nobody
|
||||||
|
numprocs=1
|
||||||
|
stdout_logfile=/code/log/task_queue.log
|
||||||
|
stderr_logfile=/code/log/task_queue.log
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
startsecs=5
|
||||||
|
stopwaitsecs = 5
|
||||||
|
killasgroup=true
|
||||||
|
|
||||||
|
[program:nginx]
|
||||||
|
command=nginx -c /code/dockerfiles/oj_web_server/oj.conf
|
||||||
|
directory=/code/
|
||||||
|
numprocs=1
|
||||||
|
stdout_logfile=/code/log/nginx.log
|
||||||
|
stderr_logfile=/code/log/nginx.log
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
startsecs=5
|
||||||
|
stopwaitsecs = 5
|
||||||
|
killasgroup=true
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
[program:task_queue]
|
|
||||||
command=celery -A oj worker --autoscale=30,4 -l DEBUG
|
|
||||||
directory=/code/
|
|
||||||
user=nobody
|
|
||||||
numprocs=1
|
|
||||||
stdout_logfile=/code/log/task_queue.log
|
|
||||||
stderr_logfile=/code/log/task_queue.log
|
|
||||||
autostart=true
|
|
||||||
autorestart=true
|
|
||||||
startsecs=5
|
|
||||||
stopwaitsecs = 5
|
|
||||||
killasgroup=true
|
|
||||||
@ -7,8 +7,8 @@ DATABASES = {
|
|||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': "oj",
|
'NAME': "oj",
|
||||||
'CONN_MAX_AGE': 0.1,
|
'CONN_MAX_AGE': 10,
|
||||||
'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"],
|
'HOST': "oj_mysql",
|
||||||
'PORT': 3306,
|
'PORT': 3306,
|
||||||
'USER': os.environ["MYSQL_ENV_MYSQL_USER"],
|
'USER': os.environ["MYSQL_ENV_MYSQL_USER"],
|
||||||
'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]
|
'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]
|
||||||
@ -16,8 +16,8 @@ DATABASES = {
|
|||||||
'submission': {
|
'submission': {
|
||||||
'NAME': 'oj_submission',
|
'NAME': 'oj_submission',
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'CONN_MAX_AGE': 0.1,
|
'CONN_MAX_AGE': 10,
|
||||||
'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"],
|
'HOST': "oj_mysql",
|
||||||
'PORT': 3306,
|
'PORT': 3306,
|
||||||
'USER': os.environ["MYSQL_ENV_MYSQL_USER"],
|
'USER': os.environ["MYSQL_ENV_MYSQL_USER"],
|
||||||
'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]
|
'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]
|
||||||
@ -25,13 +25,13 @@ DATABASES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
REDIS_CACHE = {
|
REDIS_CACHE = {
|
||||||
"host": os.environ["REDIS_PORT_6379_TCP_ADDR"],
|
"host": "oj_redis",
|
||||||
"port": 6379,
|
"port": 6379,
|
||||||
"db": 1
|
"db": 1
|
||||||
}
|
}
|
||||||
|
|
||||||
REDIS_QUEUE = {
|
REDIS_QUEUE = {
|
||||||
"host": os.environ["REDIS_PORT_6379_TCP_ADDR"],
|
"host": "oj_redis",
|
||||||
"port": 6379,
|
"port": 6379,
|
||||||
"db": 2
|
"db": 2
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,18 +124,6 @@ LOGGING = {
|
|||||||
# 日志格式
|
# 日志格式
|
||||||
},
|
},
|
||||||
'handlers': {
|
'handlers': {
|
||||||
'django_error': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'class': 'logging.handlers.RotatingFileHandler',
|
|
||||||
'filename': LOG_PATH + 'django.log',
|
|
||||||
'formatter': 'standard'
|
|
||||||
},
|
|
||||||
'app_info': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'class': 'logging.handlers.RotatingFileHandler',
|
|
||||||
'filename': LOG_PATH + 'app_info.log',
|
|
||||||
'formatter': 'standard'
|
|
||||||
},
|
|
||||||
'console': {
|
'console': {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.StreamHandler',
|
'class': 'logging.StreamHandler',
|
||||||
@ -144,12 +132,12 @@ LOGGING = {
|
|||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'app_info': {
|
'app_info': {
|
||||||
'handlers': ['app_info', "console"],
|
'handlers': ["console"],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'propagate': True
|
'propagate': True
|
||||||
},
|
},
|
||||||
'django.request': {
|
'django.request': {
|
||||||
'handlers': ['django_error', 'console'],
|
'handlers': ['console'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'propagate': True,
|
'propagate': True,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,22 +2,10 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
"""
|
|
||||||
docker-compose启动的时候是并行启动的,可能执行本脚本的时候MySQL还没启动完
|
conn = MySQLdb.connect(host="oj_mysql",
|
||||||
"""
|
|
||||||
i = 3
|
|
||||||
while i:
|
|
||||||
try:
|
|
||||||
conn = MySQLdb.connect(host=os.environ["MYSQL_PORT_3306_TCP_ADDR"],
|
|
||||||
user=os.environ["MYSQL_ENV_MYSQL_USER"],
|
user=os.environ["MYSQL_ENV_MYSQL_USER"],
|
||||||
passwd=os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"])
|
passwd=os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"])
|
||||||
conn.cursor().execute("create database if not exists oj default character set utf8;")
|
conn.cursor().execute("create database if not exists oj default character set utf8;")
|
||||||
conn.cursor().execute("create database if not exists oj_submission default character set utf8;")
|
conn.cursor().execute("create database if not exists oj_submission default character set utf8;")
|
||||||
print "Create database successfully"
|
print "Create database successfully"
|
||||||
exit(0)
|
|
||||||
except Exception as e:
|
|
||||||
print "Failed to create database, error: " + str(e) + ", will retry in 3 seconds"
|
|
||||||
i -= 1
|
|
||||||
time.sleep(3)
|
|
||||||
print "Failed to create database"
|
|
||||||
exit(1)
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ static_src_path = "static/src/"
|
|||||||
static_release_path = "static/release/"
|
static_release_path = "static/release/"
|
||||||
|
|
||||||
print "Begin to compress js"
|
print "Begin to compress js"
|
||||||
if os.system("node static/src/js/r.js -o static/src/js/build.js"):
|
if os.system("nodejs static/src/js/r.js -o static/src/js/build.js"):
|
||||||
print "Failed to compress js, exit"
|
print "Failed to compress js, exit"
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|||||||
@ -1,36 +1,13 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from account.models import User, SUPER_ADMIN, UserProfile
|
from account.models import User, SUPER_ADMIN, UserProfile
|
||||||
from utils.shortcuts import rand_str
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
try:
|
if User.objects.exists():
|
||||||
admin = User.objects.get(username="root")
|
return
|
||||||
if admin.admin_type == SUPER_ADMIN:
|
|
||||||
self.stdout.write(self.style.WARNING("Super admin user 'root' already exists, "
|
|
||||||
"would you like to reset it's password?\n"
|
|
||||||
"Input yes to confirm: "))
|
|
||||||
if raw_input() == "yes":
|
|
||||||
rand_password = rand_str(length=6)
|
|
||||||
admin.set_password(rand_password)
|
|
||||||
admin.save()
|
|
||||||
self.stdout.write(self.style.SUCCESS("Successfully created super admin user password.\n"
|
|
||||||
"Username: root\nPassword: %s\n"
|
|
||||||
"Remember to change password and turn on two factors auth "
|
|
||||||
"after installation." % rand_password))
|
|
||||||
else:
|
|
||||||
self.stdout.write(self.style.SUCCESS("Nothing happened"))
|
|
||||||
else:
|
|
||||||
self.stdout.write(self.style.ERROR("User 'root' is not super admin."))
|
|
||||||
except User.DoesNotExist:
|
|
||||||
user = User.objects.create(username="root", real_name="root", email="root@oj.com", admin_type=SUPER_ADMIN)
|
user = User.objects.create(username="root", real_name="root", email="root@oj.com", admin_type=SUPER_ADMIN)
|
||||||
rand_password = rand_str(length=6)
|
user.set_password("password@root")
|
||||||
user.set_password(rand_password)
|
|
||||||
user.save()
|
user.save()
|
||||||
UserProfile.objects.create(user=user)
|
UserProfile.objects.create(user=user)
|
||||||
self.stdout.write(self.style.SUCCESS("Successfully created super admin user.\n"
|
|
||||||
"Username: root\nPassword: %s\n"
|
|
||||||
"Remember to change password and turn on two factors auth "
|
|
||||||
"after installation." % rand_password))
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user