Skip to content

Commit

Permalink
Merge branch 'hotfix/3.5.23' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Nov 6, 2020
2 parents 8b74e0c + 7616013 commit 2a3b1ae
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 24 deletions.
12 changes: 11 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Changelog

## 3.5.23 / 2020-11-06

### Fixed:
* Fix file copying for kubectl shells
* Enhance docs for git based artifact deployment
* Apply shellProviderOptions also to other ssh commands
* Fix shell creation for ssh when executed as a sub process, typos

### New:
* Add new artifact actions `log` and `message` (Fixes #109)

## 3.5.22 / 2020-10-18
===================

### Fixed:
* Fix error in scaffolder which prevented to ask for the project name
Expand Down
32 changes: 31 additions & 1 deletion docs/deploying-artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ If you run phabalicious as part of a CI-setup, it might make sense to set `useLo
```yaml
hosts:
git-artifact:
branch: develop
needs:
- git
- composer
- artifacts--git
- script
artifact:
branch: master
branch: develop
baseBranch: master
repository: ssh://somewhere/repository.git
useLocalRepository: false
actions:
Expand All @@ -121,6 +123,13 @@ hosts:
the default actions for the git-artifact-method will copy all files to the target repo and remove the fabfile.
| property | default value | description |
|-----------------------|---------------|-------------------------------------------|
| `artifact.branch` | `false` | if set to false, the name of the source-branch is used, otherwise the value |
| `artifact.baseBranch` | `master` | If phabalicious needs to create a new branch, because it is missing from the target-repository, then start the branch from `masterBranch` |
| `artifact.repository` | | The url to the target-repository |
| `artifact.actions` | | Actions to perform |

### artifacts--custom

@TODO
Expand Down Expand Up @@ -193,4 +202,25 @@ The `script`-action will run the script from the arguments section line by line.
| `%context.data.installDir%` | The installation dir, where the app got installed into |
| `%context.data.targetDir%` | The targetdir, where the app got copied to, which gets committed or synced |

### message

```yaml
- action: message
arguments:
message: Hello world!
type: (comment|note|warning|error|success)
```

Prints out a message regardless of the log-level using symfony styles.

### log

```yaml
- action: log
arguments:
message: Hello world!
severity: (debug|info|notice|warning|error)
```

Logs a message, will be visible according to the verbosity-level and the used severity.

4 changes: 0 additions & 4 deletions src/Artifact/Actions/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Phabalicious\Artifact\Actions;

use Phabalicious\Method\ArtifactsBaseMethod;
use Phabalicious\Validation\ValidationErrorBagInterface;
use Phabalicious\Validation\ValidationService;

class ActionFactory
{

Expand Down
52 changes: 52 additions & 0 deletions src/Artifact/Actions/Base/LogAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Method\TaskContextInterface;
use Phabalicious\ShellProvider\CommandResult;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Validation\ValidationService;
use Psr\Log\LoggerInterface;

class LogAction extends ActionBase
{
const SEVERITY_MAPPINGS = [
'error' => 'error',
'warning' => 'warning',
'notice' => 'notice',
'info' => 'info',
'debug' => 'debug'
];

public function __construct()
{
}

protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation)
{
$validation->hasKey('message', 'Log action needs a message');
if (!empty($validation->getConfig()['severity'])) {
$validation->isOneOf(
'severity',
array_keys(self::SEVERITY_MAPPINGS)
);
}
}

protected function runImplementation(
HostConfig $host_config,
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
) {
$severity = $this->getArguments()['severity'] ?? 'notice';
$message = $this->getArguments()['message'];

$fn = self::SEVERITY_MAPPINGS[$severity];
$context->getConfigurationService()->getLogger()->{$fn}($message);
}
}
52 changes: 52 additions & 0 deletions src/Artifact/Actions/Base/MessageAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Method\TaskContextInterface;
use Phabalicious\ShellProvider\CommandResult;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Validation\ValidationService;
use Psr\Log\LoggerInterface;

class MessageAction extends ActionBase
{
const MESSAGE_TYPE_MAPPING = [
'error' => 'error',
'warning' => 'warning',
'note' => 'note',
'comment' => 'comment',
'success' => 'success'
];

public function __construct()
{
}

protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation)
{
$validation->hasKey('message', 'Log action needs a message');
if (!empty($validation->getConfig()['type'])) {
$validation->isOneOf(
'type',
array_keys(self::MESSAGE_TYPE_MAPPING)
);
}
}

protected function runImplementation(
HostConfig $host_config,
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
) {
$severity = $this->getArguments()['type'] ?? 'note';
$message = $this->getArguments()['message'];

$fn = self::MESSAGE_TYPE_MAPPING[$severity];
$context->io()->{$fn}($message);
}
}
2 changes: 1 addition & 1 deletion src/Command/GetBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
if ($shell->getFile(
$this->getHostConfig()['backupFolder'] . '/' . $elem['file'],
getcwd(),
getcwd() . '/' . $elem['file'],
$context
)) {
$files[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GetFilesDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($to_copy as $file) {
if ($shell->getFile(
$file,
getcwd(),
getcwd() . '/' . basename($file),
$context
)) {
$files[] = basename($file);
Expand Down
5 changes: 3 additions & 2 deletions src/Command/GetSqlDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Phabalicious\Exception\EarlyTaskExitException;
use Phabalicious\Method\TaskContext;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -47,13 +48,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getMethods()->runTask('getSQLDump', $this->getHostConfig(), $context);
$to_copy = $context->getResult('files');


/** @var ShellProviderInterface $shell */
$shell = $context->get('shell', $this->getHostConfig()->shell());
$files = [];
foreach ($to_copy as $file) {
if ($shell->getFile(
$file,
getcwd(),
getcwd() . '/' . basename($file),
$context
)) {
$files[] = basename($file);
Expand Down
19 changes: 12 additions & 7 deletions src/Method/ArtifactsBaseMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use Phabalicious\Artifact\Actions\Base\CopyAction;
use Phabalicious\Artifact\Actions\Base\DeleteAction;
use Phabalicious\Artifact\Actions\Base\InstallScriptAction;
use Phabalicious\Artifact\Actions\Base\LogAction;
use Phabalicious\Artifact\Actions\Base\MessageAction;
use Phabalicious\Artifact\Actions\Base\ScriptAction;
use Phabalicious\Configuration\ConfigurationService;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Exception\FailedShellCommandException;
use Phabalicious\Exception\MethodNotFoundException;
use Phabalicious\Exception\MissingScriptCallbackImplementation;
use Phabalicious\Exception\TaskNotFoundInMethodException;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Utilities\AppDefaultStages;
use Phabalicious\Utilities\EnsureKnownHosts;
use Phabalicious\Validation\ValidationErrorBagInterface;
Expand All @@ -34,6 +35,8 @@ public function __construct(LoggerInterface $logger)
ActionFactory::register('base', 'delete', DeleteAction::class);
ActionFactory::register('base', 'confirm', ConfirmAction::class);
ActionFactory::register('base', 'script', ScriptAction::class);
ActionFactory::register('base', 'message', MessageAction::class);
ActionFactory::register('base', 'log', LogAction::class);
ActionFactory::register('base', 'installScript', InstallScriptAction::class);
}

Expand All @@ -60,12 +63,14 @@ public function validateConfig(array $config, ValidationErrorBagInterface $error
$service->hasKeys([
'actions' => 'An artifact needs a list of actions',
]);
foreach ($config[self::PREFS_KEY]['actions'] as $action_config) {
if (!isset($action_config['action'])) {
$errors->addError('unknown', 'action needs a name');
} else {
$action = ActionFactory::get($this->getName(), $action_config['action']);
$action->validateConfig($config, $action_config, $errors);
if (isset($config[self::PREFS_KEY]['actions'])) {
foreach ($config[self::PREFS_KEY]['actions'] as $action_config) {
if (!isset($action_config['action'])) {
$errors->addError('unknown', 'action needs a name');
} else {
$action = ActionFactory::get($this->getName(), $action_config['action']);
$action->validateConfig($config, $action_config, $errors);
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/ShellProvider/SshShellProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ protected function addCommandOptions(&$command, $override = false)
$command[] = '-o';
$command[] = 'UserKnownHostsFile=/dev/null';
}
if (!empty($this->hostConfig['shellProviderOptions'])) {
$command = array_merge($command, $this->hostConfig['shellProviderOptions']);
}
}

public function getShellCommand(array $program_to_call, ShellOptions $options): array
Expand All @@ -115,9 +118,6 @@ public function getShellCommand(array $program_to_call, ShellOptions $options):
'-p',
$this->hostConfig['port'],
];
if (!empty($this->hostConfig['shellProviderOptions'])) {
$command = array_merge($command, $this->hostConfig['shellProviderOptions']);
}
$this->addCommandOptions($command);
if ($options->useTty()) {
$command[] = '-t';
Expand Down Expand Up @@ -306,7 +306,6 @@ public function wrapCommandInLoginShell(array $command)
return [
'/bin/bash',
'--login',
'-i',
'-c',
'\'' . implode(' ', $command) . '\''
];
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Utilities
{

const FALLBACK_VERSION = '3.5.22';
const FALLBACK_VERSION = '3.5.23';
const COMBINED_ARGUMENTS = 'combined';
const UNNAMED_ARGUMENTS = 'unnamedArguments';

Expand Down
7 changes: 6 additions & 1 deletion src/Validation/ValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function deprecate(array $keys)
public function arrayContainsKey(string $key, array $haystack, string $message)
{
if (!isset($haystack[$key])) {
$this->errors->addError($key, 'key '. $key . ' not not found. ' . $this->prefixMessage . ': ' . $message);
$this->errors->addError($key, 'key '. $key . ' not found. ' . $this->prefixMessage . ': ' . $message);
}
}
public function isArray(string $key, string $message)
Expand Down Expand Up @@ -93,4 +93,9 @@ public function checkForValidFolderName(string $key)
return false;
}
}

public function getConfig(): array
{
return $this->config;
}
}
Loading

0 comments on commit 2a3b1ae

Please sign in to comment.