Skip to content

Docker dev #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trunk/core/sim/*
trunk/web/discuss3/*
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ ubuntu16.04(不推荐),可以使用下面脚本
wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu16+.sh
sudo bash install-ubuntu16+.sh

docker安装

mkdir -p /data/docker/docker-wxy/data \
/data/docker/docker-wxy/mysql:\
/data/docker/docker-wxy/upload\
/data/docker/docker-wxy/config
chmod 777 /data/docker/docker-wxy/data \
/data/docker/docker-wxy/mysql:\
/data/docker/docker-wxy/upload\
/data/docker/docker-wxy/config

docker stop hustoj
docker rm hustoj
docker pull shiningrise/hustoj
docker run -d -it \
-v /data/docker/docker-wxy/data:/home/judge/data \
-v /data/docker/docker-wxy/mysql:/var/lib/mysql \
-v /data/docker/docker-wxy/upload:/home/judge/src/web/upload \
-v /data/docker/docker-wxy/config:/home/judge/src/web/config \
--name hustoj -p 80:80 shiningrise/hustoj:latest

附加说明:
/home/data/data # 测试数据目录
/home/data/mysql # mysql数据库目录
/home/data/upload #文件上传目录
/home/data/config #配置文件目录

docker测试安装
docker run -d -it --name hustoj -p 80:80 shiningrise/hustoj:latest

https://www.youtube.com/watch?v=nlhmfZqyHnA


Expand Down
61 changes: 61 additions & 0 deletions trunk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM ubuntu:trusty-20171117

#COPY ./docker/hustoj/sources.list /etc/apt/sources.list

RUN apt-get update && apt-get install -y make flex g++ clang libmysqlclient-dev libmysql++-dev php5-fpm php5-memcache memcached nginx php5-mysql php5-gd \
fp-compiler openjdk-7-jdk \
&& rm -rf /var/lib/apt/lists/*

RUN \
echo 'mysql-server-5.5 mysql-server/root_password password ""' | sudo debconf-set-selections \
&& echo 'mysql-server-5.5 mysql-server/root_password_again password ""' | sudo debconf-set-selections \
&& apt-get update && apt-get install -y mysql-server \
&& rm -rf /var/lib/apt/lists/* \
&& /usr/sbin/useradd -m -u 1536 judge

COPY . /home/judge/src

RUN \
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'` \
&& PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'` \
&& CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'` \
&& cd /home/judge/ \
&& mkdir etc data log \
&& cp src/install/java0.policy /home/judge/etc \
&& cp src/install/judge.conf /home/judge/etc \
&& mkdir run0 run1 run2 run3 \
&& chown judge run0 run1 run2 run3 \
&& sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf \
&& sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf \
&& sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf \
&& sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/config/db_info.inc.php \
&& sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/config/db_info.inc.php \
&& chown www-data src/web/upload data \
&& sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf \
&& chown -R mysql:mysql /var/lib/mysql \
&& sed -i "s:root /usr/share/nginx/html;:root /home/judge/src/web;:g" /etc/nginx/sites-enabled/default \
&& sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default \
&& sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default \
&& sed -i "s:#\tfastcgi_split_path_info:\tfastcgi_split_path_info:g" /etc/nginx/sites-enabled/default \
&& sed -i "s:#\tfastcgi_pass unix:\tfastcgi_pass unix:g" /etc/nginx/sites-enabled/default \
&& sed -i "s:#\tfastcgi_index:\tfastcgi_index:g" /etc/nginx/sites-enabled/default \
&& sed -i "s:#\tinclude fastcgi_params;:\tinclude fastcgi_params;\n\t}:g" /etc/nginx/sites-enabled/default \
&& sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php5/fpm/php.ini \
&& sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php5/fpm/php.ini

WORKDIR /home/judge/src/core
RUN pwd && chmod +x make.sh && ./make.sh

WORKDIR /home/judge/
EXPOSE 80
VOLUME ["/home/judge/data","/home/judge/src/web/upload","/var/lib/mysql"]

COPY ./docker/hustoj/docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

RUN cp -R /var/lib/mysql/ /home/ \
&& cp -R /home/judge/src/web/config/ /home/ \
&& cp /home/judge/etc/judge.conf /home/config/judge.conf

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

Empty file modified trunk/core/make.sh
100755 → 100644
Empty file.
30 changes: 30 additions & 0 deletions trunk/docker/hustoj/build-dokcer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#docker rm $(docker ps -a -q)
#cd docker\hustoj-base
cd ../../
#cd core & ./makeForDocker.sh & cd ..

#docker build -f Dockerfile -t hustoj ./

docker stop /hustoj
docker rm -f /hustoj
#rm -R /home/data/
mkdir -p /home/data/ /home/data/config
chmod 777 /home/data/ /home/data/config


docker run -d -it \
-v /home/data/data:/home/judge/data \
-v /home/data/mysql:/var/lib/mysql \
-v /home/data/upload:/home/judge/src/web/upload \
-v /home/data/config:/home/judge/src/web/config \
--name hustoj -p 80:80 hustoj

#docker run -d -it \
#-v /home/data/data:/home/judge/data \
#-v /home/data/upload:/home/judge/src/web/upload \
#-v /home/data/mysql:/var/lib/mysql \
#--name hustoj -p 80:80 hustoj

#
#docker run -d -it --name hustoj -p 80:80 hustoj
#docker exec -i -t hustoj /bin/bash
49 changes: 49 additions & 0 deletions trunk/docker/hustoj/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
service nginx start
chown -R mysql:mysql /var/lib/mysql

DIRECTORY="/var/lib/mysql"
if [ "`ls -A $DIRECTORY`" = "" ]; then
cp -R /home/mysql/* /var/lib/mysql/
fi

DIRECTORY="/home/judge/src/web/config"
if [ "`ls -A $DIRECTORY`" = "" ]; then
cp -R /home/config/* /home/judge/src/web/config
fi

chown -R mysql:mysql /var/lib/mysql
service mysql start

dir="/var/lib/mysql/jol"
if [ ! -d $dir ]; then
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
mysql -h localhost -u$USER -p$PASSWORD< /home/judge/src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','N');"|mysql -h localhost -u$USER -p$PASSWORD
else
cp /home/judge/src/web/config/db_info.inc.php /home/judge/src/web/include/db_info.inc.php
fi

if [ -f /home/judge/src/web/config/db_info.inc.php ]; then
cp /home/judge/src/web/config/db_info.inc.php /home/judge/src/web/include/db_info.inc.php
else
cp /home/judge/src/web/include/db_info.inc.php /home/judge/src/web/config/db_info.inc.php
fi

if [ -f /home/judge/src/web/config/judge.conf ]; then
cp /home/judge/src/web/config/judge.conf /home/judge/etc/judge.conf
else
cp /home/judge/etc/judge.conf /home/judge/src/web/config/judge.conf
fi


php5-fpm
/usr/bin/judged
chmod 775 -R /home/judge/data && chgrp -R www-data /home/judge/data
chmod 770 -R /home/judge/src/web/upload && chgrp -R www-data /home/judge/src/web/upload
chmod 770 -R /home/judge/src/web/config && chgrp -R /home/judge/src/web/config
/bin/bash
exit 0


10 changes: 10 additions & 0 deletions trunk/docker/hustoj/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
Empty file modified trunk/install/db.sql
100755 → 100644
Empty file.
119 changes: 119 additions & 0 deletions trunk/web/config/db_info.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php @session_start();
ini_set("display_errors","Off"); //set this to "On" for debugging ,especially when no reason blank shows up.
ini_set("session.cookie_httponly", 1);
header('X-Frame-Options:SAMEORIGIN');

//for people using hustoj out of China , be careful of the last two line of this file !

// connect db
static $DB_HOST="localhost";
static $DB_NAME="jol";
static $DB_USER="root";
static $DB_PASS="root";

static $OJ_NAME="HUSTOJ";
static $OJ_HOME="./";
static $OJ_ADMIN="root@localhost";
static $OJ_DATA="/home/judge/data";
static $OJ_BBS="discuss3";//"bbs" for phpBB3 bridge or "discuss" for mini-forum
static $OJ_ONLINE=false;
static $OJ_LANG="cn";
static $OJ_SIM=false;
static $OJ_DICT=false;
static $OJ_LANGMASK=0; //1mC 2mCPP 4mPascal 8mJava 16mRuby 32mBash 1008 for security reason to mask all other language
static $OJ_EDITE_AREA=true;//true: syntax highlighting is active
static $OJ_AUTO_SHARE=false;//true: One can view all AC submit if he/she has ACed it onece.
static $OJ_CSS="white.css";
static $OJ_SAE=false; //using sina application engine
static $OJ_VCODE=false;
static $OJ_APPENDCODE=false;
static $OJ_CE_PENALTY=false;
static $OJ_MEMCACHE=false;
static $OJ_MEMSERVER="127.0.0.1";
static $OJ_MEMPORT=11211;
static $OJ_REDIS=false;
static $OJ_REDISSERVER="127.0.0.1";
static $OJ_REDISPORT=6379;
static $OJ_REDISQNAME="hustoj";
static $SAE_STORAGE_ROOT="http://hustoj-web.stor.sinaapp.com/";
static $OJ_TEMPLATE="bs3"; //使用的默认模板
if(isset($_GET['tp'])) $OJ_TEMPLATE=$_GET['tp'];
static $OJ_LOGIN_MOD="hustoj";
static $OJ_REGISTER=true; //允许注册新用户
static $OJ_REG_NEED_CONFIRM=false; //新注册用户需要审核
static $OJ_RANK_LOCK_PERCENT=0; //比赛封榜时间比例
static $OJ_SHOW_DIFF=false; //是否显示WA的对比说明
static $OJ_TEST_RUN=false; //提交界面是否允许测试运行
static $OJ_BLOCKLY=false; //是否启用Blockly界面
static $OJ_ENCODE_SUBMIT=false; //是否启用base64编码提交的功能,用来回避WAF防火墙误拦截。
static $OJ_OPENID_PWD = '8a367fe87b1e406ea8e94d7d508dcf01';

/* weibo config here */
static $OJ_WEIBO_AUTH=false;
static $OJ_WEIBO_AKEY='1124518951';
static $OJ_WEIBO_ASEC='df709a1253ef8878548920718085e84b';
static $OJ_WEIBO_CBURL='http://192.168.0.108/JudgeOnline/login_weibo.php';

