zoukankan      html  css  js  c++  java
  • docker 搭建 hustoj

    docker 搭建 hustoj

    hustoj 是个GPL开源的OJ,其提供了docker形式的安装方式。

    为执行方便,选择使用aliyun提供的docker镜像来加速安装。

    拉取镜像

    docker pull registry.cn-shanghai.aliyuncs.com/shiningrise/hustoj
    

    执行镜像

    docker run -d -it --name hustoj -p 9900:80 --privileged registry.cn-shanghai.aliyuncs.com/shiningrise/hustoj:latest
    

    9900 是物理机针对docker image 80端口的映射。

    访问本机如下地址即可开始使用 hustoj

    http://127.0.0.1:9900

    下载题库

    https://github.com/zhblue/freeproblemset/ 提供了免费的题库下载,如果觉得不够用,
    还可以去 http://tk.hustoj.com/ 作者提供的付费网站下载更多。

    使用本地磁盘volumn

    docker因为每次启动都是全新,为持久化,可以挂载一个本地目录给docker image。

    标准执行方式
    
    docker run -d -it 
        -v /data/docker/docker-wxy/data:/data 
        --privileged 
        --name hustoj 
        -p 80:80 shiningrise/hustoj:latest
    
    docker测试安装
    
    	docker run -d -it --name hustoj -p 80:80 --privileged shiningrise/hustoj:latest
    
    仅安装C++版本
    
    	docker run -d -it --name hustoj -p 80:80 --privileged shiningrise/hustoj:cpp
    

    执行docker shell

    $ docker ps
    CONTAINER ID        IMAGE                                                         COMMAND                  CREATED             STATUS              PORTS                  NAMES
    f111112222333        registry.cn-shanghai.aliyuncs.com/shiningrise/hustoj:latest   "/usr/local/bin/dock…"   About an hour ago   Up About an hour    0.0.0.0:9900->80/tcp   hustoj
    
    docker exec -it f111112222333 bash ## f111112222333 是当前docker 映像执行的实例id 
    

    进去之后可以通过 mysql 执行数据库操作等。

    hustoj 配置其它语言

    https://blog.csdn.net/yybird_/article/details/46050023

    配置python

    python默认即支持,但,有一些诡异的小地方。

    默认执行py是使用py3

    需要在开头注释写个 # python2 才行

    主要judge_client会读取源码,通过如下语句判断py是何种版本:

    void run_solution(int & lang, char * work_dir, int & time_lmt, int & usedtime,
            int & mem_lmt) {
        nice(19);
        int py2=execute_cmd("/bin/grep 'python2' Main.py");
        // now the user is "judger"
        chdir(work_dir);
    
         ....
    
            if(!py2){
                execl("/python2", "/python2", "Main.py", (char *) NULL);
            }else{
                execl("/python3", "/python3", "Main.py", (char *) NULL);
            }
    

    配置golang

    To be done

    源码阅读

    hustoj 的模块拆分很清晰:

    • web // php后端逻辑 + html/css/js前端
    • core 判题逻辑模块
      • judged 判题后台服务
      • judge_client 判题工作模块
      • shim 源码相似度检查(据说是外部引入)

    修改源码去除公告

    为方便理解源码,也方便自己使用搭建的oj,引入一个小任务,去除晃眼的公告。

    看到公告,第一反应是,先用chrome开发工具台找到飘来飘去的元素ID。它叫 <marquee>
    搜下源码,看到在 contest-header.php 里面有涉及。

    直接注掉 $view_marquee_msg 相关部分。

    <?php 
    // php-comment
    // $view_marquee_msg=file_get_contents($OJ_SAE?"saestor://web/msg.txt":"./admin/msg.txt");
    ?>
    <!-- html
    <div id=broadcast>
    <marquee id=broadcast scrollamount=1 direction=up scrolldelay=250 onMouseOver='this.stop()' onMouseOut='this.start()';>
      <?php echo $view_marquee_msg?>
    </marquee>
    </div>
    -->
    

    点击页面,依然没搞定。

    再找,发现 template/bs3/js.php 里面才是真正生成消息元素的部分。

    <?php
    if(file_exists("./admin/msg.txt"))
    $view_marquee_msg=file_get_contents($OJ_SAE?"saestor://web/msg.txt":"./admin/msg.txt");
    if(file_exists("../admin/msg.txt"))
    $view_marquee_msg=file_get_contents($OJ_SAE?"saestor://web/msg.txt":"../admin/msg.txt");
    ?>
    
    <script>
    $(document).ready(function(){
      var msg="<marquee style='margin-top:10px' id=broadcast direction='up' scrollamount=3 scrolldelay=50 onMouseOver='this.stop()'"+
          " onMouseOut='this.start()' class=toprow>"+<?php echo json_encode($view_marquee_msg); ?>+"</marquee>";
      $(".jumbotron").prepend(msg);
      $("form").append("<div id='csrf' />");
      $("#csrf").load("<?php echo $path_fix?>csrf.php");
      $("body").append("<div id=footer class=center >GPLv2 licensed by <a href='https://github.com/zhblue/hustoj' >HUSTOJ</a> "+(new Date()).getFullYear()+" </div>");
      $("body").append("<div class=center > <img src='http://hustoj.com/wx.jpg' width='96px'><img src='http://hustoj.com/alipay.png' width='96px'><br> 欢迎关注微信公众号onlinejudge</div>");
    });
    ///// .... 省略
    </script>
    

    将上面的php和js都给注掉,搞定。

    源码理解

    php 部分为方便理解,大概可以拆分如下2个模块:

    • 用户界面
    • admin界面

    为方便自定义,同时穿插了一套简单的主题模块。

    即,所有的css、js等前端相关,都使用了如下几个模板来嵌套。

    • bs bootstrap2?
    • bs3 bootstrap3
    • classic 经典款
    • ie IE兼容
    • sae 新浪SAE模式

    而php则通过主要的配置文件 include/db_info.inc.php 来指导工作。

  • 相关阅读:
    Longest Common Prefix
    Roman to Integer
    Intger to Roman
    Container With Most Water
    Regular Expression Matching
    atoi
    Rotate List
    54. Search a 2D Matrix && Climbing Stairs (Easy)
    53. Minimum Window Substring
    52. Sort Colors && Combinations
  • 原文地址:https://www.cnblogs.com/morya/p/9688421.html
Copyright © 2011-2022 走看看