diff --git a/homepage/cwsvJudo/participo/.gitignore b/homepage/cwsvJudo/participo/.gitignore new file mode 100644 index 0000000..be0af5a --- /dev/null +++ b/homepage/cwsvJudo/participo/.gitignore @@ -0,0 +1,6 @@ +# don't commit credentials +db_root_password.txt +db_password.txt +# sql dump shall be created new every time (from the productive system) +cwsvjudo.sql + diff --git a/homepage/cwsvJudo/participo/PHP.dockerfile b/homepage/cwsvJudo/participo/PHP.dockerfile new file mode 100644 index 0000000..e4efb2c --- /dev/null +++ b/homepage/cwsvJudo/participo/PHP.dockerfile @@ -0,0 +1,11 @@ +# select base image +FROM php:fpm + +# startup scripts for the image +# - docker-php-ext-install -- install helper script from PHP +RUN docker-php-ext-install pdo pdo_mysql + +# install and add xdebug extension +# @todo What is pecl? +# @todo What is xdebug and how do I use it? +RUN pecl install xdebug && docker-php-ext-enable xdebug \ No newline at end of file diff --git a/homepage/cwsvJudo/participo/app/public/mysql.php b/homepage/cwsvJudo/participo/app/public/mysql.php new file mode 100644 index 0000000..e05e40c --- /dev/null +++ b/homepage/cwsvJudo/participo/app/public/mysql.php @@ -0,0 +1,14 @@ + PDO::ERRMODE_EXCEPTION] +); + +$query = $pdo->query('SHOW VARIABLES like "version"'); + +$row = $query->fetch(); + +echo 'MYSQL version: '. $row['Value']; \ No newline at end of file diff --git a/homepage/cwsvJudo/participo/db_password.txt.template b/homepage/cwsvJudo/participo/db_password.txt.template new file mode 100644 index 0000000..21067f7 --- /dev/null +++ b/homepage/cwsvJudo/participo/db_password.txt.template @@ -0,0 +1 @@ +insert_MYSQL_PASSWORD_here_and_remove_template_in_filename \ No newline at end of file diff --git a/homepage/cwsvJudo/participo/db_root_password.txt.template b/homepage/cwsvJudo/participo/db_root_password.txt.template new file mode 100644 index 0000000..38316a2 --- /dev/null +++ b/homepage/cwsvJudo/participo/db_root_password.txt.template @@ -0,0 +1 @@ +insert_MYSQL_ROOT_PASSWORD_here_and_remove_template_in_filename \ No newline at end of file diff --git a/homepage/cwsvJudo/participo/docker-clean b/homepage/cwsvJudo/participo/docker-clean new file mode 100755 index 0000000..f938dbc --- /dev/null +++ b/homepage/cwsvJudo/participo/docker-clean @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +# stop all containers +docker-compose down --remove-orphans +# delete all containers +docker rm -f $(docker ps -a -q) +# delete all volumes +docker volume rm $(docker volume ls -q) diff --git a/homepage/cwsvJudo/participo/docker-compose.yml b/homepage/cwsvJudo/participo/docker-compose.yml index f428c2b..257c96f 100644 --- a/homepage/cwsvJudo/participo/docker-compose.yml +++ b/homepage/cwsvJudo/participo/docker-compose.yml @@ -1,8 +1,9 @@ # version for the docker compose file to use version: "3" + # a dict of services running in the container label: {} label is a self defined name for the service services: - # the web service + # the webserver service web: image: nginx:latest # port forwarding @@ -13,7 +14,60 @@ services: volumes: - ./nginx.conf:/etc/nginx/conf.d/nginx.conf - ./app:/app + # php and extensions php: - image: php:fpm + # use pre-build image from docker.. + # image: php:fpm + # .. or build your own image + build: + context: . + dockerfile: PHP.dockerfile + # files and directories to be available in the container + # @todo Except from better structuring: Is there a reason for not having the volumes as one central list? volumes: - ./app:/app + # install a dm + # @todo Maybe use postgre instead? + database: + image: mariadb:latest + restart: always + # define environment variables + # @todo Should credentials be placed here? Even if it is just a test environment + environment: + MYSQL_USER: 'cwsvjudo' + MYSQL_DATABASE: 'cwsvjudo' + MYSQL_TCP_PORT: '3306' + MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password + MYSQL_PASSWORD_FILE: /run/secrets/db_password + volumes: + - mysqldata:/var/lib/mysql + # initial database + # - has to be created first, e.g., by dumping the database from the prooductive system + - ./cwsvjudo.sql:/docker-entrypoint-initdb.d/cwsvjudo.sql + ports: + - 3306:3306 + secrets: + - db_root_password + - db_password + # phpmyadmin + phpmyadmin: + image: phpmyadmin:latest + restart: always + depends_on: + - database + ports: + - 8080:80 + environment: + # name of the host is the name of the db service started above! Why? I don't know! + - PMA_HOST=database + - PMA_PORT=3306 + # - PMA_ARBITRARY=1 +volumes: + # data storage for the db + mysqldata: {} + +secrets: + db_root_password: + file: db_root_password.txt + db_password: + file: db_password.txt diff --git a/homepage/cwsvJudo/participo/nginx.conf b/homepage/cwsvJudo/participo/nginx.conf index 1e41db9..69bc4f4 100644 --- a/homepage/cwsvJudo/participo/nginx.conf +++ b/homepage/cwsvJudo/participo/nginx.conf @@ -1,3 +1,4 @@ +# @todo Needs helpfull comments. server { listen 80 default_server; root /app/public;