Skip to content

Commit

Permalink
initial commit mysql service (#33)
Browse files Browse the repository at this point in the history
* initial commit mysql service

* moved mysql service to it's own section in /src

* moved mysql folder to src/databases/mysql

* updated reusable workflow
  • Loading branch information
noMoreCLI authored Dec 17, 2024
1 parent cfcd820 commit be39c45
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-images-on-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- "src/loaders/**"
- "src/services/**"
- "src/databases/**"
- ".version"
- ".github/workflows/reusable-build-container-images.yml"
- ".github/workflows/build-images-on-commit.yml"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-images-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- "src/loaders/**"
- "src/services/**"
- "src/databases/**"
- ".version"
- ".github/workflows/reusable-build-container-images.yml"
- ".github/workflows/check.yml"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-build-container-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
name: loaders-curl
- context: ./src/services/java
name: services-java
- context: ./src/databases/mysql
name: databases-mysql
steps:
- name: Checkout
uses: actions/[email protected]
Expand Down
10 changes: 10 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ for DIR in "${REPO_DIR}/src/services"/*; do
fi
done

for DIR in "${REPO_DIR}/src/databases"/*; do
if [ -d "$DIR" ]; then
IMAGE_TAG="${REPO_PREFIX}/${IMAGE_PREFIX}-databases-$(basename "$DIR"):$VERSION"
echo "Building $IMAGE_TAG..."
echo "Running 'docker buildx build --platform $PLATFORM -t $IMAGE_TAG $DIR $PUSH'"
docker buildx build --platform "$PLATFORM" -t "$IMAGE_TAG" $PUSH "$DIR" $PUSH
fi
done

for DIR in "${REPO_DIR}/src/loaders"/*; do
if [ -d "$DIR" ]; then
IMAGE_TAG="${REPO_PREFIX}/${IMAGE_PREFIX}-loaders-$(basename "$DIR"):$VERSION"
Expand All @@ -64,3 +73,4 @@ for DIR in "${REPO_DIR}/src/loaders"/*; do
docker buildx build --platform "$PLATFORM" -t "$IMAGE_TAG" $PUSH "$DIR" $PUSH
fi
done

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 be39c45

Please sign in to comment.