Skip to content

Commit 160c6de

Browse files
authored
Merge pull request #235 from shiningrise/docker-dev
Docker dev
2 parents a1e8428 + 1b44c70 commit 160c6de

File tree

9 files changed

+301
-0
lines changed

9 files changed

+301
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trunk/core/sim/*
2+
trunk/web/discuss3/*

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,36 @@ ubuntu16.04(不推荐),可以使用下面脚本
2222
wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu16+.sh
2323
sudo bash install-ubuntu16+.sh
2424

25+
docker安装
26+
27+
mkdir -p /data/docker/docker-wxy/data \
28+
/data/docker/docker-wxy/mysql:\
29+
/data/docker/docker-wxy/upload\
30+
/data/docker/docker-wxy/config
31+
chmod 777 /data/docker/docker-wxy/data \
32+
/data/docker/docker-wxy/mysql:\
33+
/data/docker/docker-wxy/upload\
34+
/data/docker/docker-wxy/config
35+
36+
docker stop hustoj
37+
docker rm hustoj
38+
docker pull shiningrise/hustoj
39+
docker run -d -it \
40+
-v /data/docker/docker-wxy/data:/home/judge/data \
41+
-v /data/docker/docker-wxy/mysql:/var/lib/mysql \
42+
-v /data/docker/docker-wxy/upload:/home/judge/src/web/upload \
43+
-v /data/docker/docker-wxy/config:/home/judge/src/web/config \
44+
--name hustoj -p 80:80 shiningrise/hustoj:latest
45+
46+
附加说明:
47+
/home/data/data # 测试数据目录
48+
/home/data/mysql # mysql数据库目录
49+
/home/data/upload #文件上传目录
50+
/home/data/config #配置文件目录
51+
52+
docker测试安装
53+
docker run -d -it --name hustoj -p 80:80 shiningrise/hustoj:latest
54+
2555
https://www.youtube.com/watch?v=nlhmfZqyHnA
2656

2757

trunk/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM ubuntu:trusty-20171117
2+
3+
#COPY ./docker/hustoj/sources.list /etc/apt/sources.list
4+
5+
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 \
6+
fp-compiler openjdk-7-jdk \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
RUN \
10+
echo 'mysql-server-5.5 mysql-server/root_password password ""' | sudo debconf-set-selections \
11+
&& echo 'mysql-server-5.5 mysql-server/root_password_again password ""' | sudo debconf-set-selections \
12+
&& apt-get update && apt-get install -y mysql-server \
13+
&& rm -rf /var/lib/apt/lists/* \
14+
&& /usr/sbin/useradd -m -u 1536 judge
15+
16+
COPY . /home/judge/src
17+
18+
RUN \
19+
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'` \
20+
&& PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'` \
21+
&& CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'` \
22+
&& cd /home/judge/ \
23+
&& mkdir etc data log \
24+
&& cp src/install/java0.policy /home/judge/etc \
25+
&& cp src/install/judge.conf /home/judge/etc \
26+
&& mkdir run0 run1 run2 run3 \
27+
&& chown judge run0 run1 run2 run3 \
28+
&& sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf \
29+
&& sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf \
30+
&& sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf \
31+
&& sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/config/db_info.inc.php \
32+
&& sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/config/db_info.inc.php \
33+
&& chown www-data src/web/upload data \
34+
&& sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf \
35+
&& chown -R mysql:mysql /var/lib/mysql \
36+
&& sed -i "s:root /usr/share/nginx/html;:root /home/judge/src/web;:g" /etc/nginx/sites-enabled/default \
37+
&& sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default \
38+
&& sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default \
39+
&& sed -i "s:#\tfastcgi_split_path_info:\tfastcgi_split_path_info:g" /etc/nginx/sites-enabled/default \
40+
&& sed -i "s:#\tfastcgi_pass unix:\tfastcgi_pass unix:g" /etc/nginx/sites-enabled/default \
41+
&& sed -i "s:#\tfastcgi_index:\tfastcgi_index:g" /etc/nginx/sites-enabled/default \
42+
&& sed -i "s:#\tinclude fastcgi_params;:\tinclude fastcgi_params;\n\t}:g" /etc/nginx/sites-enabled/default \
43+
&& sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php5/fpm/php.ini \
44+
&& sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php5/fpm/php.ini
45+
46+
WORKDIR /home/judge/src/core
47+
RUN pwd && chmod +x make.sh && ./make.sh
48+
49+
WORKDIR /home/judge/
50+
EXPOSE 80
51+
VOLUME ["/home/judge/data","/home/judge/src/web/upload","/var/lib/mysql"]
52+
53+
COPY ./docker/hustoj/docker-entrypoint.sh /usr/local/bin/
54+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
55+
56+
RUN cp -R /var/lib/mysql/ /home/ \
57+
&& cp -R /home/judge/src/web/config/ /home/ \
58+
&& cp /home/judge/etc/judge.conf /home/config/judge.conf
59+
60+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
61+

trunk/core/make.sh

100755100644
File mode changed.

trunk/docker/hustoj/build-dokcer.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#docker rm $(docker ps -a -q)
2+
#cd docker\hustoj-base
3+
cd ../../
4+
#cd core & ./makeForDocker.sh & cd ..
5+
6+
#docker build -f Dockerfile -t hustoj ./
7+
8+
docker stop /hustoj
9+
docker rm -f /hustoj
10+
#rm -R /home/data/
11+
mkdir -p /home/data/ /home/data/config
12+
chmod 777 /home/data/ /home/data/config
13+
14+
15+
docker run -d -it \
16+
-v /home/data/data:/home/judge/data \
17+
-v /home/data/mysql:/var/lib/mysql \
18+
-v /home/data/upload:/home/judge/src/web/upload \
19+
-v /home/data/config:/home/judge/src/web/config \
20+
--name hustoj -p 80:80 hustoj
21+
22+
#docker run -d -it \
23+
#-v /home/data/data:/home/judge/data \
24+
#-v /home/data/upload:/home/judge/src/web/upload \
25+
#-v /home/data/mysql:/var/lib/mysql \
26+
#--name hustoj -p 80:80 hustoj
27+
28+
#
29+
#docker run -d -it --name hustoj -p 80:80 hustoj
30+
#docker exec -i -t hustoj /bin/bash
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
service nginx start
3+
chown -R mysql:mysql /var/lib/mysql
4+
5+
DIRECTORY="/var/lib/mysql"
6+
if [ "`ls -A $DIRECTORY`" = "" ]; then
7+
cp -R /home/mysql/* /var/lib/mysql/
8+
fi
9+
10+
DIRECTORY="/home/judge/src/web/config"
11+
if [ "`ls -A $DIRECTORY`" = "" ]; then
12+
cp -R /home/config/* /home/judge/src/web/config
13+
fi
14+
15+
chown -R mysql:mysql /var/lib/mysql
16+
service mysql start
17+
18+
dir="/var/lib/mysql/jol"
19+
if [ ! -d $dir ]; then
20+
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
21+
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
22+
mysql -h localhost -u$USER -p$PASSWORD< /home/judge/src/install/db.sql
23+
echo "insert into jol.privilege values('admin','administrator','N');"|mysql -h localhost -u$USER -p$PASSWORD
24+
else
25+
cp /home/judge/src/web/config/db_info.inc.php /home/judge/src/web/include/db_info.inc.php
26+
fi
27+
28+
if [ -f /home/judge/src/web/config/db_info.inc.php ]; then
29+
cp /home/judge/src/web/config/db_info.inc.php /home/judge/src/web/include/db_info.inc.php
30+
else
31+
cp /home/judge/src/web/include/db_info.inc.php /home/judge/src/web/config/db_info.inc.php
32+
fi
33+
34+
if [ -f /home/judge/src/web/config/judge.conf ]; then
35+
cp /home/judge/src/web/config/judge.conf /home/judge/etc/judge.conf
36+
else
37+
cp /home/judge/etc/judge.conf /home/judge/src/web/config/judge.conf
38+
fi
39+
40+
41+
php5-fpm
42+
/usr/bin/judged
43+
chmod 775 -R /home/judge/data && chgrp -R www-data /home/judge/data
44+
chmod 770 -R /home/judge/src/web/upload && chgrp -R www-data /home/judge/src/web/upload
45+
chmod 770 -R /home/judge/src/web/config && chgrp -R /home/judge/src/web/config
46+
/bin/bash
47+
exit 0
48+
49+

trunk/docker/hustoj/sources.list

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
2+
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
3+
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
4+
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
5+
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
6+
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
7+
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
8+
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
9+
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
10+
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

trunk/install/db.sql

100755100644
File mode changed.

trunk/web/config/db_info.inc.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php @session_start();
2+
ini_set("display_errors","Off"); //set this to "On" for debugging ,especially when no reason blank shows up.
3+
ini_set("session.cookie_httponly", 1);
4+
header('X-Frame-Options:SAMEORIGIN');
5+
6+
//for people using hustoj out of China , be careful of the last two line of this file !
7+
8+
// connect db
9+
static $DB_HOST="localhost";
10+
static $DB_NAME="jol";
11+
static $DB_USER="root";
12+
static $DB_PASS="root";
13+
14+
static $OJ_NAME="HUSTOJ";
15+
static $OJ_HOME="./";
16+
static $OJ_ADMIN="root@localhost";
17+
static $OJ_DATA="/home/judge/data";
18+
static $OJ_BBS="discuss3";//"bbs" for phpBB3 bridge or "discuss" for mini-forum
19+
static $OJ_ONLINE=false;
20+
static $OJ_LANG="cn";
21+
static $OJ_SIM=false;
22+
static $OJ_DICT=false;
23+
static $OJ_LANGMASK=0; //1mC 2mCPP 4mPascal 8mJava 16mRuby 32mBash 1008 for security reason to mask all other language
24+
static $OJ_EDITE_AREA=true;//true: syntax highlighting is active
25+
static $OJ_AUTO_SHARE=false;//true: One can view all AC submit if he/she has ACed it onece.
26+
static $OJ_CSS="white.css";
27+
static $OJ_SAE=false; //using sina application engine
28+
static $OJ_VCODE=false;
29+
static $OJ_APPENDCODE=false;
30+
static $OJ_CE_PENALTY=false;
31+
static $OJ_MEMCACHE=false;
32+
static $OJ_MEMSERVER="127.0.0.1";
33+
static $OJ_MEMPORT=11211;
34+
static $OJ_REDIS=false;
35+
static $OJ_REDISSERVER="127.0.0.1";
36+
static $OJ_REDISPORT=6379;
37+
static $OJ_REDISQNAME="hustoj";
38+
static $SAE_STORAGE_ROOT="http://hustoj-web.stor.sinaapp.com/";
39+
static $OJ_TEMPLATE="bs3"; //使用的默认模板
40+
if(isset($_GET['tp'])) $OJ_TEMPLATE=$_GET['tp'];
41+
static $OJ_LOGIN_MOD="hustoj";
42+
static $OJ_REGISTER=true; //允许注册新用户
43+
static $OJ_REG_NEED_CONFIRM=false; //新注册用户需要审核
44+
static $OJ_RANK_LOCK_PERCENT=0; //比赛封榜时间比例
45+
static $OJ_SHOW_DIFF=false; //是否显示WA的对比说明
46+
static $OJ_TEST_RUN=false; //提交界面是否允许测试运行
47+
static $OJ_BLOCKLY=false; //是否启用Blockly界面
48+
static $OJ_ENCODE_SUBMIT=false; //是否启用base64编码提交的功能,用来回避WAF防火墙误拦截。
49+
static $OJ_OPENID_PWD = '8a367fe87b1e406ea8e94d7d508dcf01';
50+
51+
/* weibo config here */
52+
static $OJ_WEIBO_AUTH=false;
53+
static $OJ_WEIBO_AKEY='1124518951';
54+
static $OJ_WEIBO_ASEC='df709a1253ef8878548920718085e84b';
55+
static $OJ_WEIBO_CBURL='http://192.168.0.108/JudgeOnline/login_weibo.php';
56+
57+
/* renren config here */
58+
static $OJ_RR_AUTH=false;
59+
static $OJ_RR_AKEY='d066ad780742404d85d0955ac05654df';
60+
static $OJ_RR_ASEC='c4d2988cf5c149fabf8098f32f9b49ed';
61+
static $OJ_RR_CBURL='http://192.168.0.108/JudgeOnline/login_renren.php';
62+
/* qq config here */
63+
static $OJ_QQ_AUTH=false;
64+
static $OJ_QQ_AKEY='1124518951';
65+
static $OJ_QQ_ASEC='df709a1253ef8878548920718085e84b';
66+
static $OJ_QQ_CBURL='192.168.0.108';
67+
68+
//if(date('H')<5||date('H')>21||isset($_GET['dark'])) $OJ_CSS="dark.css";
69+
if( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'],"zh-CN")) {
70+
$OJ_LANG="cn";
71+
}
72+
if (isset($_SESSION[$OJ_NAME.'_'.'OJ_LANG'])) $OJ_LANG=$_SESSION[$OJ_NAME.'_'.'OJ_LANG'];
73+
74+
75+
function pdo_query($sql){
76+
$num_args = func_num_args();
77+
$args = func_get_args(); //获得传入的所有参数的数组
78+
$args=array_slice($args,1,--$num_args);
79+
80+
global $DB_HOST,$DB_NAME,$DB_USER,$DB_PASS,$dbh,$OJ_SAE;
81+
if(!$dbh){
82+
83+
if(isset($OJ_SAE)&&$OJ_SAE) {
84+
$OJ_DATA="saestor://data/";
85+
// for sae.sina.com.cn
86+
$DB_NAME=SAE_MYSQL_DB;
87+
$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"));
88+
}else{
89+
$dbh=new PDO("mysql:host=".$DB_HOST.';dbname='.$DB_NAME, $DB_USER, $DB_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
90+
}
91+
92+
}
93+
94+
$sth = $dbh->prepare($sql);
95+
$sth->execute($args);
96+
$result=array();
97+
if(stripos($sql,"select") === 0){
98+
$result=$sth->fetchAll();
99+
}else if(stripos($sql,"insert") === 0){
100+
$result=$dbh->lastInsertId();
101+
}else{
102+
$result=$sth->rowCount();
103+
}
104+
//print_r($result);
105+
$sth->closeCursor();
106+
return $result;
107+
}
108+
// use db
109+
//pdo_query("set names utf8");
110+
111+
if(isset($OJ_CSRF)&&$OJ_CSRF&&$OJ_TEMPLATE=="bs3"&&basename($_SERVER['PHP_SELF'])!="problem_judge")
112+
require_once('csrf_check.php');
113+
114+
//sychronize php and mysql server with timezone settings, dafault setting for China
115+
//if you are not from China, comment out these two lines or modify them.
116+
//date_default_timezone_set("PRC");
117+
//pdo_query("SET time_zone ='+8:00'");
118+
119+
?>

0 commit comments

Comments
 (0)