I'm performing security testing on PHP source-code. The functionality of the script highly depends on the underlying infrastructure since it has optimizations for Linux, OSx and Windows as well as PHP 5.x, PHP 7.x, MySQL 4.x and 5.x. Also there is a possibility to use a different database back-end like SQLite.
I wrote some good tests in order to test specific functionality. And I want to reuse that test and automatically run my tests in the different environments. I would like to use Docker for that. But I'm quite new to Docker. Although I'm pretty handy in Bash scripting. I did some research into existing containers and possibilities. But it seems there is no easy way to get the desired containers.
Let's for now forget about OSx and Windows, and focus on Linux only. To make things easier. In my ideal scenario I start up a few docker containers each on it's own port, running the same software on a different infrastructure, like:
Preferably with a lightweight Linux distro such as Arch or Alpine.
I just finished some successful testing with Ubuntu as a distro but before I go into scripting all these Docker images myself I wondered if there is no easier solution to get this up and running.
Is there an easier way to test PHP source-code on multi-platforms using Docker images?
I don't think you can skip the process of build each environment. Altough you can use some pre-builted images from docker hub to speed up.
I'd create the following structure:
|-- test.sh
|-- docker-compose.yml
|-- php5.X
| `-- Dockerfile
|-- php7.X
`-- Dockerfile
Inside each Dockerfile, if you need to customize them so much, you can use a base image and install everything you need.
Here is the tricky thing:
docker-compose.yml
version: '3'
services:
db:
image: mysql:${MYSQL_VERSION}
environment:
- MYSQL_ROOT_PASSWORD=secret
web:
build:
context: .
dockerfile: php${PHP_VERSION}/Dockerfile
depends_on:
- db
This way you'll run different versions depending on the environment variables, so you can easily do this in your script:
test.sh
export MYSQL_VERSION=5.6
export PHP_VERSION=7.1
docker-compose up --abort-on-container-exit
export MYSQL_VERSION=5.5
export PHP_VERSION=5.6
docker-compose up --abort-on-container-exit
...