diff --git a/docker/centos7/Dockerfile b/docker/centos7/Dockerfile new file mode 100644 index 0000000..40241fd --- /dev/null +++ b/docker/centos7/Dockerfile @@ -0,0 +1,10 @@ +FROM centos:7 + +ADD packages.sh /usr/sbin/docker-packages +RUN docker-packages + +ADD install.sh /usr/sbin/docker-install +RUN docker-install + +ADD run.sh /usr/sbin/docker-run +CMD docker-run \ No newline at end of file diff --git a/docker/centos7/install.sh b/docker/centos7/install.sh new file mode 100755 index 0000000..d219f8a --- /dev/null +++ b/docker/centos7/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# install software +cd /root; git clone https://github.com/mevdschee/php-crud-api.git +# download phpunit 4.8 for PHP < 5.6 +cd php-crud-api; wget https://phar.phpunit.de/phpunit-4.8.phar -O phpunit.phar +# copy dist config to config +cp tests/Config.php.dist tests/Config.php +# replace variables +sed -i 's/{{mysql_hostname}}/localhost/g' tests/Config.php +sed -i 's/{{mysql_username}}/php-crud-api/g' tests/Config.php +sed -i 's/{{mysql_password}}/php-crud-api/g' tests/Config.php +sed -i 's/{{mysql_database}}/php-crud-api/g' tests/Config.php +sed -i 's/{{pgsql_hostname}}/localhost/g' tests/Config.php +sed -i 's/{{pgsql_username}}/php-crud-api/g' tests/Config.php +sed -i 's/{{pgsql_password}}/php-crud-api/g' tests/Config.php +sed -i 's/{{pgsql_database}}/php-crud-api/g' tests/Config.php +sed -i 's/{{sqlite_hostname}}//g' tests/Config.php +sed -i 's/{{sqlite_username}}//g' tests/Config.php +sed -i 's/{{sqlite_password}}//g' tests/Config.php +sed -i 's/{{sqlite_database}}/tests\/sqlite.db/g' tests/Config.php +# move comments +sed -i 's/\/\* Uncomment/\/\/ Uncomment/g' tests/Config.php +sed -i "s/'SQLServer'/\/\* 'SQLServer'/g" tests/Config.php \ No newline at end of file diff --git a/docker/centos7/packages.sh b/docker/centos7/packages.sh new file mode 100755 index 0000000..55da06a --- /dev/null +++ b/docker/centos7/packages.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# update should not be needed +# yum -y upgdate +# install: php / mysql / postgres / sqlite / tools +yum -y install \ +php-cli php-xml \ +mariadb-server mariadb php-mysql \ +postgresql-server postgresql php-pgsql \ +sqlite php-sqlite3 \ +git wget \ No newline at end of file diff --git a/docker/centos7/run.sh b/docker/centos7/run.sh new file mode 100755 index 0000000..81982c7 --- /dev/null +++ b/docker/centos7/run.sh @@ -0,0 +1,37 @@ +# initialize mysql +mysql_install_db > /dev/null +chown -R mysql:mysql /var/lib/mysql +# run mysql server +nohup /usr/libexec/mysqld -u mysql > /root/mysql.log 2>&1 & +# wait for mysql to become available +while ! mysqladmin ping -hlocalhost >/dev/null 2>&1; do + sleep 1 +done +# create database and user on mysql +mysql -u root >/dev/null << 'EOF' +CREATE DATABASE `php-crud-api` CHARACTER SET utf8 COLLATE utf8_general_ci; +CREATE USER 'php-crud-api'@'localhost' IDENTIFIED BY 'php-crud-api'; +GRANT ALL PRIVILEGES ON `php-crud-api`.* TO 'php-crud-api'@'localhost' WITH GRANT OPTION; +FLUSH PRIVILEGES; +EOF + +# initialize postgresql +su - -c "/usr/bin/initdb --auth-local peer --auth-host password -D /var/lib/pgsql/data" postgres > /dev/null +# run postgres server +nohup su - -c "/usr/bin/postgres -D /var/lib/pgsql/data" postgres > /root/postgres.log 2>&1 & +# wait for postgres to become available +until su - -c "psql -U postgres -c '\q'" postgres >/dev/null 2>&1; do + sleep 1; +done +# create database and user on postgres +su - -c "psql -U postgres >/dev/null" postgres << 'EOF' +CREATE USER "php-crud-api" WITH PASSWORD 'php-crud-api'; +CREATE DATABASE "php-crud-api"; +GRANT ALL PRIVILEGES ON DATABASE "php-crud-api" to "php-crud-api"; +\q +EOF + +# run the tests +cd /root/php-crud-api +git pull +php phpunit.phar