Skip to content

Commit

Permalink
Merge pull request #10 from generationtux/lumen-7.x-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Olofguard authored Jul 2, 2020
2 parents 05c4504 + c913680 commit dadf026
Show file tree
Hide file tree
Showing 31 changed files with 240 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/tests/coverage
composer.lock
.idea
.phpunit.result.cache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php
php:
- '7.2'
- '7.3'
install: composer install
script: ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_success:
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM php:7.3-fpm-alpine

# The following labels need to be set as part of the docker build process.
# org.opencontainers.image.created
# org.opencontainers.image.revision
LABEL org.opencontainers.image.url="https://laravel.com" \
org.opencontainers.image.documentation="https://github.com/generationtux/php-healthz/blob/master/README.md" \
org.opencontainers.image.source="https://github.com/generationtux/php-healthz/Dockerfile" \
org.opencontainers.image.vendor="Generation Tux <[email protected]>" \
org.opencontainers.image.title="Laravel 6.x" \
org.opencontainers.image.description="PHP built for use with the Laravel/Lumen framework" \
com.generationtux.php.backend="fpm"

USER root

COPY ./docker/installComposer.sh /tmp/installComposer.sh

RUN apk --no-cache --update add bash ca-certificates libpq postgresql-dev curl git curl git mysql-client unzip wget zip postgresql-client \
&& apk add --no-cache --virtual build-dependencies autoconf build-base g++ make \
&& pecl install redis xdebug \
&& docker-php-ext-install bcmath opcache pdo_mysql pdo_pgsql pcntl \
&& docker-php-ext-enable bcmath opcache redis xdebug \
&& chmod +x /tmp/installComposer.sh \
&& /tmp/installComposer.sh \
&& chown www-data:www-data /usr/local/bin/composer \
&& apk del --purge autoconf build-dependencies g++ make \
&& chown -R www-data:www-data /var/www

WORKDIR /var/www

