Skip to content

Commit

Permalink
Merge pull request #27 from t-geindre/feature/php-config
Browse files Browse the repository at this point in the history
Allow PHP version config
  • Loading branch information
mnapoli authored Jun 20, 2018
2 parents 57f48b2 + 9cedaaf commit a426389
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ hooks:
- 'npm install'
```
## PHP binary
If you need a specific PHP version, you can define it in a `.bref.yml` file:

```yaml
php:
version: 7.2.6
```

Here is the list of versions available:

- 7.2.5
- 7.2.2

## Contributing

There are a lot of detailed `TODO` notes in the codebase. Feel free to work on these.
2 changes: 1 addition & 1 deletion bref
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

const PHP_TARGET_VERSION = '7.2.5';
const DEFAULT_PHP_TARGET_VERSION = '7.2.5';

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
Expand Down
19 changes: 7 additions & 12 deletions src/Console/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,21 @@ private function generateArchive(SymfonyStyle $io, ProgressBar $progress) : void

// Cache PHP's binary in `.bref/bin/php` to avoid downloading it
// on every deploy.
/*
* TODO Allow choosing a PHP version instead of using directly the
* constant `PHP_TARGET_VERSION`. That could be done using the `.bref.yml`
* config file: there could be an option in that config, for example:
* php:
* version: 7.2.2
*/
$phpVersion = $projectConfig['php']['version'] ?? DEFAULT_PHP_TARGET_VERSION;

$progress->setMessage('Downloading PHP in the `.bref/bin/` directory');
$progress->display();
if (!$this->fs->exists('.bref/bin/php/php-' . PHP_TARGET_VERSION . '.tar.gz')) {
if (!$this->fs->exists('.bref/bin/php/php-' . $phpVersion . '.tar.gz')) {
$this->fs->mkdir('.bref/bin/php');
$defaultUrl = 'https://s3.amazonaws.com/bref-php/bin/php-' . PHP_TARGET_VERSION . '.tar.gz';
/*
* TODO This option allows to customize the PHP binary used. It should be documented
* and probably moved to a dedicated option like:
* php:
* url: 'https://s3.amazonaws.com/...'
*/
$url = $projectConfig['php'] ?? $defaultUrl;
(new Process("curl -sSL $url -o .bref/bin/php/php-" . PHP_TARGET_VERSION . ".tar.gz"))
$defaultUrl = 'https://s3.amazonaws.com/bref-php/bin/php-' . $phpVersion . '.tar.gz';
$url = $projectConfig['php']['url'] ?? $defaultUrl;
(new Process("curl -sSL $url -o .bref/bin/php/php-" . $phpVersion . ".tar.gz"))
->setTimeout(null)
->mustRun();
}
Expand All @@ -155,7 +150,7 @@ private function generateArchive(SymfonyStyle $io, ProgressBar $progress) : void
$progress->setMessage('Installing the PHP binary');
$progress->display();
$this->fs->mkdir('.bref/output/.bref/bin');
(new Process('tar -xzf .bref/bin/php/php-' . PHP_TARGET_VERSION . '.tar.gz -C .bref/output/.bref/bin'))
(new Process('tar -xzf .bref/bin/php/php-' . $phpVersion . '.tar.gz -C .bref/output/.bref/bin'))
->mustRun();
// Set correct permissions on the file
$this->fs->chmod('.bref/output/.bref/bin', 0755);
Expand Down

0 comments on commit a426389

Please sign in to comment.