Skip to content

Commit

Permalink
moved mysql folder to src/databases/mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
noMoreCLI committed Dec 17, 2024
1 parent 9e3b0f6 commit f8c94d5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/databases/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mysql:5.7

LABEL org.opencontainers.image.source=https://github.com/cisco-open/app-simulator
LABEL org.opencontainers.image.description="mysql database for app-simulator"
LABEL org.opencontainers.image.licenses=BSD-3-Clause

RUN yum install -y php-cli && yum clean all
COPY setup.php /tmp/
COPY setup.sh /docker-entrypoint-initdb.d/
33 changes: 33 additions & 0 deletions src/databases/mysql/setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
echo "Setup ...".PHP_EOL;

$config = json_decode($_SERVER['APP_CONFIG']);

$result = "";

foreach($config->databases as $database => $tables) {
$result .= "CREATE DATABASE ".$database.";".PHP_EOL;
$result .= "USE ".$database.";".PHP_EOL;
foreach($tables as $table => $columns) {
$result .="CREATE TABLE ".$table." (".PHP_EOL;
foreach($columns as $column) {
if($column === 'id') {
$result .= " ".$column." INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,".PHP_EOL;
} else {
$result .= " ".$column. " VARCHAR(255),".PHP_EOL;
}
}

$result = substr($result,0,-2).PHP_EOL;

$result .=') ENGINE=InnoDB;'.PHP_EOL;
}
}

echo '=====.PHP_EOL';

echo $result;

echo '=====.PHP_EOL';

file_put_contents("/tmp/create.sql",$result);
3 changes: 3 additions & 0 deletions src/databases/mysql/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
APP_CONFIG="$(</config.json)" php /tmp/setup.php
mysql -uroot -p${MYSQL_ROOT_PASSWORD} < /tmp/create.sql

0 comments on commit f8c94d5

Please sign in to comment.