diff --git a/db/Dockerfile b/db/Dockerfile new file mode 100644 index 0000000..eb4c744 --- /dev/null +++ b/db/Dockerfile @@ -0,0 +1,9 @@ +FROM mysql:latest + +ADD . /opt/uoj_db +WORKDIR /opt/uoj_db + +# Run the latest UOJ Community verison db install script +RUN sh install.sh + +ENV LANG=C.UTF-8 TZ=Asia/Shanghai diff --git a/install/judger/add_judger.sql b/db/add_judger.sql similarity index 100% rename from install/judger/add_judger.sql rename to db/add_judger.sql diff --git a/install/db/app_uoj233.sql b/db/app_uoj233.sql similarity index 100% rename from install/db/app_uoj233.sql rename to db/app_uoj233.sql diff --git a/install/db/install.sh b/db/install.sh similarity index 81% rename from install/db/install.sh rename to db/install.sh index 063cf41..4618093 100644 --- a/install/db/install.sh +++ b/db/install.sh @@ -21,8 +21,8 @@ setWebConf(){ cat >/docker-entrypoint-initdb.d/000-native_password.sql </docker-entrypoint-initdb.d/001-app_uoj233.sql - curl $RAW_URL/install/judger/add_judger.sql >/docker-entrypoint-initdb.d/002-add_judger.sql + cp app_uoj233.sql /docker-entrypoint-initdb.d/001-app_uoj233.sql + cp add_judger.sql /docker-entrypoint-initdb.d/002-add_judger.sql } echo 'Preparing UOJ System db environment...' diff --git a/install/compose/docker-compose.yml b/docker-compose.yml similarity index 78% rename from install/compose/docker-compose.yml rename to docker-compose.yml index a0d0f94..fbc9d96 100644 --- a/install/compose/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,9 @@ version: "3" services: uoj-db: - image: universaloj/uoj-system:db + build: + context: ./db/ + dockerfile: Dockerfile container_name: uoj-db restart: always volumes: @@ -12,7 +14,9 @@ services: - MYSQL_ROOT_PASSWORD=root uoj-judger: - image: universaloj/uoj-system:judger + build: + context: ./judger/ + dockerfile: Dockerfile container_name: uoj-judger restart: always stdin_open: true @@ -20,7 +24,7 @@ services: cap_add: - SYS_PTRACE volumes: - - ./uoj_data/judger/log:/opt/uoj/judger/log + - ./uoj_data/judger/log:/opt/uoj_judger/log environment: - UOJ_PROTOCOL=http - UOJ_HOST=uoj-web @@ -30,7 +34,9 @@ services: - SOCKET_PASSWORD=_judger_socket_password_ uoj-web: - image: universaloj/uoj-system:web + build: + context: ./ + dockerfile: web/Dockerfile container_name: uoj-web restart: always stdin_open: true diff --git a/install/bundle/Dockerfile b/install/bundle/Dockerfile deleted file mode 100644 index a661a07..0000000 --- a/install/bundle/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM ubuntu:20.04 -MAINTAINER MascoSkray -ARG CLONE_ADDFLAG - -WORKDIR /opt -#Update apt and install git -RUN apt-get update && apt-get install -y git -#Clone the latest UOJ Community verison to local -RUN git clone https://github.com/renbaoshuo/UOJ-System.git --depth 1 --single-branch ${CLONE_ADDFLAG} uoj -#Install environment and set startup script -RUN cd uoj/install/bundle && sh install.sh -p && echo "\ -#!/bin/sh\n\ -chown -R mysql:mysql /var/lib/mysql /var/run/mysqld\n\ -if [ ! -f \"/var/uoj_data/.UOJSetupDone\" ]; then\n\ - cd /opt/uoj/install/bundle && sh install.sh -i\n\ -fi\n\ -service ntp start\n\ -service mysql start\n\ -service apache2 start\n\ -su local_main_judger -c \"/opt/uoj/judger/judge_client start\"\n\ -exec bash\n" >/opt/up && chmod +x /opt/up - -ENV LANG=C.UTF-8 TZ=Asia/Shanghai -EXPOSE 80 3690 -CMD /opt/up diff --git a/install/bundle/hooks/build b/install/bundle/hooks/build deleted file mode 100644 index 63e2605..0000000 --- a/install/bundle/hooks/build +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -CLONE_ADDFLAG="-b $DOCKER_TAG" -if [ "$DOCKER_TAG" = "latest" ]; then - CLONE_ADDFLAG="-b master" -fi -docker build -t $IMAGE_NAME --build-arg CLONE_ADDFLAG="$CLONE_ADDFLAG" . diff --git a/install/bundle/install.sh b/install/bundle/install.sh deleted file mode 100644 index 6ff6168..0000000 --- a/install/bundle/install.sh +++ /dev/null @@ -1,162 +0,0 @@ -#!/bin/bash -genRandStr(){ - cat /dev/urandom | tr -dc [:alnum:] | head -c $1 -} -#Set some vars -_database_password_=root -_judger_socket_port_=2333 -_judger_socket_password_=$(genRandStr 32) -_main_judger_password_=$(genRandStr 32) - -getAptPackage(){ - printf "\n\n==> Getting environment packages\n" - #Set MySQL root password - export DEBIAN_FRONTEND=noninteractive - (echo "mysql-server mysql-server/root_password password $_database_password_";echo "mysql-server mysql-server/root_password_again password $_database_password_") | debconf-set-selections - #Update apt sources and install - dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg) - echo "deb http://ppa.launchpad.net/stesie/libv8/ubuntu bionic main" | tee /etc/apt/sources.list.d/stesie-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D858A0DF - apt-get update && apt-get install -y vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring php-gd php-intl php-xsl mysql-server cmake fp-compiler re2c libv8-7.5-dev libyaml-dev python python3 python3-requests openjdk-8-jdk openjdk-11-jdk - #Install PHP extensions - yes | pecl install yaml - git clone https://github.com/phpv8/v8js.git --depth=1 /tmp/pear/download/v8js-master && cd /tmp/pear/download/v8js-master - phpize && ./configure --with-php-config=/usr/bin/php-config --with-v8js=/opt/libv8-7.5 && make install && cd - -} - -setLAMPConf(){ - printf "\n\n==> Setting LAMP configs\n" - #Set Apache UOJ site conf - cat >/etc/apache2/sites-available/000-uoj.conf < - #ServerName local_uoj.ac - ServerAdmin opensource@uoj.ac - DocumentRoot /var/www/uoj - - SetEnvIf Request_URI "^/judge/.*$" judgelog - #LogLevel info ssl:warn - ErrorLog \${APACHE_LOG_DIR}/uoj_error.log - CustomLog \${APACHE_LOG_DIR}/uoj_judge.log common env=judgelog - CustomLog \${APACHE_LOG_DIR}/uoj_access.log combined env=!judgelog - - XSendFile On - XSendFilePath /var/uoj_data - XSendFilePath /var/www/uoj/app/storage - XSendFilePath /opt/uoj/judger/uoj_judger/include - -UOJEOF - #Enable modules and make UOJ site conf enabled - a2ensite 000-uoj.conf && a2dissite 000-default.conf - a2enmod rewrite headers && sed -i -e '172s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf - #Create UOJ session save dir and make PHP extensions available - mkdir --mode=733 /var/lib/php/uoj_sessions && chmod +t /var/lib/php/uoj_sessions - sed -i -e '912a\extension=v8js.so\nextension=yaml.so' /etc/php/7.4/apache2/php.ini - #Set MySQL user directory and connection config - usermod -d /var/lib/mysql/ mysql - cat >/etc/mysql/mysql.conf.d/uoj_mysqld.cnf < Setting web files\n" - #Set webroot path - ln -sf /opt/uoj/web /var/www/uoj - chown -R www-data /var/www/uoj/app/storage - #Set web config file - php -a < Setting judger files\n" - #Add local_main_judger user - useradd -m local_main_judger && usermod -a -G www-data local_main_judger - #Set uoj_data path - mkdir -p /var/uoj_data/upload - chown -R www-data:www-data /var/uoj_data - #Compile uoj_judger and set runtime - chown -R local_main_judger:local_main_judger /opt/uoj/judger - su local_main_judger <uoj_judger/include/uoj_work_path.h <../../judger/.conf.json < Doing initial config and start service\n" - #Replace password placeholders - sed -i -e "s/_main_judger_password_/$_main_judger_password_/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /opt/uoj/judger/.conf.json - sed -i -e "s/salt0/$(genRandStr 32)/g" -e "s/salt1/$(genRandStr 16)/g" -e "s/salt2/$(genRandStr 16)/g" -e "s/salt3/$(genRandStr 16)/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /var/www/uoj/app/.config.php - #Import judge_client to MySQL database - service mysql start - echo "insert into judger_info (judger_name, password) values (\"main_judger\", \"$_main_judger_password_\")" | mysql app_uoj233 -u root --password=$_database_password_ - #Using cli upgrade to latest - php /var/www/uoj/app/cli.php upgrade:latest - #Start services - service ntp restart - service mysql restart - service apache2 restart - su local_main_judger -c '/opt/uoj/judger/judge_client start' - #Touch SetupDone flag file - touch /var/uoj_data/.UOJSetupDone - printf "\n\n***Installation complete. Enjoy!***\n" -} - -prepProgress(){ - getAptPackage;setLAMPConf;setWebConf;setJudgeConf -} - -if [ $# -le 0 ]; then - echo 'Installing UOJ System bundle...' - prepProgress;initProgress -fi -while [ $# -gt 0 ]; do - case "$1" in - -p | --prep) - echo 'Preparing UOJ System bundle environment...' - prepProgress - ;; - -i | --init) - echo 'Initing UOJ System bundle...' - initProgress - ;; - -? | --*) - echo "Illegal option $1" - ;; - esac - shift $(( $#>0?1:0 )) -done diff --git a/install/db/Dockerfile b/install/db/Dockerfile deleted file mode 100644 index b0cc832..0000000 --- a/install/db/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM mysql:latest -MAINTAINER MascoSkray - -#Update apt and install curl -RUN apt-get update && apt-get install -y curl -#Run the latest UOJ Community verison db install script -RUN export RAW_URL=https://raw.githubusercontent.com/UniversalOJ/UOJ-System/master && curl $RAW_URL/install/db/install.sh | sh - -ENV LANG=C.UTF-8 TZ=Asia/Shanghai diff --git a/install/judger/Dockerfile b/install/judger/Dockerfile deleted file mode 100644 index aa7c123..0000000 --- a/install/judger/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM ubuntu:18.04 -MAINTAINER MascoSkray -ARG CLONE_ADDFLAG - -WORKDIR /opt -#Update apt and install git -RUN apt-get update && apt-get install -y git -#Clone the latest UOJ Community verison to local -RUN git clone https://github.com/renbaoshuo/UOJ-System.git --depth 1 --single-branch ${CLONE_ADDFLAG} uoj -#Install environment and set startup script -RUN cd uoj/install/judger && sh install.sh -p && echo "\ -#!/bin/sh\n\ -if [ ! -f \"/opt/uoj/judger/.conf.json\" ]; then\n\ - cd /opt/uoj/install/judger && sh install.sh -i\n\ -fi\n\ -service ntp start\n\ -su judger -c \"/opt/uoj/judger/judge_client start\"\n\ -exec bash\n" >/opt/up && chmod +x /opt/up - -ENV LANG=C.UTF-8 TZ=Asia/Shanghai -EXPOSE 2333 -CMD /opt/up diff --git a/install/web/Dockerfile b/install/web/Dockerfile deleted file mode 100644 index 8ad66d9..0000000 --- a/install/web/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM ubuntu:18.04 -MAINTAINER MascoSkray -ARG CLONE_ADDFLAG - -WORKDIR /opt -#Update apt and install git -RUN apt-get update && apt-get install -y git -#Clone the latest UOJ Community verison to local -RUN git clone https://github.com/renbaoshuo/UOJ-System.git --depth 1 --single-branch ${CLONE_ADDFLAG} uoj -#Install environment and set startup script -RUN cd uoj/install/web && sh install.sh -p && echo "\ -#!/bin/sh\n\ -if [ ! -f \"/var/uoj_data/.UOJSetupDone\" ]; then\n\ - cd /opt/uoj/install/web && sh install.sh -i\n\ -fi\n\ -service ntp start\n\ -service apache2 start\n\ -exec bash\n" >/opt/up && chmod +x /opt/up - -ENV LANG=C.UTF-8 TZ=Asia/Shanghai -EXPOSE 80 3690 -CMD /opt/up diff --git a/judger/Dockerfile b/judger/Dockerfile new file mode 100644 index 0000000..73fd52b --- /dev/null +++ b/judger/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:18.04 + +ARG CLONE_ADDFLAG + +ADD . /opt/uoj_judger +WORKDIR /opt/uoj_judger + +# Install environment and set startup script +RUN sh install.sh -p && echo "\ +#!/bin/sh\n\ +if [ ! -f \"/opt/uoj_judger/.conf.json\" ]; then\n\ + cd /opt/uoj_judger && sh install.sh -i\n\ +fi\n\ +service ntp start\n\ +su judger -c \"/opt/uoj_judger/judge_client start\"\n\ +exec bash\n" >/opt/up && chmod +x /opt/up + +ENV LANG=C.UTF-8 TZ=Asia/Shanghai +EXPOSE 2333 +CMD /opt/up diff --git a/judger/add_judger.sql b/judger/add_judger.sql new file mode 100644 index 0000000..164db47 --- /dev/null +++ b/judger/add_judger.sql @@ -0,0 +1,2 @@ +USE `app_uoj233`; +insert into judger_info (judger_name, password, ip) values ('compose_judger', '_judger_password_', 'uoj-judger'); diff --git a/install/judger/install.sh b/judger/install.sh similarity index 81% rename from install/judger/install.sh rename to judger/install.sh index bcebe99..c6bd61d 100644 --- a/install/judger/install.sh +++ b/judger/install.sh @@ -13,12 +13,12 @@ setJudgeConf(){ #Set uoj_data path mkdir /var/uoj_data_copy && chown judger /var/uoj_data_copy #Compile uoj_judger and set runtime - chown -R judger:judger /opt/uoj/judger + chown -R judger:judger /opt/uoj_judger su judger <uoj_judger/include/uoj_work_path.h < Doing initial config and start service\n" - #Check envs + # Check envs if [ -z "$UOJ_PROTOCOL" -o -z "$UOJ_HOST" -o -z "$JUDGER_NAME" -o -z "$JUDGER_PASSWORD" -o -z "$SOCKET_PORT" -o -z "$SOCKET_PASSWORD" ]; then echo "!! Environment variables not set! Please edit config file by yourself!" else - #Set judge_client config file - cat >../../judger/.conf.json <.conf.json </opt/up && chmod +x /opt/up + +ENV LANG=C.UTF-8 TZ=Asia/Shanghai +EXPOSE 80 3690 +CMD /opt/up diff --git a/install/web/install.sh b/web/install.sh similarity index 95% rename from install/web/install.sh rename to web/install.sh index a1a3422..2f41571 100644 --- a/install/web/install.sh +++ b/web/install.sh @@ -15,7 +15,7 @@ getAptPackage(){ dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg) echo "deb http://ppa.launchpad.net/stesie/libv8/ubuntu bionic main" | tee /etc/apt/sources.list.d/stesie-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D858A0DF apt-get update && apt-get install -y vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring php-gd php-intl php-xsl g++ cmake re2c libv8-7.5-dev libyaml-dev - #Install PHP extensions + # Install PHP extensions printf "/opt/libv8-7.5\n\n" | pecl install v8js yaml } @@ -50,10 +50,10 @@ UOJEOF setWebConf(){ printf "\n\n==> Setting web files\n" - #Set webroot path + # Set webroot path ln -sf /opt/uoj/web /var/www/uoj chown -R www-data /var/www/uoj/app/storage - #Set web config file + # Set web config file php -a <include/uoj_work_path.h <