From 1bfc8feebebd5a32287c553a23fc1dcde55cecc7 Mon Sep 17 00:00:00 2001 From: Maurits van der Schee Date: Mon, 2 Mar 2020 13:51:15 +0100 Subject: [PATCH] Add Ubuntu 20.04 for Docker tests --- README.md | 12 ++++++++ docker/ubuntu20/Dockerfile | 20 +++++++++++++ docker/ubuntu20/run.sh | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 docker/ubuntu20/Dockerfile create mode 100755 docker/ubuntu20/run.sh diff --git a/README.md b/README.md index f946767..9f64645 100644 --- a/README.md +++ b/README.md @@ -1158,6 +1158,17 @@ To run the docker tests run "build_all.sh" and "run_all.sh" from the docker dire mysql: 100 tests ran in 4327 ms, 0 failed pgsql: 100 tests ran in 1396 ms, 0 failed sqlsrv: skipped, driver not loaded + ================================================ + Ubuntu 20.04 (PHP 7.3) + ================================================ + [1/4] Starting MySQL 8.0 ........ done + [2/4] Starting PostgreSQL 12 .... done + [3/4] Starting SQLServer 2017 ... skipped + [4/4] Cloning PHP-CRUD-API v2 ... skipped + ------------------------------------------------ + mysql: 100 tests ran in 4327 ms, 0 failed + pgsql: 100 tests ran in 1396 ms, 0 failed + sqlsrv: skipped, driver not loaded The above test run (including starting up the databases) takes less than 5 minutes on my slow laptop. @@ -1166,6 +1177,7 @@ The above test run (including starting up the databases) takes less than 5 minut 2) debian9 3) ubuntu16 4) ubuntu18 + 5) ubuntu20 > 4 ================================================ Ubuntu 18.04 (PHP 7.2) diff --git a/docker/ubuntu20/Dockerfile b/docker/ubuntu20/Dockerfile new file mode 100644 index 0000000..0266908 --- /dev/null +++ b/docker/ubuntu20/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:20.04 + +ARG DEBIAN_FRONTEND=noninteractive + +# install: php / mysql / postgres / tools +RUN apt-get update && apt-get -y install \ +php-cli php-xml \ +mysql-server mysql-client php-mysql \ +postgresql php-pgsql \ +postgresql-12-postgis-3 \ +git wget + +# install locales +RUN apt-get -y install locales +RUN locale-gen en_US.UTF-8 +RUN update-locale LANG=en_US.UTF-8 + +# install run script +ADD run.sh /usr/sbin/docker-run +CMD docker-run diff --git a/docker/ubuntu20/run.sh b/docker/ubuntu20/run.sh new file mode 100755 index 0000000..158d6fa --- /dev/null +++ b/docker/ubuntu20/run.sh @@ -0,0 +1,60 @@ +#!/bin/bash +echo "================================================" +echo " Ubuntu 20.04 (PHP 7.3)" +echo "================================================" + +echo -n "[1/4] Starting MySQL 8.0 ........ " +# make sure mysql can create socket and lock +mkdir /var/run/mysqld && chmod 777 /var/run/mysqld +# run mysql server +nohup mysqld > /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 WITH MYSQL_NATIVE_PASSWORD BY 'php-crud-api'; +GRANT ALL PRIVILEGES ON `php-crud-api`.* TO 'php-crud-api'@'localhost' WITH GRANT OPTION; +FLUSH PRIVILEGES; +EOF +echo "done" + +echo -n "[2/4] Starting PostgreSQL 12 .... " +# ensure statistics can be written +mkdir /var/run/postgresql/10-main.pg_stat_tmp/ && chmod 777 /var/run/postgresql/10-main.pg_stat_tmp/ +# run postgres server +nohup su - -c "/usr/lib/postgresql/12/bin/postgres -D /etc/postgresql/12/main" 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"; +\c "php-crud-api"; +CREATE EXTENSION IF NOT EXISTS postgis; +\q +EOF +echo "done" + +echo -n "[3/4] Starting SQLServer 2017 ... " +echo "skipped" + +echo -n "[4/4] Cloning PHP-CRUD-API v2 ... " +# install software +if [ -d /php-crud-api ]; then + echo "skipped" +else + git clone --quiet https://github.com/mevdschee/php-crud-api.git + echo "done" +fi + +echo "------------------------------------------------" + +# run the tests +cd php-crud-api +php test.php