Skip to content

Commit c91bd2a

Browse files
authored
[CI] Improve build system (Makefile, Docker, Travis) (#21)
Fixes #20
1 parent 61e18ab commit c91bd2a

18 files changed

+324
-124
lines changed

.gitignore

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
.idea
2+
3+
### Vagrant template
4+
.vagrant/
5+
### Composer template
16
composer.phar
27
/vendor/
3-
composer.lock
48

59
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
610
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
11+
composer.lock
712

8-
.idea
9-
10-
.php_cs.cache
13+
# Custom entries
14+
.php_cs*.cache
15+
.env
16+
variables.mk
17+
/build/
18+
ocular.phar
19+
php-cs-fixer.phar

.travis.yml

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,103 @@ sudo: required
33
language: php
44

55
services:
6-
- docker
6+
- docker
77

88
php:
9-
- '7.0'
10-
- '7.1'
11-
- '7.2'
12-
- nightly
9+
- '7.1'
10+
- '7.2'
1311

1412
env:
1513
global:
16-
- DOCKER_COMPOSE_VERSION=1.19.0
14+
- DOCKER_COMPOSE_VERSION=1.22.0
1715
matrix:
18-
- DEPENDENCIES="low" INTEGRATION_TEST="enabled"
19-
- DEPENDENCIES="low" INTEGRATION_TEST="disabled"
20-
- DEPENDENCIES="stable" INTEGRATION_TEST="enabled"
21-
- DEPENDENCIES="stable" INTEGRATION_TEST="disabled"
22-
23-
matrix:
24-
allow_failures:
25-
- php: nightly
16+
- DEPENDENCIES="low"
17+
- DEPENDENCIES="stable"
2618

2719
before_script:
28-
- if [ "$INTEGRATION_TEST" == "enabled" ]; then sudo rm /usr/local/bin/docker-compose; fi;
29-
- if [ "$INTEGRATION_TEST" == "enabled" ]; then curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose; fi;
30-
- if [ "$INTEGRATION_TEST" == "enabled" ]; then chmod +x docker-compose; fi;
31-
- if [ "$INTEGRATION_TEST" == "enabled" ]; then sudo mv docker-compose /usr/local/bin; fi;
32-
- composer self-update
33-
- if [ "$DEPENDENCIES" == "stable" ]; then composer update --prefer-stable; fi;
34-
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest --prefer-stable; fi;
20+
- make install-phars
21+
- if [ "$INTEGRATION_TEST" == "enabled" ]; then sudo rm /usr/local/bin/docker-compose; fi;
22+
- if [ "$INTEGRATION_TEST" == "enabled" ]; then curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose; fi;
23+
- if [ "$INTEGRATION_TEST" == "enabled" ]; then chmod +x docker-compose; fi;
24+
- if [ "$INTEGRATION_TEST" == "enabled" ]; then sudo mv docker-compose /usr/local/bin; fi;
25+
- composer self-update
26+
- if [ "$DEPENDENCIES" == "stable" ]; then composer update --prefer-stable; fi;
27+
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest --prefer-stable; fi;
3528

3629
script:
37-
- if [ "$INTEGRATION_TEST" == "disabled" ]; then make quick-test; fi;
38-
- if [ "$INTEGRATION_TEST" == "enabled" ]; then make integration-test; fi;
30+
- COMPOSER=composer PHP=php make ci-local
3931

32+
jobs:
33+
include:
34+
- stage: coverage
35+
php: 7.2
36+
env:
37+
- DEPENDENCIES="stable"
38+
script:
39+
- PHP=php make coverage
40+
- stage: integration
41+
php: 7.2
42+
env:
43+
- DEPENDENCIES="stable"
44+
- INTEGRATION_TEST="enabled"
45+
- CONFLUENT_VERSION=3.1.2
46+
script:
47+
- make platform
48+
- PHP=php make phpunit-integration
49+
- stage: integration
50+
php: 7.2
51+
env:
52+
- DEPENDENCIES="stable"
53+
- INTEGRATION_TEST="enabled"
54+
- CONFLUENT_VERSION=3.2.4
55+
script:
56+
- make platform
57+
- PHP=php make phpunit-integration
58+
- stage: integration
59+
php: 7.2
60+
env:
61+
- DEPENDENCIES="stable"
62+
- INTEGRATION_TEST="enabled"
63+
- CONFLUENT_VERSION=3.3.2
64+
script:
65+
- make platform
66+
- PHP=php make phpunit-integration
67+
- stage: integration
68+
php: 7.2
69+
env:
70+
- DEPENDENCIES="stable"
71+
- INTEGRATION_TEST="enabled"
72+
- CONFLUENT_VERSION=4.0.2
73+
script:
74+
- make platform
75+
- PHP=php make phpunit-integration
76+
- stage: integration
77+
php: 7.2
78+
env:
79+
- DEPENDENCIES="stable"
80+
- INTEGRATION_TEST="enabled"
81+
- CONFLUENT_VERSION=4.1.2
82+
script:
83+
- make platform
84+
- PHP=php make phpunit-integration
85+
- stage: integration
86+
php: 7.2
87+
env:
88+
- DEPENDENCIES="stable"
89+
- INTEGRATION_TEST="enabled"
90+
- CONFLUENT_VERSION=5.0.0
91+
script:
92+
- make platform
93+
- PHP=php make phpunit-integration
4094
after_script:
41-
- make clean
95+
- make clean
96+
97+
branches:
98+
only:
99+
- master
100+
- '/^ft-.*/'
101+
- '/^\d+\.\d+\.\d+$/'
102+
103+
cache:
104+
directories:
105+
- $HOME/.composer/cache/files

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ARG PHP_VERSION=7.1
2+
3+
FROM php:${PHP_VERSION}-cli-alpine
4+
5+
ARG XDEBUG_VERSION=2.6.1
6+
7+
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS zlib-dev \
8+
&& apk add --no-cache --virtual .runtime-deps git \
9+
&& docker-php-ext-install zip \
10+
&& pecl install xdebug-$XDEBUG_VERSION \
11+
&& docker-php-ext-enable xdebug \
12+
&& echo "xdebug.max_nesting_level=15000" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
13+
&& echo "xdebug.remote_enable=true" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
14+
&& echo "xdebug.remote_host=localhost" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
15+
&& echo "xdebug.idekey=PHPSTORM" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
16+
&& echo "xdebug.remote_handler=dbgp" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
17+
&& echo "xdebug.remote_autostart=1" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
18+
&& echo "xdebug.remote_connect_back=0" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \
19+
&& apk del .build-deps

Makefile

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,117 @@
1+
# no buildin rules and variables
2+
MAKEFLAGS =+ -rR --warn-undefined-variables
13

2-
quick-test:
3-
./bin/ci
4+
.PHONY: composer-install composer-update phpstan cs-fixer examples docker run
45

5-
integration-test:
6-
docker-compose up -d
7-
sleep 20
8-
./vendor/bin/phpunit -c phpunit.xml.integration.dist -v --group integration
6+
ifndef CONFLUENT_VERSION
7+
CONFLUENT_VERSION := latest
8+
endif
9+
10+
ifndef CONFLUENT_NETWORK_SUBNET
11+
CONFLUENT_NETWORK_SUBNET := 172.68.0.0/24
12+
endif
13+
14+
ifndef SCHEMA_REGISTRY_IPV4
15+
SCHEMA_REGISTRY_IPV4 := 172.68.0.103
16+
endif
17+
18+
ifndef KAFKA_BROKER_IPV4
19+
KAFKA_BROKER_IPV4 := 172.68.0.102
20+
endif
21+
22+
ifndef ZOOKEEPER_IPV4
23+
ZOOKEEPER_IPV4 := 172.68.0.101
24+
endif
25+
26+
ifndef COMPOSER
27+
COMPOSER := bin/composer.phar
28+
endif
29+
30+
ifndef COMPOSER_VERSION
31+
COMPOSER_VERSION := 1.7.2
32+
endif
33+
34+
ifndef PHP
35+
PHP := bin/php
36+
endif
37+
38+
ifndef PHP_VERSION
39+
PHP_VERSION := 7.1
40+
endif
41+
42+
ifndef XDEBUG_VERSION
43+
XDEBUG_VERSION := 2.6.1
44+
endif
45+
46+
-include variables.mk
47+
export
48+
49+
docker:
50+
docker build \
51+
--build-arg PHP_VERSION=$(PHP_VERSION) \
52+
--build-arg XDEBUG_VERSION=$(XDEBUG_VERSION) \
53+
-t schema-registry-client:$(PHP_VERSION) \
54+
-f Dockerfile \
55+
.
56+
57+
composer-install:
58+
PHP_VERSION=$(PHP_VERSION) $(PHP) $(COMPOSER) install --no-interaction --no-progress --no-suggest --no-scripts
59+
60+
composer-update:
61+
PHP_VERSION=$(PHP_VERSION) $(PHP) $(COMPOSER) update --no-interaction --no-progress --no-suggest --no-scripts
62+
63+
phpstan:
64+
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpstan.phar analyse -l 7 src
65+
66+
cs-fixer:
67+
PHP_VERSION=$(PHP_VERSION) $(PHP) bin/php-cs-fixer.phar fix --config=.php_cs.dist -v --dry-run \
68+
--path-mode=intersection --allow-risky=yes src test
69+
70+
cs-fixer-modify:
71+
PHP_VERSION=$(PHP_VERSION) $(PHP) bin/php-cs-fixer.phar fix --config=.php_cs.dist -v \
72+
--path-mode=intersection --allow-risky=yes src test
73+
74+
phpunit:
75+
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit --exclude-group integration
76+
77+
phpunit-integration:
78+
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit -c phpunit.xml.integration.dist --group integration
79+
80+
coverage:
81+
mkdir -p build
82+
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit --coverage-clover=build/coverage.clover --coverage-text
83+
PHP_VERSION=$(PHP_VERSION) $(PHP) bin/ocular.phar code-coverage:upload --format=php-clover \
84+
--repository=g/flix-tech/schema-registry-php-client build/coverage.clover
85+
86+
run:
87+
PHP_VERSION=$(PHP_VERSION) $(PHP) $(ARGS)
88+
89+
ci-local: cs-fixer phpstan phpunit
90+
91+
examples:
92+
PHP_VERSION=$(PHP_VERSION) $(PHP) examples/*
93+
94+
install-phars:
95+
curl http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -o bin/php-cs-fixer.phar -LR -z bin/php-cs-fixer.phar
96+
chmod a+x bin/php-cs-fixer.phar
97+
curl https://scrutinizer-ci.com/ocular.phar -o bin/ocular.phar -LR -z bin/ocular.phar
98+
chmod a+x bin/ocular.phar
99+
curl https://getcomposer.org/download/$(COMPOSER_VERSION)/composer.phar -o bin/composer.phar -LR -z bin/composer.phar
100+
chmod a+x bin/composer.phar
101+
102+
103+
platform:
9104
docker-compose down
105+
docker-compose up -d
106+
sleep 25
10107

11108
clean:
109+
rm -rf build
110+
docker-compose down
111+
112+
benchmark:
113+
docker-compose down
114+
docker-compose up -d
115+
sleep 15
116+
PHP_VERSION=$(PHP_VERSION) $(PHP) ./vendor/bin/phpbench run benchmarks/AvroEncodingBench.php --report=aggregate --retry-threshold=5
12117
docker-compose down

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Confluent Schema Registry PHP API
22

33
[![Build Status](https://travis-ci.org/flix-tech/schema-registry-php-client.svg?branch=2.0.2)](https://travis-ci.org/flix-tech/schema-registry-php-client)
4+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/flix-tech/schema-registry-php-client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/flix-tech/schema-registry-php-client/?branch=master)
5+
[![Code Coverage](https://scrutinizer-ci.com/g/flix-tech/schema-registry-php-client/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/flix-tech/schema-registry-php-client/?branch=master)
46
[![Latest Stable Version](https://poser.pugx.org/flix-tech/confluent-schema-registry-api/v/stable)](https://packagist.org/packages/flix-tech/confluent-schema-registry-api)
57
[![Total Downloads](https://poser.pugx.org/flix-tech/confluent-schema-registry-api/downloads)](https://packagist.org/packages/flix-tech/confluent-schema-registry-api)
68
[![License](https://poser.pugx.org/flix-tech/confluent-schema-registry-api/license)](https://packagist.org/packages/flix-tech/confluent-schema-registry-api)
@@ -226,12 +228,20 @@ There are also requests to use the new `DELETE` API of the schema registry.
226228

227229
## Testing
228230

229-
This library uses a `Makefile` to run the test suite.
231+
This library uses a `Makefile` to run the test suite and requires `docker`.
232+
233+
You can set the default variables by copying `variables.mk.dist` to `variables.mk` and change them to your liking.
234+
235+
#### Build the local docker image
236+
237+
```bash
238+
make docker
239+
```
230240

231241
#### Unit tests, Coding standards and static analysis
232242

233243
```bash
234-
make quick-test
244+
make ci-local
235245
```
236246

237247
#### Integration tests
@@ -240,7 +250,8 @@ This library uses a `docker-compose` configuration to fire up a schema registry
240250
`docker-compose` from version 1.13.0 is required to run those tests.
241251

242252
```bash
243-
make integration-test
253+
CONFLUENT_VERSION=5.0.0 make platform
254+
make phpunit-integration
244255
make clean
245256
```
246257

bin/ci

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

bin/php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
command -v docker >/dev/null 2>&1 || { echo "docker is required to run this binary. Aborting." >&2; exit 1; }
6+
7+
USER=${USER:-$( id -un )}
8+
GROUP=${GROUP:-$( id -gn )}
9+
COMPOSER_HOME=${COMPOSER_HOME:-${HOME}/.composer}
10+
PHP_VERSION=${PHP_VERSION:-7.1}
11+
DOCKER_OPTS=${DOCKER_OPTS:-'-it'}
12+
13+
exec docker run ${DOCKER_OPTS} --rm \
14+
-u $( id -u ${USER} ):$( id -g ${USER} ) \
15+
-v "${PWD}":"${PWD}" \
16+
-v "${COMPOSER_HOME}":/tmp/composer \
17+
-w ${PWD} \
18+
-e PHP_IDE_CONFIG="serverName=schema-registry-client" \
19+
-e COMPOSER_HOME="/tmp/composer" \
20+
--net=host --sig-proxy=true --pid=host \
21+
--entrypoint="php" \
22+
schema-registry-client:${PHP_VERSION} "${@}"

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@
1111
}
1212
],
1313
"require": {
14-
"php": "~7.0",
14+
"php": "~7.1",
1515
"guzzlehttp/guzzle": "~6.3",
1616
"beberlei/assert": "~2.7",
1717
"flix-tech/avro-php": "^2.0"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "~6.2",
21-
"friendsofphp/php-cs-fixer": "~2.0",
22-
"phpstan/phpstan": "~0.8",
20+
"phpunit/phpunit": "~7.0",
21+
"phpstan/phpstan-shim": "~0.8",
2322
"raphhh/trex-reflection": "~1.0",
2423
"doctrine/cache": "~1.3"
2524
},
2625
"suggest": {
27-
"flix-tech/avro-php": "Needed for decoding and encoding messages in Apache Avro format",
2826
"raphhh/trex-reflection": "Needed if you want to use the `RequestCallbackValidator`",
2927
"doctrine/cache": "If you want to use the DoctrineCacheAdapter"
3028
},

0 commit comments

Comments
 (0)