Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
mstuder committed Mar 31, 2022
1 parent 7b10d85 commit 77f4c6c
Show file tree
Hide file tree
Showing 44 changed files with 2,700 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
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
8 changes: 8 additions & 0 deletions bin/downloadSources.php
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();
47 changes: 47 additions & 0 deletions composer.json
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
}
}
}
83 changes: 83 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions schemas/sources/sourceList.yaml
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]
25 changes: 25 additions & 0 deletions src/Adapters/Api/SourceDownloaderApi.php
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);
}
}
8 changes: 8 additions & 0 deletions src/Adapters/Configs/Env.php
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';
}
39 changes: 39 additions & 0 deletions src/Adapters/Configs/Outbounds.php
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)));
}
}
24 changes: 24 additions & 0 deletions src/Adapters/ShellExecutor/ShellExecutorClient.php
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);
}
}
12 changes: 12 additions & 0 deletions src/Core/Application/DownloadHandlers/Command.php
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;
}
11 changes: 11 additions & 0 deletions src/Core/Application/DownloadHandlers/CommandHandler.php
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 src/Core/Application/DownloadHandlers/DownloadTarGzHandler.php
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 src/Core/Application/DownloadHandlers/GitCommandHandler.php
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]);
}
}
Loading

0 comments on commit 77f4c6c

Please sign in to comment.