Skip to content

Commit

Permalink
Added Docker config
Browse files Browse the repository at this point in the history
For now have added docker-compose.yml keeping development in mind.
Will soon update it to support docker secrets and add a yml file
that can be use in production environment.
  • Loading branch information
pushkar8723 committed Nov 14, 2018
1 parent 051021d commit 693eb8a
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DB/2015_05-04_01_aurora_main.sql
Expand Up @@ -45,7 +45,7 @@ INSERT INTO `admin` (`variable`, `value`) VALUES
('endtime', '0'),
('starttime', '0'),
('port', '8723'),
('ip', '127.0.0.1');
('ip', 'judge');
-- --------------------------------------------------------

--
Expand Down
1 change: 1 addition & 0 deletions DB/2017_04_15_01_currentContest_variable.sql
@@ -1,2 +1,3 @@
USE `aurora_main`;
INSERT INTO `admin` (`variable`, `value`) VALUES
('currentContest', 'test');
1 change: 1 addition & 0 deletions DB/2017_04_15_02_sample_input_output_field.sql
@@ -1,2 +1,3 @@
USE `aurora_main`;
ALTER TABLE problems add `sampleinput` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE problems add `sampleoutput` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci;
26 changes: 17 additions & 9 deletions Judge/Dockerfile
@@ -1,25 +1,33 @@
# DOCKER-VERSION 1.12.0
FROM debian:latest
FROM ubuntu:latest
ARG DEBIAN_FRONTEND=noninteractive
# INSTALL COMPILERS
RUN apt-get update && apt-get install -y \
openjdk-7-jdk \
openjdk-8-jdk \
g++ \
python \
python3 \
perl \
locales \
php5 \
php \
ruby \
rhino \
fpc \
mono-complete \
bc hsbrainfuck \
mono-complete mono-mcs \
bf bc \
psmisc \
python3-pip
RUN locale-gen "en_US.UTF-8"
COPY requirements.txt /tmp/
RUN pip3 install --requirement /tmp/requirements.txt
COPY judge.py /judge/
RUN mkdir /judge/env
RUN mkdir /judge/io_cache
CMD ["python3", "/judge/judge.py"]
RUN chmod 700 /tmp
RUN useradd -m -u 8723 -s /bin/bash judge
WORKDIR /home/judge
RUN mkdir env io_cache
RUN chmod 755 env
RUN chmod 700 io_cache
RUN chown judge env
RUN chgrp judge env
COPY judge.py /home/judge/
EXPOSE 8723
CMD ["python3", "judge.py", "-judge", "-cache"]
18 changes: 11 additions & 7 deletions Judge/judge.py
Expand Up @@ -10,13 +10,17 @@
sys.exit(0);

timeoffset = 0

def getEnv(key, default):
return os.environ[key] if key in os.environ else default

# Initialize Database and judge Constants
sql_hostname = '127.0.0.1'
sql_hostport = 3306
sql_username = 'aurora'
sql_password = 'aurora'
sql_database = 'aurora_main'
HOST, PORT = "127.0.0.1", 8723
sql_hostname = getEnv('AURORA_SQL_HOSTNAME', '127.0.0.1')
sql_hostport = getEnv('AURORA_SQL_HOSTPORT', 3306)
sql_username = getEnv('AURORA_SQL_USERNAME', 'aurora')
sql_password = getEnv('AURORA_SQL_PASSWORD', 'aurora')
sql_database = getEnv('AURORA_SQL_DATABASE', 'aurora_main')
HOST, PORT = "0.0.0.0", 8723
#timeoffset = 19800

# Initialize Language Constants
Expand All @@ -31,7 +35,7 @@
"Brain" : {"extension": "b", "system":"find /usr/bin/ -name bf", "execute":"bf env/[exename].b[inputfile]"},
"C" : {"extension":"c", "system":"find /usr/bin/ -name cc", "compile":"cc env/[codefilename].c -O2 -fomit-frame-pointer -o env/[codefilename] -lm"+ioeredirect, "execute":"env/[exename][inputfile]"},
"C++": {"extension": "cpp", "system": "find /usr/bin/ -name g++", "compile": "g++ env/[codefilename].cpp -O2 -fomit-frame-pointer -o env/[codefilename]"+ioeredirect, "execute": "env/[exename][inputfile]"},
"C#" : {"extension": "cs", "system":"find /usr/bin/ -name gmcs", "compile":"gmcs env/[codefilename].cs -out:env/[codefilename].exe"+ioeredirect, "execute":"mono env/[exename].exe[inputfile]"},
"C#" : {"extension": "cs", "system":"find /usr/bin/ -name mcs", "compile":"mcs env/[codefilename].cs -out:env/[codefilename].exe"+ioeredirect, "execute":"mono env/[exename].exe[inputfile]"},
"Java" : {"extension" : "java", "system":"find /usr/bin/ -name javac", "compile":"javac -g:none -Xlint -d env env/[codefilename].java"+ioeredirect, "execute":"java -client -classpath env [exename][inputfile]"},
"JavaScript": {"extension":"js", "system": "find /usr/bin/ -name rhino", "execute":"rhino -f env/[exename].js[inputfile]"},
"Pascal": {"extension":"pas", "system":"find /usr/bin/ -name fpc", "compile":"fpc env/[codefilename].pas -O2 -oenv/[codefilename]"+ioeredirect, "execute":"env/[exename][inputfile]"},
Expand Down
24 changes: 24 additions & 0 deletions Web Interface/Dockerfile
@@ -0,0 +1,24 @@
FROM php:7.2-apache

