TQ
dev.com

Blog about software development

Subscribe

PHP-CRUD-API now on Docker Hub

01 Aug 2020 - by 'Maurits van der Schee'

PHP-CRUD-API is an "automatic" API: software that turns your database into a REST API. This is possible thanks to database reflection (asking the database which tables and fields it has). Support for Docker and Docker Compose has been added and the Docker image is registered on Docker Hub.

Test using Docker

To do proper testing you may have to test the full matrix of all dependencies (PHP, MySQL, MariaDB, PostgreSQL, SQLite and SQL Server) and there corresponding versions. For PHP there are already 5 supported versions (7.0, 7.1, 7.2, 7.3 and 7.4), for MySQL there are 3 supported versions (5.6 5.7 and 8.0) and for PostgreSQL there are 9 supported versions (9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 10, 11 and 12). Only these combinations of these major versions would lead to 5 x 3 + 5 x 9 = 50 test runs.

In reality there are minor versions and many other dependencies (such as PostGIS). This makes that the number of combinations is growing rapidly and testing them all is unfeasible. Instead we would like to test only the most common combinations of versions. We find them by using the repository contents of certain versions of Linux distributions. Below you find the distributions with their repository versions:

These can be tested in only 6 x 3 = 18 test runs and the number is not growing at all! This also means that (for instance) PHP 7.1 is not tested, nor is PostgreSQL 9.4.

Install Docker on Ubuntu

Install docker using the following commands:

sudo apt install docker.io
sudo usermod -aG docker ${USER}

Note that you need to logout and login for the changes to take effect.

Official Docker image

There is a "Dockerfile" in the repository that is used to build an image at:

https://hub.docker.com/r/mevdschee/php-crud-api

It will be automatically build on every release. The "latest" tag points to the last release.

Run with Docker Compose

This repository also contains a "docker-compose.yml" file that you can install/build/run using:

sudo apt install docker-compose
docker-compose build
docker-compose up

This will setup a database (MySQL) and a webserver (Apache) and runs the application using the blog example data used in the tests.

Test the script (running in the container) by opening the following URL:

http://localhost:8080/records/posts/1

Enjoy!


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.