Skip to content

Commit

Permalink
Travis config and CS fixes (brefphp#1)
Browse files Browse the repository at this point in the history
* Adding blackfire and xdebug

* updates

* Create nice folded reports

* Use before install

* cleanup

* Syntax fixes

* Use minimal travis image

* CS fixes

* cs
  • Loading branch information
Nyholm authored Dec 20, 2019
1 parent 6afeae0 commit 15b4fbd
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 121 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export/ export-ignore
layers/ export-ignore
src/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.phpcs.xml.dist export-ignore
.prettyci.composer.json export-ignore
.travis.yml export-ignore
bref-extra export-ignore
bchecksums.json export-ignore
Makefile export-ignore

7 changes: 1 addition & 6 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
<!-- Show sniff names -->
<arg value="s"/>

<file>bref</file>
<file>bref-extra</file>
<file>src</file>
<file>tests</file>
<exclude-pattern>tests/Bridge/Symfony/var</exclude-pattern>
<exclude-pattern>tests/Bridge/Symfony/cache</exclude-pattern>
<exclude-pattern>tests/Bridge/Symfony/logs</exclude-pattern>
<exclude-pattern>tests/Bridge/Laravel/bootstrap/cache</exclude-pattern>

<!-- Import the Doctrine coding standard -->
<rule ref="Doctrine"/>
Expand Down
37 changes: 26 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: php
language: minimal

notifications:
email:
Expand All @@ -8,16 +8,31 @@ services:
- docker

env:
- LAYER=amqp PHP=72
- LAYER=amqp PHP=73
- LAYER=amqp PHP=74
- LAYER=blackfire PHP=72
- LAYER=blackfire PHP=73
- LAYER=blackfire PHP=74
- LAYER=xdebug PHP=72
- LAYER=xdebug PHP=73
- LAYER=xdebug PHP=74
- LAYER=amqp PHP="72 73 74"
- LAYER=blackfire PHP="72 73 74"
- LAYER=xdebug PHP="72 73 74"

before_install:
- |
# tfold is a helper to create folded reports (From Symfony)
tfold () {
local title="$1"
local fold=$(echo $title | sed -r 's/[^-_A-Za-z0-9]+/./g')
shift
echo -e "travis_fold:start:$fold"
echo -e "\\e[1;34m$title\\e[0m"
bash -xc "$*" 2>&1
local ok=$?
(exit $ok) &&
echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" ||
echo -e "\\e[41mKO\\e[0m $title\\n"
(exit $ok)
}
export -f tfold
script:
- cd layers/$LAYER
- docker build --build-arg PHP_VERSION=$PHP .
- |
for php_version in $PHP; do
tfold "Build $php_version" docker build --build-arg PHP_VERSION=${php_version} .
done
5 changes: 2 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ provider:

plugins:
- ./vendor/bref/bref
- ./vendor/bref/extra-layers # <--- Add the extra Serverless plugin
- ./vendor/bref/extra-layers # <----- Add the extra Serverless plugin

functions:
console:
Expand All @@ -28,7 +28,7 @@ functions:
- ${bref:layer.console}
```
```
```ini
;php/conf.d/php.ini
extension=/opt/bref-extra/amqp.so
```
Expand All @@ -45,7 +45,6 @@ extension=/opt/bref-extra/amqp.so

```
make publish
make list
git add checksums.json layers.json
git commit -m "New version of layers"
git push
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "bref/extra-layers",
"name": "bref/extra-php-extensions",
"description": "Extra PHP extensions for your lambda application.",
"type": "library",
"require-dev": {
"symfony/process": "^5.0",
Expand Down
19 changes: 9 additions & 10 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace Bref\Extra;

use Bref\Extra\Aws\LayerProvider;
use Bref\Extra\Aws\LayerPublisher;
use Bref\Extra\Service\RegionProvider;
use Bref\Extra\Command\ListCommand;
use Bref\Extra\Command\PublishCommand;
use Bref\Extra\Service\RegionProvider;
use DI\Container;
use DI\ContainerBuilder;
use Psr\Container\ContainerInterface;

class Application extends \Silly\Edition\PhpDi\Application
{
protected function createContainer()
protected function createContainer(): Container
{
$builder = new ContainerBuilder();
$builder = new ContainerBuilder;
$awsId = getenv('AWS_ID');
$awsProfile = getenv('AWS_PROFILE');
if (empty($awsId)){
if (empty($awsId)) {
$awsId = 'xxxxxxxxx';
}
if (empty($awsProfile)){
if (empty($awsProfile)) {
$awsProfile = null;
}

$projectDir = dirname(__DIR__);
$localLayers = array_keys(json_decode(file_get_contents($projectDir.'/checksums.json'), true));
$localLayers = array_keys(json_decode(file_get_contents($projectDir . '/checksums.json'), true));

$builder->addDefinitions([
'project_dir' => $projectDir,
Expand All @@ -50,4 +49,4 @@ protected function createContainer()

return $builder->build();
}
}
}
22 changes: 7 additions & 15 deletions src/Aws/LayerProvider.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace Bref\Extra\Aws;

use Aws\Lambda\LambdaClient;
use function GuzzleHttp\Promise\unwrap;

/**
* Fetches layers and details from AWS
*
* @author Tobias Nyholm <[email protected]>
*/
class LayerProvider
{
/** @var string */
private $awsId;

/**
* @var array
*/
/** @var array */
private $layerNames;

/**
* @param array $layerNames the name of the layers to list.
* @param string $awsId The account id
* @param array $layerNames the name of the layers to list.
* @param string $awsId The account id
*/
public function __construct(array $layerNames, string $awsId)
{
Expand All @@ -50,7 +44,7 @@ public function listLayers(string $selectedRegion): array

// Wait on all of the requests to complete. Throws a ConnectException
// if any of the requests fail
$results = \GuzzleHttp\Promise\unwrap($promises);
$results = unwrap($promises);

$layers = [];
foreach ($results as $layerName => $result) {
Expand All @@ -61,6 +55,4 @@ public function listLayers(string $selectedRegion): array

return $layers;
}


}
}
31 changes: 7 additions & 24 deletions src/Aws/LayerPublisher.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace Bref\Extra\Aws;

use Symfony\Component\Process\Process;

class LayerPublisher
{
/**
* @var string|null
*/
/** @var string|null */
private $awsProfile;

/**
*
* @param string|null $awsProfile
*/
public function __construct(?string $awsProfile)
{
$this->awsProfile = $awsProfile;
}


/**
* @param array<string, string> $layers Layer name and layer zip file path.
* @param array $regions
* @param array<string, string> $layers Layer name and layer zip file path.
* @param array $regions
*/
public function publishLayers(array $layers, array $regions): void
{
Expand All @@ -38,7 +30,6 @@ public function publishLayers(array $layers, array $regions): void
}
$this->finishProcesses($publishingProcesses);


// Add public permissions on the layers
/** @var Process[] $permissionProcesses */
$permissionProcesses = [];
Expand All @@ -55,9 +46,7 @@ public function publishLayers(array $layers, array $regions): void

/**
* @param string $region The AWS region to publish the layer to
* @param string $layerName
* @param string $file The absolute file path to the layer
* @return Process
* @param string $file The absolute file path to the layer
*/
private function publishSingleLayer(string $region, string $layerName, string $file): Process
{
Expand All @@ -74,7 +63,7 @@ private function publishSingleLayer(string $region, string $layerName, string $f
'--license-info',
'MIT',
'--zip-file',
'fileb://'.$file,
'fileb://' . $file,
'--compatible-runtimes',
'provided',
// Output the version so that we can fetch it and use it
Expand Down Expand Up @@ -122,10 +111,7 @@ private function finishProcesses(array $processes): void
}

/**
* @param string $region
* @param string $layer name
* @param string $layerVersion
* @return Process
*/
private function addPublicLayerPermissions(string $region, string $layer, string $layerVersion): Process
{
Expand Down Expand Up @@ -157,7 +143,4 @@ private function addPublicLayerPermissions(string $region, string $layer, string

return $process;
}



}
}
11 changes: 3 additions & 8 deletions src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace Bref\Extra\Command;

use Bref\Extra\Aws\LayerPublisher;
use Bref\Extra\Service\RegionProvider;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;

class HelpCommand
{
public function __invoke(OutputInterface $output)
public function __invoke(OutputInterface $output): int
{
$output->writeln('With this small application you may publish new layers and list existing ones in layer.json');
$output->writeln('You may specify the following environment variables: AWS_ID, AWS_PROFILE');

return 0;
}
}
}
22 changes: 7 additions & 15 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace Bref\Extra\Command;

Expand All @@ -15,19 +13,13 @@
*/
class ListCommand
{
/**
* @var LayerProvider
*/
/** @var LayerProvider */
private $provider;


/**
* @var string
*/
/** @var string */
private $projectDir;
/**
* @var RegionProvider
*/

/** @var RegionProvider */
private $regionProvider;

public function __construct(LayerProvider $provider, RegionProvider $regionProvider, string $projectDir)
Expand All @@ -37,7 +29,7 @@ public function __construct(LayerProvider $provider, RegionProvider $regionProvi
$this->regionProvider = $regionProvider;
}

public function __invoke(OutputInterface $output)
public function __invoke(OutputInterface $output): int
{
$export = [];
foreach ($this->regionProvider->getAll() as $region) {
Expand All @@ -52,4 +44,4 @@ public function __invoke(OutputInterface $output)

return 0;
}
}
}
Loading

0 comments on commit 15b4fbd

Please sign in to comment.