Skip to content

Commit

Permalink
Merge branch 'main' into pipeline-code-required
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat authored Oct 6, 2023
2 parents 456e9a7 + 8edfc6a commit 59738e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/Adapter/Docker/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('tags')
->scalarPrototype()->end()
->end()
->arrayNode('copy')
->arrayPrototype()
->children()
->scalarNode('from')->isRequired()->end()
->scalarNode('to')->isRequired()->end()
->end()
->end()
->end()
->end()
;

Expand Down
24 changes: 10 additions & 14 deletions src/Adapter/Docker/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,16 @@ public function __invoke(array $configuration): Configurator\SatelliteBuilderInt
if (isset($configuration['docker']['tags'])) {
$builder->withTags(...$configuration['docker']['tags']);
}

if (isset($configuration['docker']['include']) && is_iterable($configuration['docker']['include'])) {
foreach ($configuration['docker']['include'] as $path) {
if (is_dir($path)) {
$builder->withDirectory(new Packaging\Directory($path));
} else {
$builder->withFile(new Packaging\Asset\LocalFile($path));
if (isset($configuration['docker']['copy'])) {
foreach ($configuration['docker']['copy'] as $copy) {
if (!file_exists($copy['from'])) {
throw new FileOrDirectoryNotFoundException(strtr('Unable to find the file or the directory at path %path%', ['path' => $copy['from']]));
}
}
}

if (isset($configuration['include'])) {
foreach ($configuration['include'] as $path) {
if (is_dir($path)) {
$builder->withDirectory(new Packaging\Directory($path));
if (is_file($copy['from'])) {
$builder->withFile(new Packaging\File($copy['from'], new Packaging\Asset\LocalFile($copy['from'])), $copy['to']);
} else {
$builder->withFile(new Packaging\Asset\LocalFile($path));
$builder->withDirectory(new Packaging\Directory($copy['from']), $copy['to']);
}
}
}
Expand All @@ -60,6 +53,9 @@ public function __invoke(array $configuration): Configurator\SatelliteBuilderInt
} else {
$builder->withComposerFile(new Packaging\Asset\LocalFile('composer.json'));
}
if (file_exists('vendor')) {
$builder->withDirectory(new Packaging\Directory('vendor/'));
}
}

if (\array_key_exists('autoload', $configuration['composer']) && \array_key_exists('psr4', $configuration['composer']['autoload'])) {
Expand Down
7 changes: 7 additions & 0 deletions src/Adapter/Docker/FileOrDirectoryNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Satellite\Adapter\Docker;

class FileOrDirectoryNotFoundException extends \RuntimeException {}
2 changes: 1 addition & 1 deletion src/Adapter/Docker/Satellite.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function dependsOn(string ...$dependencies): self
public function build(
LoggerInterface $logger,
): void {
$archive = new TarArchive($this->dockerfile, ...$this->files);
$archive = new TarArchive($this->dockerfile, ...array_values($this->files));

$iterator = function (iterable $tags) {
foreach ($tags as $tag) {
Expand Down

0 comments on commit 59738e4

Please sign in to comment.