Skip to content

Commit c806991

Browse files
committed
Add an initial Docker configuration
This change adds the initial Docker setup, providing an environment where the tests can be run, regardless of the user's operating system. It provides three services; one for PHP, one for MySQL, and one for PostgreSQL. The PHP environment has all of the dependencies and extensions required to interact with MySQL, PostgreSQL, and SQLite, along with any required binaries. It also updates PHPUnit's configuration, where required, to sync with that configuration. The change also removes the Vagrantfile as it's no longer required. Signed-off-by: Matthew Setter <matthew@matthewsetter.com>
1 parent be625cd commit c806991

10 files changed

Lines changed: 121 additions & 94 deletions

File tree

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,53 @@ $ ./vendor/bin/phpunit --testsuite "integration test" # integration tests only
4040

4141
Unit tests do not require additional functionality beyond having the appropriate database extensions present and loaded in your PHP binary.
4242

43-
### Integration tests
43+
#### Integration tests
4444

4545
To run the integration tests, you need databases.
46-
The repository includes a `Vagrantfile` which allows you to fire up a [vagrant box](https://app.vagrantup.com) with several of our target databases, including:
46+
So, the repository includes a [Docker Compose][docker-compose] configuration which allows you to start a test environment that provides several of our target databases, including _MySQL_ and _PostgreSQL_, and SQLite.
4747

48-
- MySQL
49-
- PostgreSQL
50-
- SQL Server
48+
To start up the configuration, run the following command:
5149

52-
To start up vagrant:
50+
```bash
51+
$ docker compose up -d
52+
```
53+
54+
To test that the environment is up and running, run the following command:
5355

5456
```bash
55-
$ vagrant up
57+
$ docker compose ps
5658
```
5759

58-
Copy `phpunit.xml.dist` to `phpunit.xml`, and change the following ENV var declaration values to "true":
60+
You should see output similar to the following:
61+
62+
```bash
63+
docker compose ps
64+
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
65+
laminas-db-mysql-1 docker.io/library/laminas-db-mysql:latest "mysqld" mysql 7 hours ago Up 7 hours
66+
laminas-db-php-1 docker.io/library/laminas-db-php:latest "apache2-foreground" php 7 hours ago Up 7 hours
67+
laminas-db-postgresql-1 docker.io/library/laminas-db-postgresql:latest "postgres" postgresql 7 hours ago Up 7 hours
68+
```
69+
70+
If you see three containers listed, then they're all running, and you are ready to run the test suite.
71+
So, copy `phpunit.xml.dist` to `phpunit.xml`, and change the following environment variable to "true" to enable the three databases:
5972

6073
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL
61-
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV
6274
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL
6375
- TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY
6476

65-
From there, you can run the integration tests:
77+
From there, you can run the integration tests by running the following command:
6678

6779
```bash
68-
$ ./vendor/bin/phpunit --testsuite "integration test"
80+
$ docker compose exec php composer test-integration
6981
```
7082

83+
> [!TIP]
84+
> If you want to grow your Docker Compose knowledge, grab a (free) copy of [Deploy with Docker Compose][deploy-with-docker-compose].
85+
7186
-----
7287

7388
- File issues at https://github.com/laminas/laminas-db/issues
7489
- Documentation is at https://docs.laminas.dev/laminas-db/
90+
91+
[docker-compose]: https://docs.docker.com/compose/intro/features-uses/
92+
[deploy-with-docker-compose]: https://deploywithdockercompose.com

Vagrantfile

Lines changed: 0 additions & 74 deletions
This file was deleted.

bin/install-deps.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
/usr/bin/composer validate && \
4+
/usr/bin/composer --ignore-platform-reqs install \
5+
--no-ansi --no-progress --no-scripts \
6+
--classmap-authoritative --no-interaction \
7+
--quiet

compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
php:
3+
build:
4+
context: ./
5+
dockerfile: docker/php/Dockerfile
6+
args:
7+
- PHP_VERSION=${PHP_VERSION:-8.3.19}
8+
depends_on:
9+
- mysql
10+
- postgresql
11+
12+
mysql:
13+
build:
14+
context: ./
15+
dockerfile: docker/databases/mysql/Dockerfile
16+
args:
17+
- VERSION=${MYSQL_VERSION:-8.0.41}
18+
environment:
19+
- MYSQL_DATABASE=${MYSQL_DATABASE:-laminasdb_test}
20+
- MYSQL_USER=${MYSQL_USER:-user}
21+
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-password}
22+
- MYSQL_RANDOM_ROOT_PASSWORD=${MYSQL_RANDOM_ROOT_PASSWORD:-yes}
23+
24+
postgresql:
25+
build:
26+
context: ./
27+
dockerfile: docker/databases/postgresql/Dockerfile
28+
args:
29+
- VERSION=${VERSION:-17.4}
30+
- ALPINE_VERSION=${ALPINE_VERSION:-3.21}
31+
environment:
32+
- POSTGRES_DB=${POSTGRES_DB:-laminasdb_test}
33+
- POSTGRES_USER=${POSTGRES_USER:-postgres}
34+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}

