From 61f97eb72693c15faba574c58be302b6ca3419f4 Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 15 Dec 2023 09:43:21 +0100 Subject: [PATCH 1/9] Added commands for docker and composer --- src/Dockerfile/Arg.php | 18 ++++++++++++++++++ src/PHP/ComposerConfig.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/Dockerfile/Arg.php create mode 100644 src/PHP/ComposerConfig.php diff --git a/src/Dockerfile/Arg.php b/src/Dockerfile/Arg.php new file mode 100644 index 0000000..5035f5b --- /dev/null +++ b/src/Dockerfile/Arg.php @@ -0,0 +1,18 @@ +name); + } +} diff --git a/src/PHP/ComposerConfig.php b/src/PHP/ComposerConfig.php new file mode 100644 index 0000000..20082c9 --- /dev/null +++ b/src/PHP/ComposerConfig.php @@ -0,0 +1,28 @@ +host, + $this->token, + )); + } +} From c3d2271d4a6f30a8e8b394a365a89e02dd50700b Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 15 Dec 2023 15:27:02 +0000 Subject: [PATCH 2/9] [rector] Rector fixes --- src/PHP/ComposerConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHP/ComposerConfig.php b/src/PHP/ComposerConfig.php index 20082c9..6b077bf 100644 --- a/src/PHP/ComposerConfig.php +++ b/src/PHP/ComposerConfig.php @@ -6,7 +6,7 @@ use Kiboko\Component\Dockerfile\Dockerfile; -final class ComposerConfig implements Dockerfile\LayerInterface, \Stringable +final readonly class ComposerConfig implements Dockerfile\LayerInterface, \Stringable { public function __construct( private string $host, From e3e773ec413ca5bf762fb98f85df0a2de07ce91f Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 26 Jan 2024 09:37:51 +0100 Subject: [PATCH 3/9] Ran php-cs-fixer --- src/Dockerfile.php | 4 ++-- src/PHP/ComposerConfig.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Dockerfile.php b/src/Dockerfile.php index 6b7b786..6308ad4 100644 --- a/src/Dockerfile.php +++ b/src/Dockerfile.php @@ -12,12 +12,12 @@ final class Dockerfile implements \IteratorAggregate, \Countable, FileInterface, /** @var iterable|Dockerfile\LayerInterface[] */ private iterable $layers; - public function __construct(null|Dockerfile\LayerInterface ...$layers) + public function __construct(null|LayerInterface ...$layers) { $this->layers = $layers; } - public function push(Dockerfile\LayerInterface ...$layers): void + public function push(LayerInterface ...$layers): void { array_push($this->layers, ...$layers); } diff --git a/src/PHP/ComposerConfig.php b/src/PHP/ComposerConfig.php index 6b077bf..d835195 100644 --- a/src/PHP/ComposerConfig.php +++ b/src/PHP/ComposerConfig.php @@ -11,8 +11,7 @@ public function __construct( private string $host, private string $token, - ) - { + ) { } public function __toString(): string From 569497d7ec9a98da95b45547e3fdd9abbf20bd1a Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 26 Jan 2024 17:18:44 +0100 Subject: [PATCH 4/9] Added a default value for the ARG syntax + rename class with Global prefix --- src/Dockerfile/Arg.php | 3 ++- src/PHP/{ComposerConfig.php => ComposerConfigGlobal.php} | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename src/PHP/{ComposerConfig.php => ComposerConfigGlobal.php} (84%) diff --git a/src/Dockerfile/Arg.php b/src/Dockerfile/Arg.php index 5035f5b..2f8fcd6 100644 --- a/src/Dockerfile/Arg.php +++ b/src/Dockerfile/Arg.php @@ -8,11 +8,12 @@ { public function __construct( private string $name, + private string $defaultValue, ) { } public function __toString(): string { - return sprintf('ARG %s', $this->name); + return sprintf('ARG %s=%s', $this->name, $this->defaultValue); } } diff --git a/src/PHP/ComposerConfig.php b/src/PHP/ComposerConfigGlobal.php similarity index 84% rename from src/PHP/ComposerConfig.php rename to src/PHP/ComposerConfigGlobal.php index d835195..19f8967 100644 --- a/src/PHP/ComposerConfig.php +++ b/src/PHP/ComposerConfigGlobal.php @@ -6,7 +6,7 @@ use Kiboko\Component\Dockerfile\Dockerfile; -final readonly class ComposerConfig implements Dockerfile\LayerInterface, \Stringable +final readonly class ComposerConfigGlobal implements Dockerfile\LayerInterface, \Stringable { public function __construct( private string $host, From f15caa9c7f4ebd52389b81fd8a52a438b3328547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20PLANCHAT?= Date: Thu, 1 Feb 2024 10:58:25 +0100 Subject: [PATCH 5/9] Apply suggestions from code review --- src/Dockerfile/Arg.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Dockerfile/Arg.php b/src/Dockerfile/Arg.php index 2f8fcd6..7ce8347 100644 --- a/src/Dockerfile/Arg.php +++ b/src/Dockerfile/Arg.php @@ -8,12 +8,15 @@ { public function __construct( private string $name, - private string $defaultValue, + private ?string $defaultValue = null, ) { } public function __toString(): string { - return sprintf('ARG %s=%s', $this->name, $this->defaultValue); + if ($this->defaultValue !== null) { + return sprintf('ARG %s=%s', $this->name, $this->defaultValue); + } + return sprintf('ARG %s', $this->name); } } From 312d50e8ec180aa734f13ebbe9b546bbccd1c43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20PLANCHAT?= Date: Thu, 1 Feb 2024 11:04:38 +0100 Subject: [PATCH 6/9] Apply suggestions from code review --- src/PHP/ComposerConfigGlobal.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/PHP/ComposerConfigGlobal.php b/src/PHP/ComposerConfigGlobal.php index 19f8967..62fef2a 100644 --- a/src/PHP/ComposerConfigGlobal.php +++ b/src/PHP/ComposerConfigGlobal.php @@ -10,18 +10,15 @@ { public function __construct( private string $host, - private string $token, + private string $tokenArgument, ) { } public function __toString(): string { - return (string) new Dockerfile\Run(sprintf( - <<<'RUN' - composer config --global %s %s - RUN, - $this->host, - $this->token, - )); + return (string) new Dockerfile\Run(<<<"RUN" + composer config --global {$this->host} \${{$this->tokenArgument}} + RUN, + ); } } From 1b6c8ffca989d7b53d84cf986d30f03d1ec18b57 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 1 Feb 2024 11:39:21 +0100 Subject: [PATCH 7/9] Added classes to manage the options used in the composer config command --- src/Argument.php | 18 +++++++++++++ src/Dockerfile/Arg.php | 3 ++- src/EnvironmentVariable.php | 18 +++++++++++++ ...figGlobal.php => ComposerGlobalConfig.php} | 11 ++++---- .../ComposerGlobalGithubAuthentication.php | 25 +++++++++++++++++++ src/Variable.php | 9 +++++++ 6 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/Argument.php create mode 100644 src/EnvironmentVariable.php rename src/PHP/{ComposerConfigGlobal.php => ComposerGlobalConfig.php} (55%) create mode 100644 src/PHP/ComposerGlobalGithubAuthentication.php create mode 100644 src/Variable.php diff --git a/src/Argument.php b/src/Argument.php new file mode 100644 index 0000000..8272d3f --- /dev/null +++ b/src/Argument.php @@ -0,0 +1,18 @@ +name}}"; + } +} diff --git a/src/Dockerfile/Arg.php b/src/Dockerfile/Arg.php index 7ce8347..186cabc 100644 --- a/src/Dockerfile/Arg.php +++ b/src/Dockerfile/Arg.php @@ -14,9 +14,10 @@ public function __construct( public function __toString(): string { - if ($this->defaultValue !== null) { + if (null !== $this->defaultValue) { return sprintf('ARG %s=%s', $this->name, $this->defaultValue); } + return sprintf('ARG %s', $this->name); } } diff --git a/src/EnvironmentVariable.php b/src/EnvironmentVariable.php new file mode 100644 index 0000000..711a11f --- /dev/null +++ b/src/EnvironmentVariable.php @@ -0,0 +1,18 @@ +name}}"; + } +} diff --git a/src/PHP/ComposerConfigGlobal.php b/src/PHP/ComposerGlobalConfig.php similarity index 55% rename from src/PHP/ComposerConfigGlobal.php rename to src/PHP/ComposerGlobalConfig.php index 62fef2a..7e87f38 100644 --- a/src/PHP/ComposerConfigGlobal.php +++ b/src/PHP/ComposerGlobalConfig.php @@ -5,20 +5,21 @@ namespace Kiboko\Component\Dockerfile\PHP; use Kiboko\Component\Dockerfile\Dockerfile; +use Kiboko\Component\Dockerfile\Variable; -final readonly class ComposerConfigGlobal implements Dockerfile\LayerInterface, \Stringable +final readonly class ComposerGlobalConfig implements Dockerfile\LayerInterface, \Stringable { public function __construct( - private string $host, - private string $tokenArgument, + private string $key, + private string|Variable $value, ) { } public function __toString(): string { return (string) new Dockerfile\Run(<<<"RUN" - composer config --global {$this->host} \${{$this->tokenArgument}} - RUN, + composer config --global {$this->key} {$this->value} + RUN ); } } diff --git a/src/PHP/ComposerGlobalGithubAuthentication.php b/src/PHP/ComposerGlobalGithubAuthentication.php new file mode 100644 index 0000000..a50ccf4 --- /dev/null +++ b/src/PHP/ComposerGlobalGithubAuthentication.php @@ -0,0 +1,25 @@ +host} {$this->tokenArgument} + RUN, + ); + } +} diff --git a/src/Variable.php b/src/Variable.php new file mode 100644 index 0000000..4bcd9e9 --- /dev/null +++ b/src/Variable.php @@ -0,0 +1,9 @@ + Date: Wed, 7 Feb 2024 14:47:05 +0100 Subject: [PATCH 8/9] Added a class to configure repositories --- src/PHP/ComposerConfigRepository.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/PHP/ComposerConfigRepository.php diff --git a/src/PHP/ComposerConfigRepository.php b/src/PHP/ComposerConfigRepository.php new file mode 100644 index 0000000..2fc8243 --- /dev/null +++ b/src/PHP/ComposerConfigRepository.php @@ -0,0 +1,26 @@ +name} {$this->type} {$this->url} + RUN + ); + } +} From 47e3ddf0e58ecc637848331b466d41e2f4774e22 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 7 Feb 2024 15:02:14 +0100 Subject: [PATCH 9/9] Remove useless class --- src/PHP/ComposerConfigRepository.php | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/PHP/ComposerConfigRepository.php diff --git a/src/PHP/ComposerConfigRepository.php b/src/PHP/ComposerConfigRepository.php deleted file mode 100644 index 2fc8243..0000000 --- a/src/PHP/ComposerConfigRepository.php +++ /dev/null @@ -1,26 +0,0 @@ -name} {$this->type} {$this->url} - RUN - ); - } -}