Skip to content

Commit

Permalink
Merge branch 'v1.0.3' into 'main'
Browse files Browse the repository at this point in the history
example, gitclonestatehandler

See merge request fluxlabs/flux-eco/source-downloader!2
  • Loading branch information
mstuder committed Apr 1, 2022
2 parents 2288b90 + 31fe288 commit fda00a9
Show file tree
Hide file tree
Showing 23 changed files with 230 additions and 105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# CHANGELOG

## [1.0.0]
- first version
## [1.0.3]
- added example
- added gitCloneStateHandler
- added shell argument handling

## [1.0.2]
- added flux-publisher

## [1.0.1]
- fixed bug with env variables

## [1.0.2]
- added flux-publisher
## [1.0.0]
- first version
12 changes: 11 additions & 1 deletion bin/downloadSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@

use FluxEco\SourceDownloader\Adapters\Api\SourceDownloaderApi;

$api = SourceDownloaderApi::new();
$sourceListFile = null;
$volumePath = null;
$gitGetFullClone = null;

if (count($argv) === 4) {
$sourceListFile = __DIR__ . '/' . $argv[1];
$volumePath = $argv[2];
$gitGetFullClone = (bool)$argv[3];
}

$api = SourceDownloaderApi::new($sourceListFile, $volumePath, $gitGetFullClone);
$api->downloadSources();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flux-eco/source-downloader",
"description": "Component for flux-capacitor apps developed by fluxlabs",
"version": "1.0.2",
"version": "1.0.3",
"type": "flux-eco",
"keywords": [
"FluxCapacitor",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

1 change: 1 addition & 0 deletions examples/ilias/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
php ../../bin/downloadSources.php '../examples/ilias/sourceList.yaml' '/tmp' 0
5 changes: 5 additions & 0 deletions examples/ilias/sourceList.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- sourceType: git
url: https://github.com/fluxapps/SrContainerObjectMenu.git
directoryPath: /var/www/ilias/Customizing/global/plugins/Services/UIComponent/UserInterfaceHook
directoryName: SrContainerObjectMenu
tag: v2.5.7
15 changes: 11 additions & 4 deletions schemas/sources/sourceList.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$schema: "https://raw.githubusercontent.com/flux-eco/source-downloader/main/schemas/sources/sourceList.yaml"
type: array
items:
oneOf:
Expand All @@ -7,15 +8,21 @@ items:
const: git
url:
type: string
localPath:
directoryPath:
type: string
required: [sourceType, url, localPath]
directoryName:
type: string
tag:
type: string
required: [sourceType, url, directoryPath, directoryName, tag]
- type: object
properties:
sourceType:
const: tar-gz
url:
type: string
localPath:
directoryPath:
type: string
directoryName:
type: string
required: [sourceType, url, localPath]
required: [sourceType, url, directoryPath, directoryName]
8 changes: 4 additions & 4 deletions src/Adapters/Api/SourceDownloaderApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ private function __construct(Ports\Service $service)
$this->service = $service;
}

public static function new() : self
public static function new(?string $sourceListFile = null, ?string $volumePath = null, ?bool $gitGetFullClone = null) : self
{
$apiGatewayService = Ports\Service::new(Adapters\Configs\Outbounds::new());
$apiGatewayService = Ports\Service::new(Adapters\Configs\Outbounds::new($sourceListFile, $volumePath, $gitGetFullClone));
return new self($apiGatewayService);
}

public function downloadSources(?string $sourceListFile = null, ?string $volumePath = null) {
$this->service->downloadSources($sourceListFile, $volumePath);
public function downloadSources() {
$this->service->downloadSources();
}
}
4 changes: 3 additions & 1 deletion src/Adapters/Configs/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

class Env
{
public const SOURCE_DOWNLOADER_SOURCE_LIST_FILE = 'SOURCE_DOWNLOADER_SOURCE_LIST_FILE';
public const GIT_FULL_CLONE = 'SOURCE_DOWNLOADER_GIT_FULL_CLONE';
public const SOURCE_LIST_FILE = 'SOURCE_DOWNLOADER_SOURCE_LIST_FILE';
public const VOLUME_PATH = 'SOURCE_DOWNLOADER_VOLUME_PATH';
}
51 changes: 35 additions & 16 deletions src/Adapters/Configs/Outbounds.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,53 @@