/* renren config here */
static $OJ_RR_AUTH=false;
static $OJ_RR_AKEY='d066ad780742404d85d0955ac05654df';
static $OJ_RR_ASEC='c4d2988cf5c149fabf8098f32f9b49ed';
static $OJ_RR_CBURL='http://192.168.0.108/JudgeOnline/login_renren.php';
/* qq config here */
static $OJ_QQ_AUTH=false;
static $OJ_QQ_AKEY='1124518951';
static $OJ_QQ_ASEC='df709a1253ef8878548920718085e84b';
static $OJ_QQ_CBURL='192.168.0.108';

//if(date('H')<5||date('H')>21||isset($_GET['dark'])) $OJ_CSS="dark.css";
if( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'],"zh-CN")) {
$OJ_LANG="cn";
}
if (isset($_SESSION[$OJ_NAME.'_'.'OJ_LANG'])) $OJ_LANG=$_SESSION[$OJ_NAME.'_'.'OJ_LANG'];


function pdo_query($sql){
$num_args = func_num_args();
$args = func_get_args(); //获得传入的所有参数的数组
$args=array_slice($args,1,--$num_args);

global $DB_HOST,$DB_NAME,$DB_USER,$DB_PASS,$dbh,$OJ_SAE;
if(!$dbh){

if(isset($OJ_SAE)&&$OJ_SAE) {
$OJ_DATA="saestor://data/";
// for sae.sina.com.cn
$DB_NAME=SAE_MYSQL_DB;
$dbh=new PDO("mysql:host=".SAE_MYSQL_HOST_M.';dbname='.SAE_MYSQL_DB, SAE_MYSQL_USER, SAE_MYSQL_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
}else{
$dbh=new PDO("mysql:host=".$DB_HOST.';dbname='.$DB_NAME, $DB_USER, $DB_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
}

}

$sth = $dbh->prepare($sql);
$sth->execute($args);
$result=array();
if(stripos($sql,"select") === 0){
$result=$sth->fetchAll();
}else if(stripos($sql,"insert") === 0){
$result=$dbh->lastInsertId();
}else{
$result=$sth->rowCount();
}
//print_r($result);
$sth->closeCursor();
return $result;
}
// use db
//pdo_query("set names utf8");

if(isset($OJ_CSRF)&&$OJ_CSRF&&$OJ_TEMPLATE=="bs3"&&basename($_SERVER['PHP_SELF'])!="problem_judge")
require_once('csrf_check.php');

//sychronize php and mysql server with timezone settings, dafault setting for China
//if you are not from China, comment out these two lines or modify them.
//date_default_timezone_set("PRC");
//pdo_query("SET time_zone ='+8:00'");

?>