Skip to content

Commit

Permalink
Merge pull request #29 from t-geindre/feature/dynamic-extensions
Browse files Browse the repository at this point in the history
Dynamic extensions loading
  • Loading branch information
mnapoli authored Jun 20, 2018
2 parents a426389 + da4f117 commit 343d65b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 9 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ hooks:
- 'npm install'
```
## PHP binary
## PHP configuration
If you need a specific PHP version, you can define it in a `.bref.yml` file:

Expand All @@ -248,6 +248,21 @@ Here is the list of versions available:
- 7.2.5
- 7.2.2

You can also define `php.ini` configuration flags and activate extensions:

```yaml
php:
configuration:
max_execution_time: 300
extensions:
- redis
```

Here is the list of extensions available:

- Redis: `redis`
- MongoDB: `mongodb`

## Contributing

There are a lot of detailed `TODO` notes in the codebase. Feel free to work on these.
7 changes: 6 additions & 1 deletion bin/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ RUN yum --releasever=2017.03 install \
openssl-devel \
libpng-devel \
libjpeg-devel \
curl-devel -y
curl-devel \
# The pecl command uses find
findutils \
php-pear -y

RUN curl -sL https://github.com/php/php-src/archive/$PHP_VERSION.tar.gz | tar -zxv

Expand Down Expand Up @@ -54,3 +57,5 @@ RUN ./configure \
RUN make -j 5

RUN make install

RUN pecl install mongodb redis
3 changes: 1 addition & 2 deletions bin/php/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ container=$(docker create php-build)

docker -D cp $container:/php-src-$PHP_VERSION_GIT_BRANCH/sapi/cli/php .
mkdir -p ext
docker -D cp $container:/usr/local/lib/php/extensions/no-debug-non-zts-20170718/opcache.a ext/opcache.a
docker -D cp $container:/usr/local/lib/php/extensions/no-debug-non-zts-20170718/opcache.so ext/opcache.so
docker -D cp $container:/usr/local/lib/php/extensions/no-debug-non-zts-20170718/. ext/
docker rm $container

tar czf $PHP_VERSION_GIT_BRANCH.tar.gz php ext
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"aws/aws-sdk-php": "^3.44",
"psr/http-server-handler": "^1.0",
"zendframework/zend-diactoros": "^1.6",
"jolicode/jolinotif": "^2.0"
"jolicode/jolinotif": "^2.0",
"matomo/ini": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5",
Expand Down
37 changes: 35 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions src/Console/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Bref\Filesystem\DirectoryMirror;
use Joli\JoliNotif\Notification;
use Joli\JoliNotif\NotifierFactory;
use Matomo\Ini\IniReader;
use Matomo\Ini\IniWriter;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -154,8 +156,13 @@ private function generateArchive(SymfonyStyle $io, ProgressBar $progress) : void
->mustRun();
// Set correct permissions on the file
$this->fs->chmod('.bref/output/.bref/bin', 0755);
// Install our custom php.ini
$this->fs->copy(__DIR__ . '/../../template/php.ini', '.bref/output/.bref/php.ini');
// Install our custom php.ini and merge it with user configuration
$this->buildPhpConfig(
__DIR__ . '/../../template/php.ini',
'.bref/output/.bref/php.ini',
$projectConfig['php']['configuration'] ?? [],
$projectConfig['php']['extensions'] ?? []
);
$progress->advance();

$progress->setMessage('Installing Bref files for NodeJS');
Expand Down Expand Up @@ -241,4 +248,26 @@ private function copyProjectToOutputDirectory() : void
$directoryMirror = new DirectoryMirror($this->fs);
$directoryMirror->mirror($source, $target);
}

private function buildPhpConfig(string $sourceFile, string $targetFile, array $flags, array $extensions = [])
{
$config = array_merge(
['flags' => array_merge(
(new IniReader())->readFile($sourceFile),
$flags
)],
array_combine(
$extensions,
array_map(function ($extension) {
if (!$this->fs->exists('.bref/output/.bref/bin/ext/' . $extension . '.so')) {
throw new \Exception("The PHP extension '$extension' is not available yet in Bref, please open an issue or a pull request on GitHub to add that extension");
}

return ['extension' => $extension . '.so'];
}, $extensions)
)
);

(new IniWriter())->writeToFile($targetFile, $config);
}
}

0 comments on commit 343d65b

Please sign in to comment.