docker/databases/mysql/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ARG VERSION=8.4.5
2+
3+
FROM mysql:${VERSION}-bookworm AS base
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ARG VERSION=17.4
2+
ARG ALPINE_VERSION=3.21
3+
4+
FROM postgres:${VERSION}-alpine${ALPINE_VERSION} AS base

docker/php/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG PHP_VERSION=8.3.19
2+
3+
FROM php:${PHP_VERSION}-apache-bookworm AS base
4+
5+
# Copy Composer from the official Docker Hub repository to the local filesystem
6+
COPY --from=composer:2.8.6 /usr/bin/composer /usr/bin/
7+
8+
# Install the database extensions for MySQL, PostgreSQL, and SQLite, their
9+
# dependencies, and any other tools that are required for the environment to be
10+
# used fully and completely.
11+
RUN apt-get update \
12+
&& apt-get install -y git libpq-dev libsqlite3-dev \
13+
&& docker-php-ext-install mysqli pdo pdo_mysql pdo_pgsql pdo_sqlite pgsql \
14+
&& apt-get clean
15+
16+
# Allow the www-data login so that it can run Composer instead of using root
17+
RUN usermod -s /usr/bin/bash www-data
18+
19+
# Copy all of the files from the context to the current directory setting the
20+
# correct owner
21+
COPY --chown=www-data:www-data . .
22+
23+
RUN chmod +x bin/install-deps.sh
24+
25+
# Validate and install PHP's dependencies
26+
RUN su --preserve-environment www-data --command "bin/install-deps.sh"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error_reporting=E_ALL

docker/php/conf.d/xdebug.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
zend_extension=xdebug
2+
3+
[xdebug]
4+
xdebug.mode=develop,debug
5+
xdebug.client_host=host.docker.internal
6+
xdebug.start_with_request=yes

phpunit.xml.dist

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@
3434
-->
3535
<!-- Integration Test Variables -->
3636
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL" value="false"/>
37-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="192.168.20.20"/>
38-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME" value="root"/>
39-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD" value="Password123"/>
37+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME" value="mysql"/>
38+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_USERNAME" value="user"/>
39+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_PASSWORD" value="password"/>
4040
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL_DATABASE" value="laminasdb_test"/>
41+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL" value="false"/>
42+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="postgresql"/>
43+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME" value="postgres"/>
44+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="postgres"/>
45+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE" value="laminasdb_test"/>
46+
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY" value="false"/>
47+
<!--
4148
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV" value="false"/>
4249
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME" value="192.168.20.20"/>
4350
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_USERNAME" value="sa"/>
@@ -53,11 +60,6 @@
5360
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_USERNAME" value=""/>
5461
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD" value=""/>
5562
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_DATABASE" value=""/>
56-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL" value="false"/>
57-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="192.168.20.20"/>
58-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_USERNAME" value="postgres"/>
59-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="postgres"/>
60-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_PGSQL_DATABASE" value="laminasdb_test"/>
61-
<env name="TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLITE_MEMORY" value="true"/>
63+
-->
6264
</php>
6365
</phpunit>

0 commit comments

Comments
 (0)