Added centos7 to docker

This commit is contained in:
Maurits van der Schee 2017-08-07 13:19:41 +02:00
commit 47c09cdd6f
4 changed files with 82 additions and 0 deletions

10
docker/centos7/Dockerfile Normal file
View file

@ -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

24
docker/centos7/install.sh Executable file
View file

@ -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

11
docker/centos7/packages.sh Executable file
View file

@ -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

37
docker/centos7/run.sh Executable file
View file

@ -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