diff --git a/src/Adapter/Docker/Configuration.php b/src/Adapter/Docker/Configuration.php index c4770b35..dfee1bd4 100644 --- a/src/Adapter/Docker/Configuration.php +++ b/src/Adapter/Docker/Configuration.php @@ -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() ; diff --git a/src/Adapter/Docker/Factory.php b/src/Adapter/Docker/Factory.php index 3ba0ecfc..5c47ae94 100644 --- a/src/Adapter/Docker/Factory.php +++ b/src/Adapter/Docker/Factory.php @@ -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']); } } } @@ -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'])) { diff --git a/src/Adapter/Docker/FileOrDirectoryNotFoundException.php b/src/Adapter/Docker/FileOrDirectoryNotFoundException.php new file mode 100644 index 00000000..c3a2e14b --- /dev/null +++ b/src/Adapter/Docker/FileOrDirectoryNotFoundException.php @@ -0,0 +1,7 @@ +dockerfile, ...$this->files); + $archive = new TarArchive($this->dockerfile, ...array_values($this->files)); $iterator = function (iterable $tags) { foreach ($tags as $tag) {