RUN apt-get update && apt-get install -y --no-install-recommends libxml++2.6-dev \
zlib1g-dev libicu-dev g++ libssl-dev git \
&& pecl install apcu-5.1.5 && \
docker-php-ext-enable apcu && \
docker-php-ext-install \
intl \
mbstring \
pdo_mysql \
zip \
bcmath \
opcache \
&& docker-php-ext-install -j "$(nproc)" mbstring pdo tokenizer xml zip \
&& a2enmod rewrite

WORKDIR /var/www/html

COPY . /var/www/html

EXPOSE 80
EXPOSE 443

CMD apache2-foreground
21 changes: 12 additions & 9 deletions Web Interface/config.php
@@ -1,11 +1,15 @@
<?php
function getEnvVar($key, $default) {
return getenv($key) ? getenv($key) : $default;
}

// Change the following parameters according to the instructions beside them
define("SITE_URL", "http://" . $_SERVER['HTTP_HOST'] . "/aurora"); // path to directory
define("SQL_USER", "aurora"); // Database username
define("SQL_PASS", "aurora"); // Database password
define("SQL_DB", "aurora_main"); // Database name
define("SQL_HOST", "127.0.0.1"); // Database host
define("SQL_PORT", "3306"); // Database port
define("SITE_URL", "http://" . $_SERVER['HTTP_HOST']); // path to directory
define("SQL_USER", getEnvVar("AURORA_SQL_USER", "aurora")); // Database username
define("SQL_PASS", getEnvVar("AURORA_SQL_PASS", "aurora")); // Database password
define("SQL_DB", getEnvVar("AURORA_SQL_DB", "aurora_main")); // Database name
define("SQL_HOST", getEnvVar("AURORA_SQL_HOST", "127.0.0.1")); // Database host
define("SQL_PORT", getEnvVar("AURORA_SQL_PORT", "3306")); // Database port
displayErrors(FALSE); // Display PHP errors or not.
date_default_timezone_set("Asia/Kolkata"); //Set your timezone, resolves most timer errors
// Language specific variables
Expand All @@ -20,10 +24,9 @@
*
*
*/

session_start();
session_set_cookie_params (0, substr(SITE_URL, strlen("http://" . $_SERVER['HTTP_HOST'])));
ini_set("session.gc_maxlifetime", 86400);
session_set_cookie_params (0, substr(SITE_URL, strlen("http://" . $_SERVER['HTTP_HOST'])));
session_start();
function displayErrors($option = true) {
if ($option) {
error_reporting(E_ALL | E_STRICT);
Expand Down
3 changes: 0 additions & 3 deletions Web Interface/process.php
Expand Up @@ -24,13 +24,10 @@ function customhash($str) {
$_POST['teamname'] = addslashes($_POST['teamname']);
$_POST['password'] = customhash(addslashes($_POST['password']));
$query = "select * from teams where teamname = '$_POST[teamname]' and pass = '$_POST[password]'";
echo $query;
$res = DB::findOneFromQuery($query);
if ($res && ($res['status'] == 'Normal' || $res['status'] == 'Admin')) {
$save = $_SESSION;
session_destroy();
session_regenerate_id(true);
session_start();
$_SESSION = $save;
$_SESSION['team']['id'] = $res['tid'];
$_SESSION['team']['name'] = $res['teamname'];
Expand Down
13 changes: 13 additions & 0 deletions conf/000-default.conf
@@ -0,0 +1,13 @@
<VirtualHost *:80 *:443>
ServerAdmin admin@aurora.pushkaranand.com
DocumentRoot "/var/www/html/"
ServerName aurora.pushkaranand.com
ServerName localhost
<Directory "/var/www/html/">
Options FollowSymLinks
AllowOverride All

Order allow,deny
Allow from all
</Directory>
</VirtualHost>
35 changes: 35 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,35 @@
version: '2'

services:
mysql:
image: mysql:5
volumes:
- ./DB:/docker-entrypoint-initdb.d
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=aurora

web:
build: ./Web Interface
image: pushkar8723/aurora-web
ports:
- 80:80
environment:
- AURORA_SQL_USER=root
- AURORA_SQL_PASS=aurora
- AURORA_SQL_DB=aurora_main
- AURORA_SQL_HOST=mysql
volumes:
- ./conf:/etc/apache2/sites-enabled

judge:
build: ./Judge
image: pushkar8723/aurora-judge
ports:
- 8723:8723
environment:
- AURORA_SQL_HOSTNAME=mysql
- AURORA_SQL_USERNAME=root
- AURORA_SQL_PASSWORD=aurora
- AURORA_SQL_DATABASE=aurora_main

0 comments on commit 693eb8a

Please sign in to comment.