Skip to content

Commit

Permalink
Improve overall php and dependencies support (#15)
Browse files Browse the repository at this point in the history
* Add PHP 8 support.
 * Add PHP 7.2 support.
 * Add pipeline for running tests.
 * Replace `endclothing/prometheus_client_php` dependency with the more
 up-to-date `promphp/prometheus_client_php` lib.
 * Update changelog.
 * Add support for Guzzle 6 and 7.
 * Drop Laravel 6 support and add support for Laravel 8.
  • Loading branch information
xico42 authored Feb 23, 2021
1 parent b3324b0 commit 3c715a3
Show file tree
Hide file tree
Showing 27 changed files with 379 additions and 240 deletions.
17 changes: 17 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG PHP_VERSION="7.3"

FROM php:${PHP_VERSION}-cli

WORKDIR /application

RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

RUN pecl install xdebug && docker-php-ext-enable xdebug

RUN apt-get update \
&& apt-get install -y git libzip-dev \
&& docker-php-ext-install zip \
&& pecl install redis apcu \
&& docker-php-ext-enable redis zip apcu

COPY .docker/php-ini-overrides.ini /usr/local/etc/php/conf.d/99-overrides.ini
13 changes: 13 additions & 0 deletions .docker/php-ini-overrides.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
memory_limit=-1

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.discover_client_host=1

apc.enable_cli=true

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/Sao_Paulo
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/examples export-ignore
/bin export-ignore
/.docker export-ignore
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build

on:
pull_request:
push:
branches: [ master ]

jobs:
build:
strategy:
matrix:
php: ["7.2", "7.3", "7.4", "8.0"]
runs-on: ubuntu-latest
container: arquivei/laravel-prometheus-exporter:${{ matrix.php }}
steps:
- uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer dependencies
run: composer install

- name: Run checks
run: php vendor/bin/phpunit

- name: Run checks in lower versions
run: |
composer update --prefer-lowest --prefer-dist --prefer-stable --no-interaction
php vendor/bin/phpunit
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish docker images

on:
workflow_dispatch:

jobs:
publish:
strategy:
matrix:
php: ["7.2", "7.3", "7.4", "8.0"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Push to Docker Hub
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: arquivei/laravel-prometheus-exporter
push: true
context: .
file: ./.docker/Dockerfile
tags: ${{ matrix.php }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.idea
composer.lock
vendor
bin
coverage
coverage.xml
.php_cs.cache
examples/lumen-app/vendor
.phpunit.cache
66 changes: 0 additions & 66 deletions .php_cs

This file was deleted.

76 changes: 0 additions & 76 deletions .styleci.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
PHP_VERSION ?= 7.3
PHP ?= bin/php -d "xdebug.mode=off"
COMPOSER ?= bin/composer

.PHONY: setup
setup:
DOCKER_BUILDKIT=1 docker build -f .docker/Dockerfile -t laravel-prometheus-exporter:7.2 --build-arg PHP_VERSION=7.2 .
DOCKER_BUILDKIT=1 docker build -f .docker/Dockerfile -t laravel-prometheus-exporter:7.3 --build-arg PHP_VERSION=7.3 .
DOCKER_BUILDKIT=1 docker build -f .docker/Dockerfile -t laravel-prometheus-exporter:7.4 --build-arg PHP_VERSION=7.4 .
DOCKER_BUILDKIT=1 docker build -f .docker/Dockerfile -t laravel-prometheus-exporter:8.0 --build-arg PHP_VERSION=8.0 .

.PHONY: publish
publish: publish-7.2 publish-7.3 publish-7.4 publish-8.0

.PHONY: publish-%
publish-%:
docker tag laravel-prometheus-exporter:${*} arquivei/laravel-prometheus-exporter:${*}
docker push arquivei/laravel-prometheus-exporter:${*}

.PHONY: vendor
vendor:
PHP_VERSION=$(PHP_VERSION) $(COMPOSER) install

.PHONY: tests
tests:
PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit

.PHONY: ci-local
ci-local: ci-local-7.2 ci-local-7.3 ci-local-7.4 ci-local-8.0

ci-local-%:
rm -rf composer.lock vendor/

PHP_VERSION=${*} $(COMPOSER) install
PHP_VERSION=${*} $(PHP) vendor/bin/phpunit

PHP_VERSION=${*} $(COMPOSER) update --prefer-lowest --prefer-dist --prefer-stable --no-interaction
PHP_VERSION=${*} $(PHP) vendor/bin/phpunit
22 changes: 22 additions & 0 deletions bin/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

command -v docker >/dev/null 2>&1 || { echo "docker is required to run this binary. Aborting." >&2; exit 1; }

USER=${USER:-$( id -un )}
GROUP=${GROUP:-$( id -gn )}
COMPOSER_HOME=${COMPOSER_HOME:-${HOME}/.composer}
DOCKER_OPTS=${DOCKER_OPTS:-'-it'}
PHP_VERSION=${PHP_VERSION:-7.3}

exec docker run ${DOCKER_OPTS} --rm \
-u $( id -u ${USER} ):$( id -g ${USER} ) \
-v "${PWD}":"/application" \
-v "${COMPOSER_HOME}":/tmp/composer \
-w "/application" \
-e COMPOSER_HOME="/tmp/composer" \
--net=host --sig-proxy=true --pid=host \
--entrypoint="php" \
laravel-prometheus-exporter:"${PHP_VERSION}" -d "xdebug.mode=off" /usr/bin/composer "${@}"

20 changes: 20 additions & 0 deletions bin/php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -e

command -v docker >/dev/null 2>&1 || { echo "docker is required to run this binary. Aborting." >&2; exit 1; }

USER=${USER:-$( id -un )}
GROUP=${GROUP:-$( id -gn )}
DOCKER_OPTS=${DOCKER_OPTS:-'-it'}
PHP_VERSION=${PHP_VERSION:-7.3}

exec docker run ${DOCKER_OPTS} --rm \
-u $( id -u ${USER} ):$( id -g ${USER} ) \
-v "${PWD}":"/application" \
-w "/application" \
-e PHP_IDE_CONFIG="serverName=laravel-prometheus-exporter.localhost" \
--net=host --sig-proxy=true --pid=host \
--entrypoint="php" \
laravel-prometheus-exporter:"${PHP_VERSION}" "${@}"

31 changes: 27 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.0.1 - 2017-08-30
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

* Fix config retrieval of `prometheus.storage_adapters`
## [2.0.0] - 2020-02-12
### Added
- Add PHP 7.2 support.
- Add PHP 8 support.
- Add pipeline for running automated tests.
- Add makefile and docker images for development purposes.
- Add support for Guzzle 7.
- Add default metric `php_version`.

## 1.0.0 - 2017-07-27
### Changed
- Replace `endclothing/prometheus_client_php` dependency with `promphp/prometheus_client_php` .
- Move collectors instantiation from the boot method to the callable that creates
the prometheus exporter. This means that the collectors are instantiated only when the
exporter is required, preventing the need of a redis connection when just executing
`php artisan`, for example.

* Initial release
### Removed
- Drop Laravel 5.x support.

## [1.0.1] - 2017-08-30
### Changed
- Fix config retrieval of `prometheus.storage_adapters`

## [1.0.0] - 2017-07-27
### Added
- Initial release
Loading

0 comments on commit 3c715a3

Please sign in to comment.