-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
2,700 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# source-downloader | ||
# flux-eco/source-downloader | ||
|
||
This component supports the downloading of software sources. e.g. for building docker containers | ||
|
||
## Contributing :purple_heart: | ||
|
||
Please ... | ||
|
||
1. ... register an account at https://git.fluxlabs.ch | ||
2. ... create pull requests :fire: | ||
|
||
## Adjustment suggestions / bug reporting :feet: | ||
|
||
Please ... | ||
|
||
1. ... register an account at https://git.fluxlabs.ch | ||
2. ... ask us for a Service Level Agreement: [email protected] :kissing_heart: | ||
3. ... read and create issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use FluxEco\SourceDownloader\Adapters\Api\SourceDownloaderApi; | ||
|
||
$api = SourceDownloaderApi::new(); | ||
$api->downloadSources(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "flux-cap/source-downloader", | ||
"description": "Component for flux-capacitor apps developed by fluxlabs", | ||
"version": "1.0.0", | ||
"type": "flux-eco", | ||
"keywords": [ | ||
"FluxCapacitor", | ||
"FluxEco", | ||
"fluxlabs ag" | ||
], | ||
"homepage": "https://fluxlabs.ch", | ||
"license": "GPL-3.0-only", | ||
"authors": [ | ||
{ | ||
"name": "fluxlabs ag", | ||
"email": "[email protected]", | ||
"homepage": "https://fluxlabs.ch", | ||
"role": "Developer" | ||
} | ||
], | ||
"support": { | ||
"email": "[email protected]" | ||
}, | ||
"require": { | ||
"flux-eco/shell-executor": ">=0.0.1", | ||
"php": ">=7.4", | ||
"ext-curl": "*", | ||
"ext-json": "*", | ||
"ext-yaml": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"FluxEco\\SourceDownloader\\": [ | ||
"src/" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"classmap-authoritative": true, | ||
"optimize-autoloader": true, | ||
"sort-packages": true, | ||
"platform-check": true, | ||
"allow-plugins": { | ||
"composer/package-versions-deprecated": true | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type: array | ||
items: | ||
oneOf: | ||
- type: object | ||
properties: | ||
sourceType: | ||
const: git | ||
url: | ||
type: string | ||
localPath: | ||
type: string | ||
required: [sourceType, url, localPath] | ||
- type: object | ||
properties: | ||
sourceType: | ||
const: tar-gz | ||
url: | ||
type: string | ||
localPath: | ||
type: string | ||
required: [sourceType, url, localPath] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Adapters\Api; | ||
|
||
use FluxEco\SourceDownloader\{Adapters, Core\Ports}; | ||
|
||
class SourceDownloaderApi | ||
{ | ||
private Ports\Service $service; | ||
|
||
private function __construct(Ports\Service $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
public static function new() : self | ||
{ | ||
$apiGatewayService = Ports\Service::new(Adapters\Configs\Outbounds::new()); | ||
return new self($apiGatewayService); | ||
} | ||
|
||
public function downloadSources(?string $sourceListFile = null, ?string $volumePath = null) { | ||
$this->service->downloadSources($sourceListFile, $volumePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Adapters\Configs; | ||
|
||
class Env | ||
{ | ||
public const SOURCE_DOWNLOADER_SOURCE_LIST_FILE = 'SOURCE_DOWNLOADER_SOURCE_LIST_FILE'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Adapters\Configs; | ||
|
||
use FluxEco\SourceDownloader\{Adapters, Core\Ports}; | ||
|
||
class Outbounds implements Ports\Configs\Outbounds | ||
{ | ||
|
||
private function __construct() | ||
{ | ||
|
||
} | ||
|
||
public static function new() : self | ||
{ | ||
return new self(); | ||
} | ||
|
||
public function getShellExecutorClient() : Ports\ShellExecutor\ShellExecutorClient | ||
{ | ||
return Adapters\ShellExecutor\ShellExecutorClient::new(); | ||
} | ||
|
||
public function getSourceList(?string $sourceListFile, ?string $volumePath) : array | ||
{ | ||
if ($sourceListFile !== null) { | ||
$sources = yaml_parse(file_get_contents($sourceListFile)); | ||
$transformedSources = []; | ||
foreach ($sources as $source) { | ||
$source['localPath'] = $volumePath . $source['localPath']; | ||
$transformedSources[] = $source; | ||
} | ||
return $transformedSources; | ||
} | ||
|
||
return yaml_parse(file_get_contents(getenv(ENV::SOURCE_DOWNLOADER_SOURCE_LIST_FILE))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Adapters\ShellExecutor; | ||
|
||
use FluxEco\SourceDownloader\Core\Ports; | ||
use FluxEco\ShellExecutor\Adapters\Api\ShellExecutorApi; | ||
|
||
class ShellExecutorClient implements Ports\ShellExecutor\ShellExecutorClient | ||
{ | ||
private function __construct() | ||
{ | ||
|
||
} | ||
|
||
public static function new() : self | ||
{ | ||
return new self(); | ||
} | ||
|
||
public function execute(array $commandQueue) : void | ||
{ | ||
ShellExecutorApi::new()->execute($commandQueue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Core\Application\DownloadHandlers; | ||
|
||
interface Command | ||
{ | ||
public function getSourceType() : string; | ||
|
||
public function getPath() : string; | ||
|
||
public function getUrl() : string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Core\Application\DownloadHandlers; | ||
|
||
use FluxEco\SourceDownloader\Core\{Ports}; | ||
|
||
interface CommandHandler | ||
{ | ||
public static function new(Ports\Configs\Outbounds $outbounds, Process $process) : self; | ||
public function handle(Command $command) : void; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Core/Application/DownloadHandlers/DownloadTarGzHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Core\Application\DownloadHandlers; | ||
|
||
use FluxEco\SourceDownloader\Core\{Domain\Models, Ports}; | ||
|
||
class DownloadTarGzHandler | ||
{ | ||
private Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient; | ||
private Process $process; | ||
|
||
private function __construct(Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient, Process $process) | ||
{ | ||
$this->shellExecutorClient = $shellExecutorClient; | ||
$this->process = $process; | ||
} | ||
|
||
public static function new(Ports\Configs\Outbounds $outbounds, Process $process) : self | ||
{ | ||
return new self($outbounds->getShellExecutorClient(), $process); | ||
} | ||
|
||
public function handle(Command $command) : void | ||
{ | ||
if ($command->getSourceType() !== Models\SourceTypeEnum::TAR_GZ) { | ||
$this->process->process($command); | ||
return; | ||
} | ||
|
||
$createDirectory = 'mkdir -p ' . $command->getPath(); | ||
$cdDirectory = 'cd ' . $command->getPath(); | ||
$curlUrl = 'curl -SL ' . $command->getUrl() . ' | tar -xz --strip-components=1'; | ||
|
||
$this->shellExecutorClient->execute([$createDirectory, $cdDirectory, $curlUrl]); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Core/Application/DownloadHandlers/GitCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace FluxEco\SourceDownloader\Core\Application\DownloadHandlers; | ||
|
||
use FluxEco\SourceDownloader\Core\{Domain\Models, Ports}; | ||
|
||
class GitCommandHandler implements CommandHandler | ||
{ | ||
private Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient; | ||
private Process $process; | ||
|
||
private function __construct(Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient, Process $process) | ||
{ | ||
$this->shellExecutorClient = $shellExecutorClient; | ||
$this->process = $process; | ||
} | ||
|
||
public static function new(Ports\Configs\Outbounds $outbounds, Process $process) : self | ||
{ | ||
return new self($outbounds->getShellExecutorClient(), $process); | ||
} | ||
|
||
public function handle(Command $command) : void | ||
{ | ||
if ($command->getSourceType() !== Models\SourceTypeEnum::GIT) { | ||
$this->process->process($command); | ||
return; | ||
} | ||
|
||
$createDirectory = 'mkdir -p ' . $command->getPath(); | ||
$cdDirectory = 'cd ' . $command->getPath(); | ||
$cloneRepository = 'git clone ' . $command->getUrl(); | ||
|
||
$this->shellExecutorClient->execute([$createDirectory, $cdDirectory, $cloneRepository]); | ||
} | ||
} |
Oops, something went wrong.