Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created new option to copy file from local into docker image #130

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
gplanchat marked this conversation as resolved.
Show resolved Hide resolved
$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/'));
}
gplanchat marked this conversation as resolved.
Show resolved Hide resolved
}

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