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
|
||||
RUN rm /etc/apt/sources.list
|
||||
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
|
||||
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 apt-get update && apt-get -y install software-properties-common python-software-properties python python-dev gcc g++ git libtool python-pip libseccomp-dev
|
||||
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 && apt-get install -y oracle-java8-installer
|
||||
RUN cd /tmp && git clone -b master 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 chmod -R 777 /var/judger/run/
|
||||
COPY policy /var/judger/run/
|
||||
COPY supervisord.conf /etc
|
||||
COPY dockerfiles/judger/policy /var/judger/run/
|
||||
COPY dockerfiles/judger/supervisord.conf /etc
|
||||
RUN pip install supervisor
|
||||
ADD . /var/judger/code
|
||||
WORKDIR /var/judger/code/judge/
|
||||
EXPOSE 8080
|
||||
CMD bash /var/judger/code/dockerfiles/judger/run.sh
|
||||
@ -1,15 +1,11 @@
|
||||
FROM python:2.7
|
||||
FROM ubuntu:16.04
|
||||
ENV PYTHONBUFFERED 1
|
||||
RUN mkdir -p /code/log /code/test_case /code/upload
|
||||
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 apt-get update && apt-get install -y nginx python-pip libmysqlclient-dev curl nodejs
|
||||
RUN curl -sL https://deb.nodesource.com/setup | bash -
|
||||
RUN apt-get -y install nodejs
|
||||
ADD gunicorn.conf /etc
|
||||
ADD supervisord.conf /etc
|
||||
ADD task_queue.conf /etc
|
||||
EXPOSE 8080
|
||||
RUN apt-get install nodejs
|
||||
ADD . /code
|
||||
WORKDIR /code
|
||||
RUN pip install -i https://pypi.douban.com/simple -r dockerfiles/oj_web_server/requirements.txt
|
||||
RUN python tools/release_static.py
|
||||
EXPOSE 80
|
||||
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
|
||||
fi
|
||||
find /code -name "*.pyc" -delete
|
||||
python -m compileall /code
|
||||
# python -m compileall /code
|
||||
chown -R nobody:nogroup /code/log /code/test_case /code/upload
|
||||
echo "Waiting MySQL and Redis to start"
|
||||
exec supervisord
|
||||
cd /code
|
||||
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
|
||||
pidfile=/code/log/supervisord.pid
|
||||
nodaemon=true
|
||||
user=nobody
|
||||
childlogdir=/code/log/
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///tmp/supervisor.sock
|
||||
|
||||
[include]
|
||||
files=gunicorn.conf task_queue.conf
|
||||
[program:gunicorn]
|
||||
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': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': "oj",
|
||||
'CONN_MAX_AGE': 0.1,
|
||||
'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"],
|
||||
'CONN_MAX_AGE': 10,
|
||||
'HOST': "oj_mysql",
|
||||
'PORT': 3306,
|
||||
'USER': os.environ["MYSQL_ENV_MYSQL_USER"],
|
||||
'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]
|
||||
@ -16,8 +16,8 @@ DATABASES = {
|
||||
'submission': {
|
||||
'NAME': 'oj_submission',
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'CONN_MAX_AGE': 0.1,
|
||||
'HOST': os.environ["MYSQL_PORT_3306_TCP_ADDR"],
|
||||
'CONN_MAX_AGE': 10,
|
||||
'HOST': "oj_mysql",
|
||||
'PORT': 3306,
|
||||
'USER': os.environ["MYSQL_ENV_MYSQL_USER"],
|
||||
'PASSWORD': os.environ["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]
|
||||
@ -25,13 +25,13 @@ DATABASES = {
|
||||
}
|
||||
|
||||
REDIS_CACHE = {
|
||||
"host": os.environ["REDIS_PORT_6379_TCP_ADDR"],
|
||||
"host": "oj_redis",
|
||||
"port": 6379,
|
||||
"db": 1
|
||||
}
|
||||
|
||||
REDIS_QUEUE = {
|
||||
"host": os.environ["REDIS_PORT_6379_TCP_ADDR"],
|
||||
"host": "oj_redis",
|
||||
"port": 6379,
|
||||
"db": 2
|
||||
}
|
||||
|
||||
@ -124,18 +124,6 @@ LOGGING = {
|
||||
# 日志格式
|
||||
},
|
||||
'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': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
@ -144,12 +132,12 @@ LOGGING = {
|
||||
},
|
||||
'loggers': {
|
||||
'app_info': {
|
||||
'handlers': ['app_info', "console"],
|
||||
'handlers': ["console"],
|
||||
'level': 'DEBUG',
|
||||
'propagate': True
|
||||
},
|
||||
'django.request': {
|
||||
'handlers': ['django_error', 'console'],
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': True,
|
||||
},
|
||||
|
||||
@ -2,22 +2,10 @@
|
||||
import os
|
||||
import time
|
||||
import MySQLdb
|
||||
"""
|
||||
docker-compose启动的时候是并行启动的,可能执行本脚本的时候MySQL还没启动完
|
||||
"""
|
||||
i = 3
|
||||
while i:
|
||||
try:
|
||||
conn = MySQLdb.connect(host=os.environ["MYSQL_PORT_3306_TCP_ADDR"],
|
||||
|
||||
conn = MySQLdb.connect(host="oj_mysql",
|
||||
user=os.environ["MYSQL_ENV_MYSQL_USER"],
|
||||
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_submission default character set utf8;")
|
||||
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/"
|
||||
|
||||
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"
|
||||
exit()
|
||||
|
||||
|
||||
@ -1,36 +1,13 @@
|
||||
# coding=utf-8
|
||||
from django.core.management.base import BaseCommand
|
||||
from account.models import User, SUPER_ADMIN, UserProfile
|
||||
from utils.shortcuts import rand_str
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
admin = User.objects.get(username="root")
|
||||
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:
|
||||
if User.objects.exists():
|
||||
return
|
||||
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(rand_password)
|
||||
user.set_password("password@root")
|
||||
user.save()
|
||||
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