Skip to content

Commit

Permalink
CI test php PHP 8.1, 8.2 (#129)
Browse files Browse the repository at this point in the history
* CI test

* remove dep from external docker images

* update contributing guidelines

* handle docker compose

* additional space
  • Loading branch information
ilario-pierbattista authored Nov 11, 2023
1 parent 159dcae commit 08e1f52
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 17 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ jobs:
- php: 7.4
mongo-ext: 1.9.0
mongo-img: 4.4
- php: 8.0
mongo-ext: 1.9.0
mongo-img: 4.4
- php: 8.1
mongo-ext: 1.12.0
mongo-img: 5.0
- php: 8.2
mongo-ext: 1.15.0
mongo-img: 6.0

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
docker-compose.override.yml
.phpunit.result.cache
auth.json
build
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
* CI coverage for PHP 8.1 and 8.2
### Removed
* Removed support for PHP < 7.4
* Docker images dev-dependency from https://github.com/ilario-pierbattista/docker-php-mongodb-bundle

## [1.5.0] (2022-01-06)
### Added
Expand Down
48 changes: 39 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.PHONY: up setup sh test phpstan phpstan-baseline cs-fix cs-check usage

.PHONY: usage
usage:
@echo ''
@echo 'Facile.it MongoDB Bundle'
Expand All @@ -23,32 +22,63 @@ usage:
@echo 'make phpstan-baseline: update the phpstan baseline'
@echo ''

##################################################################
#
# RUN OUTISDE THE CONTAINER
#
##################################################################
DOCKER_COMPOSE ?= $(shell (command -v docker-compose > /dev/null && echo "docker-compose") || (command -v docker > /dev/null && echo "docker compose"))

docker-compose.override.yml:
cp docker-compose.override.yml.dist docker-compose.override.yml

docker-compose.yml: docker-compose.override.yml
.PHONY: build-74 build-81 build-82
build-74:
PHP_VERSION=7.4 MONGODB_EXTENSION_VERSION=1.6.0 $(DOCKER_COMPOSE) build
build-81:
PHP_VERSION=8.1 MONGODB_EXTENSION_VERSION=1.12.0 $(DOCKER_COMPOSE) build
build-82:
PHP_VERSION=8.1 MONGODB_EXTENSION_VERSION=1.15.0 $(DOCKER_COMPOSE) build

setup: docker-compose.yml composer.json
docker-compose run --rm php composer install
.PHONY: --setup-common setup setup-74 setup-81 setup-82
setup: setup-74
setup-74: | build-74 --setup-common
setup-81: | build-81 --setup-common
setup-82: | build-82 --setup-common
--setup-common: docker-compose.override.yml
rm composer.lock || true
$(DOCKER_COMPOSE) run --rm php composer install

.PHONY: sh stop
sh: docker-compose.yml
docker-compose up -d --force-recreate
docker exec -ti mb_php bash
$(DOCKER_COMPOSE) up -d --force-recreate
$(DOCKER_COMPOSE) exec -ti php bash

stop: docker-compose.yml
docker-compose stop
$(DOCKER_COMPOSE) stop


##################################################################
#
# RUN INSIDE THE CONTAINER
#
##################################################################

.PHONY: test coverage
test:
bin/phpunit tests
coverage:
bin/phpunit tests --coverage-clover=build/coverage-report.xml

.PHONY: phpstan phpstan-baseline
phpstan:
bin/phpstan analyze --memory-limit=-1

phpstan-baseline:
bin/phpstan analyze --memory-limit=-1 --generate-baseline

.PHONY: cs-fix cs-check
cs-fix:
composer cs-fix

cs-check:
composer cs-check
2 changes: 1 addition & 1 deletion docker-compose.override.yml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.1"
version: "3.8"

services:
mongo:
Expand Down
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
version: "3.1"
version: "3.8"

services:
php:
image: ilariopierbattista/mongodb-bundle-php:php-7.4-mongoext-1.6.0-20231111
image: mongodb-bundle-php:${PHP_VERSION:-7.4}-${MONGODB_EXTENSION_VERSION:-1.6.0}
build:
context: docker
args:
PHP_VERSION: ${PHP_VERSION:-7.4}
MONGODB_EXTENSION_VERSION: ${MONGODB_EXTENSION_VERSION:-1.6.0}
volumes:
- ./:/home/user-dev/project
tty: true
Expand Down
44 changes: 44 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y \
libbz2-dev \
libcurl4-openssl-dev \
libedit-dev \
libfontconfig \
libgmp-dev \
libicu-dev \
libmcrypt-dev \
libssl-dev \
libtidy-dev \
libxml2-dev \
libxslt-dev \
libzip-dev \
locales \
openssl \
libonig-dev \
git \
unzip

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY install-extensions.sh .
RUN ./install-extensions.sh

ARG MONGODB_EXTENSION_VERSION

RUN pecl install mongodb-${MONGODB_EXTENSION_VERSION} \
&& docker-php-ext-enable mongodb

ENV TEST_ENV=docker

RUN useradd -m user-dev

USER user-dev

RUN mkdir -p /home/user-dev/project

WORKDIR /home/user-dev/project
21 changes: 21 additions & 0 deletions docker/install-extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

# Is everything necessary?
docker-php-ext-install curl
docker-php-ext-install opcache
docker-php-ext-install intl
docker-php-ext-install tidy
docker-php-ext-install bz2
docker-php-ext-install xml
docker-php-ext-install mbstring
docker-php-ext-install zip

if echo "$PHP_VERSION" | grep -Eq '7\.\d*'
then
docker-php-ext-install json
fi

pecl install pcov && docker-php-ext-enable pcov
20 changes: 18 additions & 2 deletions docs/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Since we defined our code stile, and configured a quality tool for enforce its u
## Development Environment

We like a lot Docker and Make.
We use the former and `docker-compose` to set up and insulated, reproducible development environment.
The latter helps us to define a lot of shortcuts.

We use`docker-compose` to set up and insulated, reproducible development environment.
Make helps us to define easy-to-use build targets.

Run `make usage` or just `make` inside the project folder to get a list of available targets.

Expand Down Expand Up @@ -68,6 +69,21 @@ another port for the binding.
Change the port binding into the `docker-compose.override.yml` file.
It is generated from the `docker-compose.override.yml.dist` template, and it's not tracked by git.

### Run a different version of PHP and/or the ext-mongodb

By default `make setup` will build a docker image with the lower supported version of PHP
and `ext-mongodb`.

If you need a different environment, you should exec one of the following target **instead** of `make setup`.

make setup-81 # PHP 8.1, ext-mongodb 1.12
make setup-82 # PHP 8.2, ext-mongodb 1.15

Feel free to add other `setup-*` and `build-*` targets to meet your needs (take a look at the [Makefile](../Makefile) and just follow the same convention).

Remember to edit the [ci.yaml](../.github/workflows/ci.yaml), if you need to test the bundle against
a specific set of PHP and ext-mongodb versions.

### Tests and Quality Tools

This project uses `phpunit` to run its test suite.
Expand Down

0 comments on commit 08e1f52

Please sign in to comment.