class Outbounds implements Ports\Configs\Outbounds
{
private string $sourceListFile;
private string $volumePath;
private bool $gitGetFullClone;

private function __construct()
private function __construct(string $sourceListFile, string $volumePath, bool $gitGetFullClone)
{

$this->sourceListFile = $sourceListFile;
$this->volumePath = $volumePath;
$this->gitGetFullClone = $gitGetFullClone;
}

public static function new() : self
{
return new self();
public static function new(
?string $sourceListFile = null,
?string $volumePath = null,
?bool $gitGetFullClone = null
) : self {
if (is_null($sourceListFile) === true) {
$sourceListFile = getenv(Env::SOURCE_LIST_FILE);
}
if (is_null($volumePath) === true) {
$volumePath = getenv(Env::VOLUME_PATH);
}
if (is_null($gitGetFullClone) === true) {
$gitGetFullClone = getenv(Env::GIT_FULL_CLONE);
}

return new self($sourceListFile, $volumePath, $gitGetFullClone);
}

public function getShellExecutorClient() : Ports\ShellExecutor\ShellExecutorClient
{
return Adapters\ShellExecutor\ShellExecutorClient::new();
}

public function getSourceList(?string $sourceListFile, ?string $volumePath) : array
public function getGitFullClone() : bool
{
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 $this->gitGetFullClone;
}

return yaml_parse(file_get_contents(getenv(Env::SOURCE_DOWNLOADER_SOURCE_LIST_FILE)));
public function getSourceList() : array
{
$sources = yaml_parse(file_get_contents($this->sourceListFile));
$transformedSources = [];
foreach ($sources as $source) {
$source['directoryPath'] = $this->volumePath . $source['directoryPath'];
$transformedSources[] = $source;
}
return $transformedSources;
}
}
8 changes: 6 additions & 2 deletions src/Core/Application/DownloadHandlers/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ interface Command
{
public function getSourceType() : string;

public function getPath() : string;

public function getUrl() : string;

public function getDirectoryPath() : string;

public function getDirectoryName() : string;

public function getTag() : string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function handle(Command $command) : void
return;
}

$createDirectory = 'mkdir -p ' . $command->getPath();
$cdDirectory = 'cd ' . $command->getPath();
$createDirectory = 'mkdir -p ' . $command->getDirectoryPath() . '/' . $command->getDirectoryName();
$cdDirectory = 'cd ' . $command->getDirectoryPath() . '/' . $command->getDirectoryName();
$curlUrl = 'curl -SL ' . $command->getUrl() . ' | tar -xz --strip-components=1';

$this->shellExecutorClient->execute([$createDirectory, $cdDirectory, $curlUrl]);
Expand Down
42 changes: 42 additions & 0 deletions src/Core/Application/DownloadHandlers/GitCloneCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace FluxEco\SourceDownloader\Core\Application\DownloadHandlers;

use FluxEco\SourceDownloader\Core\{Domain\Models, Ports};

class GitCloneCommandHandler implements CommandHandler
{
private Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient;
private bool $gitFullClone;
private Process $process;

private function __construct(
Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient,
bool $gitFullClone,
Process $process
) {
$this->shellExecutorClient = $shellExecutorClient;
$this->gitFullClone = $gitFullClone;
$this->process = $process;
}

public static function new(Ports\Configs\Outbounds $outbounds, Process $process) : self
{
return new self($outbounds->getShellExecutorClient(), $outbounds->getGitFullClone(), $process);
}

public function handle(Command $command) : void
{
if ($command->getSourceType() !== Models\SourceTypeEnum::GIT || $this->gitFullClone === false) {
$this->process->process($command);
return;
}

$deleteDirectory = 'rm -r ' . $command->getDirectoryPath();
$createDirectory = 'mkdir -p ' . $command->getDirectoryPath();
$cdDirectory = 'cd ' . $command->getDirectoryPath();
$cloneRepository = 'git clone --branch ' . $command->getTag() . ' ' . $command->getUrl() . ' ' . $command->getDirectoryName();

$this->shellExecutorClient->execute([$deleteDirectory, $createDirectory, $cdDirectory, $cloneRepository]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace FluxEco\SourceDownloader\Core\Application\DownloadHandlers;

use FluxEco\SourceDownloader\Core\{Domain\Models, Ports};

class GitCloneStateCommandHandler implements CommandHandler
{
private Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient;
private bool $gitFullClone;
private Process $process;

private function __construct(
Ports\ShellExecutor\ShellExecutorClient $shellExecutorClient,
bool $gitFullClone,
Process $process
) {
$this->shellExecutorClient = $shellExecutorClient;
$this->gitFullClone = $gitFullClone;
$this->process = $process;
}

public static function new(Ports\Configs\Outbounds $outbounds, Process $process) : self
{
return new self($outbounds->getShellExecutorClient(), $outbounds->getGitFullClone(), $process);
}

public function handle(Command $command) : void
{
if ($command->getSourceType() !== Models\SourceTypeEnum::GIT || $this->gitFullClone === true) {
$this->process->process($command);
return;
}

$deleteDirectory = 'rm -r ' . $command->getDirectoryPath();
$createDirectory = 'mkdir -p ' . $command->getDirectoryPath();
$cdDirectory = 'cd ' . $command->getDirectoryPath();
$cloneRepository = 'git clone --depth 1 --branch '.$command->getTag() .' '. $command->getUrl().' '.$command->getDirectoryName();

$this->shellExecutorClient->execute([$deleteDirectory, $createDirectory, $cdDirectory, $cloneRepository]);
}
}
36 changes: 0 additions & 36 deletions src/Core/Application/DownloadHandlers/GitCommandHandler.php

This file was deleted.

Loading

0 comments on commit fda00a9

Please sign in to comment.