From bc52bc889a2e14280b551b0cd0bd49f1e9744647 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 1 Feb 2017 19:04:40 +0100 Subject: [PATCH] Docker config to host botsarena on a container --- Dockerfile | 34 ++++++++++++++ README.md | 12 +++-- dockerConfig/populate_mysql.sh | 17 +++++++ dockerConfig/run.sh | 14 ++++++ install.sql | 85 ++++++++++++++++++++++++++-------- src/PHPMailer | 1 - src/act.php | 2 +- src/arenas/tron/functions.php | 2 + src/config.php.empty | 8 ++-- 9 files changed, 144 insertions(+), 31 deletions(-) create mode 100644 Dockerfile create mode 100644 dockerConfig/populate_mysql.sh create mode 100644 dockerConfig/run.sh mode change 100755 => 100644 install.sql delete mode 160000 src/PHPMailer diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b9494b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +#Docker image hosting botsarena + +FROM tutum/lamp:latest + +MAINTAINER Gnieark https://blog-du-grouik.tinad.fr + + +RUN apt-get update && \ + apt-get install -q -y php5-curl + +#delete symbolic linc +RUN rm /var/www/html && \ + mkdir /var/www/html + +#Copy bots arena code +COPY html/ /var/www/html/ +COPY src/ /var/www/src/ +COPY lang /var/www/lang/ + +#Some config and mysql scripts +ADD dockerConfig/populate_mysql.sh /populate_mysql.sh + +RUN cp /var/www/src/config.php.empty /var/www/src/config.php && \ + chmod +x /populate_mysql.sh && \ + chown -R www-data:www-data /var/www + +EXPOSE 80 3306 + +ADD install.sql /install.sql +RUN rm /run.sh +ADD dockerConfig/run.sh /run.sh +RUN chmod +x /run.sh + +CMD ["/run.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 7e01c7f..d6c08f6 100755 --- a/README.md +++ b/README.md @@ -14,13 +14,15 @@ You are welcome, Make pull requests on branch dev. Im available on twitter [@gni # install it I'd better like you to help me to improve [bot's Arena](https://botsarena.tinad.fr/), and you to make your own bots to play challenges. It would be more funny having lot of bots in one arena rather than lot of arenas. -* Mysql structure is in the .sql -* Apache/tomcat document root starts at ./html -* copy src/config.php.empty to src/config.php +See dockerFile and associated scripts to understand what is needed. -Apache RewriteRules are given on the file html/.htaccess +To test an image of bots arena with docker: -For nginx in server directive: + make + docker build . + docker run --name hey -p 127.0.0.1:8080:80 DockerImageId + +For nginx Rewrite rules in server directive are: rewrite '^/([a-zA-Z]{1,})/doc-([a-z]{2})$' /index.php?doc=$1&lang=$2 last; rewrite '^/p/([a-zA-Z]{1,})/(.*)-([a-z]{2})$' /index.php?page=$1¶ms=$2&lang=$3 last; diff --git a/dockerConfig/populate_mysql.sh b/dockerConfig/populate_mysql.sh new file mode 100644 index 0000000..d9b82dc --- /dev/null +++ b/dockerConfig/populate_mysql.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +/usr/bin/mysqld_safe > /dev/null 2>&1 & + +RET=1 +while [[ RET -ne 0 ]]; do + echo "=> Waiting for confirmation of MySQL service startup" + sleep 5 + mysql -uroot -e "status" > /dev/null 2>&1 + RET=$? +done +mysql -u root -e "CREATE database botsarena;" +mysql -u root -e "GRANT ALL on botsarena.* TO 'botsarena'@'localhost' IDENTIFIED BY 'botsPwd';" +mysql -u root botsarena < /install.sql + + +mysqladmin -uroot shutdown diff --git a/dockerConfig/run.sh b/dockerConfig/run.sh new file mode 100644 index 0000000..3d2f46d --- /dev/null +++ b/dockerConfig/run.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +VOLUME_HOME="/var/lib/mysql" + +sed -ri -e "s/^upload_max_filesize.*/upload_max_filesize = ${PHP_UPLOAD_MAX_FILESIZE}/" \ + -e "s/^post_max_size.*/post_max_size = ${PHP_POST_MAX_SIZE}/" /etc/php5/apache2/php.ini +if [[ ! -d $VOLUME_HOME/mysql ]]; then + mysql_install_db > /dev/null 2>&1 + /populate_mysql.sh +else + echo "=> Using an existing volume of MySQL" +fi + +exec supervisord -n diff --git a/install.sql b/install.sql old mode 100755 new mode 100644 index d4ccf65..a3e2e64 --- a/install.sql +++ b/install.sql @@ -1,24 +1,46 @@ +-- MySQL dump 10.13 Distrib 5.5.54, for debian-linux-gnu (x86_64) +-- +-- Host: localhost Database: botsarena +-- ------------------------------------------------------ +-- Server version 5.5.54-0+deb8u1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- --- Structure de la table `arena_history` +-- Table structure for table `arena_history` -- -CREATE TABLE IF NOT EXISTS `arena_history` ( +DROP TABLE IF EXISTS `arena_history`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `arena_history` ( `game` varchar(8) NOT NULL, `player1_id` int(11) NOT NULL, `player2_id` int(11) NOT NULL, `player1_winsCount` int(11) NOT NULL, `player2_winsCount` int(11) NOT NULL, `nulCount` int(11) NOT NULL, - PRIMARY KEY (`game`,`player1_id`,`player2_id`) -); - + PRIMARY KEY (`game`,`player1_id`,`player2_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; -- --- Structure de la table `bots` +-- Table structure for table `bots` -- -CREATE TABLE IF NOT EXISTS `bots` ( +DROP TABLE IF EXISTS `bots`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bots` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `game` varchar(10) NOT NULL, @@ -30,26 +52,33 @@ CREATE TABLE IF NOT EXISTS `bots` ( `validate_secret` varchar(8) NOT NULL, `author_email` text NOT NULL, `ELO` int(11) NOT NULL DEFAULT '1500', - PRIMARY KEY (`id`) -); - + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; -- --- Contenu de la table `bots` only stupid ias +-- Dumping data for table `bots` -- -INSERT INTO `bots` (`id`, `name`, `game`, `url`, `description`, `unclean_description`, `active`, `date_inscription`, `validate_secret`, `author_email`) VALUES -(2, 'stupidAI', 'tictactoe', 'https://ias.tinad.fr/stupidIATictactoe.php', '', '', 1, '2015-12-03 10:55:34', '', ''), -(3, 'stupidAI', 'Battleship', 'https://botsArena.tinad.fr/StupidIABattleship.php', '', '', 1, '2015-12-11 11:16:50', '', ''), -(4, 'stupidAI', 'connectFou', 'https://ias.tinad.fr/StupidIAconnectFour.php', '', '', 1, '2016-05-11 07:47:57', '', ''); +LOCK TABLES `bots` WRITE; +/*!40000 ALTER TABLE `bots` DISABLE KEYS */; +INSERT INTO `bots` VALUES +(2,'stupidAI','tictactoe','https://ias.tinad.fr/stupidIATictactoe.php','This bot choose the cell to play simply by random.
\r\nSon code source: https://github.com/gnieark/IAS/blob/master/stupidIATictactoe.php','This bot choose the cell to play simply by random.\r\nSon code source: https://github.com/gnieark/IAS/blob/master/stupidIATictactoe.php',1,'2015-12-03 10:55:34','','',814), +(3,'stupidIA','Battleship','https://ias.tinad.fr/StupidIABattleship.php','','',1,'2015-12-11 11:16:50','','',1538), +(4,'stupidIA','connectFou','https://ias.tinad.fr/StupidIAconnectFour.php','','',1,'2016-05-11 07:47:57','','',2087), +(5,'stupidIa','tron','http://ias.localhost/stupidIATronBetter.php','','',1,'2016-06-29 07:20:08','','',1677); --- -------------------------------------------------------- +/*!40000 ALTER TABLE `bots` ENABLE KEYS */; +UNLOCK TABLES; -- --- Structure de la table `bots_modifs` +-- Table structure for table `bots_modifs` -- -CREATE TABLE IF NOT EXISTS `bots_modifs` ( +DROP TABLE IF EXISTS `bots_modifs`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bots_modifs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `real_id` int(11) NOT NULL, `name` text NOT NULL, @@ -60,7 +89,23 @@ CREATE TABLE IF NOT EXISTS `bots_modifs` ( `date_modification` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `validate_secret` varchar(8) NOT NULL, `author_email` text NOT NULL, - PRIMARY KEY (`id`); -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `bots_modifs` +-- + +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +-- Dump completed on 2017-02-01 8:09:06 diff --git a/src/PHPMailer b/src/PHPMailer deleted file mode 160000 index f97b9cd..0000000 --- a/src/PHPMailer +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f97b9cd3c2dcf348d110d17613a82614d1163ab5 diff --git a/src/act.php b/src/act.php index 4103c7d..d127730 100755 --- a/src/act.php +++ b/src/act.php @@ -200,4 +200,4 @@ switch($_POST['act']){ error(404,"erf"); break; -} +} \ No newline at end of file diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index b3d9bbc..50ae3d9 100755 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -1 +1,3 @@ "http://botsarena.tinad.fr/"); +$siteParam=array("BASEURL" => "http://localhost/"); $mysqlParams=array( 'host' => 'localhost', - 'user' => '', - 'pass' => '', - 'database'=>'' + 'user' => 'botsarena', + 'pass' => 'botsPwd', + 'database'=>'botsarena' ); $smtpParams=array( //exemple for gmail