USER www-data:www-data
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
]
},
"require": {
"guzzlehttp/guzzle": "~6.0",
"php": ">=7.3",
"guzzlehttp/guzzle": "^6.2",
"aws/aws-sdk-php": "~3.0",
"illuminate/contracts": "^6.0",
"illuminate/database": "^6.0",
"illuminate/queue": "^6.0",
"illuminate/console": "^6.0",
"twig/twig": "~1.0"
"illuminate/contracts": "^7.0",
"illuminate/database": "^7.0",
"illuminate/queue": "^7.0",
"illuminate/console": "^7.0",
"twig/twig": "~3.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"mockery/mockery": "^0.9.4",
"phpunit/phpunit": "^8.5",
"mockery/mockery": "^1.2.1",
"gecko-packages/gecko-memcache-mock": "^1.0"
},
"extra": {
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: '3'
services:
app:
image: gentux/php:lumen-5.6-ci
build:
context: .
dockerfile: ./Dockerfile
volumes:
- ./:/var/www
ports:
Expand Down
20 changes: 20 additions & 0 deletions docker/installComposer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('sha384', 'composer-setup.php');")

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi

php composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet
RESULT=$?
rm composer-setup.php
if [[ "$RESULT" -eq "0" ]]; then
composer global require hirak/prestissimo
fi;
exit $RESULT
Terms
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false">
stopOnFailure="true">
<testsuites>
<testsuite name="Main">
<directory>./tests/</directory>
Expand Down
36 changes: 36 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,39 @@ public function run()
throw new HealthWarningException("The check didn't fail, but here ye be warned.");
}
```


## Contributing

### What you need
* [docker & docker-compose](https://docs.docker.com/compose/install/)
* a fork of this repo

### Bringing up the development environment

```sh
docker-compose up -d
```

### Exec into the container
```sh
docker-compose exec app bash
```
### Composer install
```sh
composer install
```

### Running the tests
```sh
./vendor/bin/phpunit
```


### Finally
Make your changes and add any needed tests around said changes.
Then open a pull request into the generationtux repository.




4 changes: 2 additions & 2 deletions src/Checks/General/DebugHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function __construct($env = 'APP_DEBUG')
/**
* Check if the app is in debug mode
*
* @return mixed
* @return void
*
* @throws HealthWarningException
*/
public function run()
public function run(): void
{
$debug = getenv($this->env) == 'true';

Expand Down
4 changes: 3 additions & 1 deletion src/Checks/General/EnvHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public function __construct($env = 'APP_ENV')

/**
* Run the health check
*
* @throws HealthWarningException
*/
public function run()
public function run(): void
{
$env = getenv($this->env) ?: 'UNKNOWN';
if ($env == 'UNKNOWN') {
Expand Down
9 changes: 5 additions & 4 deletions src/Checks/General/HttpHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use Gentux\Healthz\HealthCheck;
use Psr\Http\Message\ResponseInterface;

/**
* Health check for HTTP endpoints
Expand Down Expand Up @@ -41,11 +42,11 @@ public function __construct(Request $request, $expectedStatusCode = 200, array $
/**
* Send the request
*
* @return mixed
* @return ResponseInterface
*
* @throws HealthFailureException
* @throws HealthFailureException|RequestException
*/
public function run()
public function run(): ResponseInterface
{
try {
$response = $this->guzzle()->send(
Expand Down Expand Up @@ -156,7 +157,7 @@ public function guzzle()
*
* @return string
*/
public function description()
public function description(): ?string
{
$description = $this->description;

Expand Down
20 changes: 11 additions & 9 deletions src/Checks/General/MemcachedHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public function __construct($memcached = null)
/**
* Check for connection to memcached servers
*
* @return mixed
* @return void
*
* @throws HealthFailureException
*/
public function run()
public function run(): void
{
if (count($this->servers())) {
$this->memcached->addServers($this->servers());
Expand Down Expand Up @@ -64,7 +66,7 @@ public function run()
*
* @return self
*/
public function addServer($server, $port = 11211, $weight = 0)
public function addServer($server, $port = 11211, $weight = 0): HealthCheck
{
$this->servers[] = [$server, $port, $weight];

Expand All @@ -76,7 +78,7 @@ public function addServer($server, $port = 11211, $weight = 0)
*
* @return array
*/
public function servers()
public function servers(): array
{
return $this->servers;
}
Expand All @@ -88,7 +90,7 @@ public function servers()
*
* @return self
*/
public function setOptions(array $options)
public function setOptions(array $options): HealthCheck
{
$this->options = $options;

Expand All @@ -100,7 +102,7 @@ public function setOptions(array $options)
*
* @return array
*/
public function options()
public function options(): array
{
return $this->options;
}
Expand All @@ -113,7 +115,7 @@ public function options()
*
* @return self
*/
public function setAuth($username, $password)
public function setAuth($username, $password): HealthCheck
{
$this->username = $username;
$this->password = $password;
Expand All @@ -126,7 +128,7 @@ public function setAuth($username, $password)
*
* @return string|null
*/
public function username()
public function username(): ?string
{
return $this->username;
}
Expand All @@ -136,7 +138,7 @@ public function username()
*
* @return string|null
*/
public function password()
public function password(): ?string
{
return $this->password;
}
Expand Down
14 changes: 9 additions & 5 deletions src/Checks/Laravel/DatabaseHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public function __construct(DatabaseManager $db = null)
/**
* Check database connection
*
* @return mixed
* @return void
*
* @throws HealthFailureException
*/
public function run()
public function run(): void
{
try {
$name = $this->connection();
Expand All @@ -63,7 +63,7 @@ public function run()
*
* @return null|string
*/
public function connection()
public function connection(): ?string
{
return $this->connection;
}
Expand All @@ -72,17 +72,21 @@ public function connection()
* Set the connection name
*
* @param string $connection
*
* @return void
*/
public function setConnection($connection)
public function setConnection($connection): void
{
$this->connection = $connection;
}

/**
* If no description property is defined, use the connection
* name instead ('default' if connection is also null).
*
* @return string
*/
public function description()
public function description(): string
{
$description = $this->description;

Expand Down
Loading

0 comments on commit dadf026

Please sign in to comment.